Skip to content

Commit

Permalink
Merge pull request #155 from TomCasavant/fix_bookmarks
Browse files Browse the repository at this point in the history
Adjusted SQL REGEX to fix bookmark search
  • Loading branch information
ckolderup authored Oct 20, 2023
2 parents beb5a74 + ab97b59 commit 0dd81d5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
7 changes: 4 additions & 3 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,17 @@ const hbs = create({
return process.env.MASTODON_ACCOUNT;
},
ifIn(item, array, options) {
return array.indexOf(item) >= 0 ? options.fn(this) : options.inverse(this);
const lowercased = array.map((tag) => tag.toLowerCase());
return lowercased.indexOf(item.toLowerCase()) >= 0 ? options.fn(this) : options.inverse(this);
},
removeTag(tag, path) {
return path
.split('/')
.filter((x) => x !== tag)
.filter((x) => x.toLowerCase() !== tag.toLowerCase())
.join('/');
},
ifThisTag(tag, path, options) {
return path === `/tagged/${tag}` ? options.fn(this) : options.inverse(this);
return path.toLowerCase() === `/tagged/${tag}`.toLowerCase() ? options.fn(this) : options.inverse(this);
},
eq(a, b, options) {
return a === b ? options.fn(this) : options.inverse(this);
Expand Down
4 changes: 2 additions & 2 deletions src/bookmarks-db.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ export async function getBookmarksForCSVExport() {

export async function getBookmarkCountForTags(tags) {
const tagClauses = tags.map(() => `(tags like ? OR tags like ?)`).join(' AND ');
const tagParams = tags.map((tag) => [`%${tag}% `, `%${tag}%`]).flat();
const tagParams = tags.map((tag) => [`%#${tag} %`, `%#${tag}`]).flat();
const result = await db.get.apply(db, [`SELECT count(id) as count from bookmarks WHERE ${tagClauses}`, ...tagParams]);
return result?.count;
}
Expand All @@ -224,7 +224,7 @@ export async function getBookmarksForTags(tags, limit = 10, offset = 0) {
// We use a try catch block in case of db errors
try {
const tagClauses = tags.map(() => `(tags like ? OR tags like ?)`).join(' AND ');
const tagParams = tags.map((tag) => [`%${tag}% `, `%${tag}%`]).flat();
const tagParams = tags.map((tag) => [`%#${tag} %`, `%#${tag}`]).flat();
const results = await db.all.apply(db, [
`SELECT * from bookmarks WHERE ${tagClauses} ORDER BY updated_at DESC LIMIT ? OFFSET ?`,
...tagParams,
Expand Down

0 comments on commit 0dd81d5

Please sign in to comment.