Skip to content

Commit

Permalink
List searches on home
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiodxa committed Dec 29, 2023
1 parent e12390c commit 4d1b773
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions app/routes/cms._index/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,23 @@ export async function createQuickLike(
export async function queryLastDaySearch(context: AppLoadContext) {
let cache = new Cache.KVStore(context.kv.cache, context.waitUntil);

let [articles, tutorials] = await Promise.all([
let [articles, tutorials, feedArticles, feedTutorials] = await Promise.all([
cache.list("articles:search:"),
cache.list("tutorials:search:"),
cache.list("feed:articles:search:"),
cache.list("feed:tutorials:search:"),
]);

return {
articles: articles.map((key) => key.replace("articles:search:", "")),
tutorials: tutorials.map((key) => {
key = key.replace("tutorials:search:", "");
if (!key.startsWith("tech:")) return key;
return key.replace("tech:", "");
}),
articles: [...articles, ...feedArticles]
.map((key) => key.replace("articles:search:", "").replace("feed:", ""))
.sort((a, b) => a.localeCompare(b)),
tutorials: [...tutorials, ...feedTutorials]
.map((key) => {
key = key.replace("tutorials:search:", "").replace("feed:", "");
if (!key.startsWith("tech:")) return key;
return key.replace("tech:", "");
})
.sort((a, b) => a.localeCompare(b)),
};
}

0 comments on commit 4d1b773

Please sign in to comment.