mirror of
https://git.sr.ht/~cadence/bibliogram
synced 2025-12-14 02:35:06 +00:00
Add remove hashtags setting
This commit is contained in:
@@ -112,6 +112,11 @@ let constants = {
|
||||
default: "",
|
||||
boolean: true,
|
||||
replaceEmptyWithDefault: true
|
||||
},{
|
||||
name: "remove_trailing_hashtags",
|
||||
default: "",
|
||||
boolean: true,
|
||||
replaceEmptyWithDefault: false
|
||||
},{
|
||||
name: "link_hashtags",
|
||||
default: "",
|
||||
@@ -122,6 +127,11 @@ let constants = {
|
||||
default: "on",
|
||||
boolean: true,
|
||||
replaceEmptyWithDefault: false
|
||||
},{
|
||||
name: "infinite_scroll",
|
||||
default: "normal",
|
||||
boolean: false,
|
||||
replaceEmptyWithDefault: true
|
||||
},{
|
||||
name: "caption_side",
|
||||
default: "left",
|
||||
@@ -263,7 +273,7 @@ let constants = {
|
||||
|
||||
additional_routes: [],
|
||||
|
||||
database_version: 7
|
||||
database_version: 8
|
||||
}
|
||||
|
||||
// Override values from config and export the result
|
||||
|
||||
@@ -2,7 +2,7 @@ const constants = require("../constants")
|
||||
const {proxyImage, proxyExtendedOwner} = require("../utils/proxyurl")
|
||||
const {compile} = require("pug")
|
||||
const collectors = require("../collectors")
|
||||
const {structure} = require("../utils/structuretext")
|
||||
const {structure, removeTrailingHashtags} = require("../utils/structuretext")
|
||||
const TimelineBaseMethods = require("./TimelineBaseMethods")
|
||||
const TimelineChild = require("./TimelineChild")
|
||||
require("../testimports")(collectors, TimelineChild, TimelineBaseMethods)
|
||||
@@ -110,6 +110,12 @@ class TimelineEntry extends TimelineBaseMethods {
|
||||
else return structure(caption)
|
||||
}
|
||||
|
||||
getStructuredCaptionWithoutTrailingHashtags() {
|
||||
const structured = this.getStructuredCaption()
|
||||
if (!structured) return null // no caption
|
||||
else return removeTrailingHashtags(structured)
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to get the first meaningful line or sentence from the caption.
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,20 @@
|
||||
const constants = require("../constants")
|
||||
|
||||
const dots = [
|
||||
".", // full stop
|
||||
"\u00b7", // middle dot
|
||||
"\u2022", // bullet
|
||||
"\u2027", // hyphenation point
|
||||
"\u2219", // bullet operator
|
||||
"\u22c5", // dot operator
|
||||
"\u2e31", // word separator middle dot
|
||||
"\u2e33", // raised dot
|
||||
"\u30fb", // katakana middle dot
|
||||
"\uff65", // halfwidth katakana middle dot
|
||||
]
|
||||
|
||||
const dotRegex = new RegExp(`[\n ][\n #${dots.join("")}]*$`, "gms")
|
||||
|
||||
function tryMatch(text, against, callback) {
|
||||
if (against instanceof RegExp && against.global) {
|
||||
// if it's a global match, keep sending matches to the callback while the callback returns true
|
||||
@@ -67,6 +82,41 @@ function structure(text) {
|
||||
return parts
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit a structure in-place to remove trailing hashtags and separator characters.
|
||||
*/
|
||||
function removeTrailingHashtags(structured) {
|
||||
let hasHashtags = structured.some(part => part.type === "hashtag")
|
||||
let seenHashtags = false
|
||||
|
||||
function shouldRemoveLastPart() {
|
||||
const part = structured[structured.length-1]
|
||||
if (part.type === "hashtag") {
|
||||
seenHashtags = true
|
||||
return true
|
||||
} else if (part.type === "user") {
|
||||
if (hasHashtags && !seenHashtags) { // compromise?
|
||||
return true
|
||||
}
|
||||
} else if (part.type === "text") {
|
||||
const content = part.text.replace(dotRegex, "")
|
||||
if (content.length === 0) {
|
||||
return true
|
||||
} else {
|
||||
part.text = content
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
while (shouldRemoveLastPart()) {
|
||||
structured.pop()
|
||||
}
|
||||
|
||||
return structured
|
||||
}
|
||||
|
||||
module.exports.structure = structure
|
||||
module.exports.partsUsername = partsUsername
|
||||
module.exports.partsHashtag = partsHashtag
|
||||
module.exports.removeTrailingHashtags = removeTrailingHashtags
|
||||
|
||||
@@ -80,7 +80,7 @@ const deltas = new Map([
|
||||
db.transaction(() => {
|
||||
db.prepare("ALTER TABLE UserSettings ADD COLUMN save_data TEXT NOT NULL DEFAULT 'automatic'")
|
||||
.run()
|
||||
db.prepare("ALTER TABLE UserSettings ADD COLUMN rewrite_youtube TEXT NOT NULL DEFAULt ''")
|
||||
db.prepare("ALTER TABLE UserSettings ADD COLUMN rewrite_youtube TEXT NOT NULL DEFAULT ''")
|
||||
.run()
|
||||
db.prepare("ALTER TABLE UserSettings ADD COLUMN rewrite_twitter TEXT NOT NULL DEFAULT ''")
|
||||
.run()
|
||||
@@ -94,6 +94,15 @@ const deltas = new Map([
|
||||
db.prepare("CREATE TABLE CSRFTokens (token TEXT NOT NULL, expires INTEGER NOT NULL, PRIMARY KEY (token))")
|
||||
.run()
|
||||
})()
|
||||
}],
|
||||
// version 7 to version 8
|
||||
[8, function() {
|
||||
db.transaction(() => {
|
||||
db.prepare("ALTER TABLE UserSettings ADD COLUMN remove_trailing_hashtags INTEGER NOT NULL DEFAULT 0")
|
||||
.run()
|
||||
db.prepare("ALTER TABLE UserSettings ADD COLUMN infinite_scroll TEXT NOT NULL DEFAULT 'normal'")
|
||||
.run()
|
||||
})()
|
||||
}]
|
||||
])
|
||||
|
||||
|
||||
@@ -28,7 +28,10 @@ mixin post(post, headerWithNavigation)
|
||||
div
|
||||
if post.getCaption()
|
||||
p.structured-text.description
|
||||
+display_structured(post.getStructuredCaption())
|
||||
if settings.remove_trailing_hashtags
|
||||
+display_structured(post.getStructuredCaptionWithoutTrailingHashtags())
|
||||
else
|
||||
+display_structured(post.getStructuredCaption())
|
||||
|
||||
footer
|
||||
if willDisplayAltInDescription
|
||||
|
||||
@@ -61,12 +61,20 @@ html
|
||||
|
||||
+input("rewrite_twitter", "Rewrite Twitter domain", "twitter.com", true)
|
||||
|
||||
+checkbox("show_comments", "Display comments", "Display", true)
|
||||
+checkbox("remove_trailing_hashtags", "Hide trailing hashtags", false)
|
||||
|
||||
+checkbox("link_hashtags", "Clickable hashtags", "Clickable", true)
|
||||
|
||||
+checkbox("show_comments", "Display comments", "Display", true)
|
||||
|
||||
+checkbox("spa", "Fast navigation", "Enabled", false)
|
||||
|
||||
+select("infinite_scroll", "Infinite scroll", true, [
|
||||
{value: "normal", text: "Normal"},
|
||||
{value: "eager", text: "Eager"},
|
||||
{value: "off", text: "Manual"}
|
||||
])
|
||||
|
||||
+fieldset("Appearance")
|
||||
+select("theme", "Theme", false, constants.themes.collated.map(entry => ({value: entry.file, text: entry.name})))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user