aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMirek Kratochvil <exa.exa@gmail.com>2023-06-17 20:55:26 +0200
committerMirek Kratochvil <exa.exa@gmail.com>2023-06-17 20:55:26 +0200
commit33cb84713fc6cbbd7925c9d51c61e94d3e3cff77 (patch)
treebae265e41af428db4db10f1583061b996cbba21b
parent32a49d3179a969604410ff7507af939c77045b4f (diff)
downloadreploy-33cb84713fc6cbbd7925c9d51c61e94d3e3cff77.tar.gz
reploy-33cb84713fc6cbbd7925c9d51c61e94d3e3cff77.tar.bz2
add tags to the search metadata
-rw-r--r--make-search-index.js6
-rw-r--r--site.hs6
2 files changed, 8 insertions, 4 deletions
diff --git a/make-search-index.js b/make-search-index.js
index bb92b68..0690dae 100644
--- a/make-search-index.js
+++ b/make-search-index.js
@@ -3,8 +3,8 @@
* make-search-index.js
*
* This converts a "search data" file produced by the haskell site builder into
- * a lunr.js index and saves it in JSON. Metadata for search (currently titles)
- * are stored separately in an extra file.
+ * a lunr.js index and saves it in JSON. Metadata for rendering search output
+ * (currently titles and tags) are stored separately in an extra file.
*
* Installing dependencies:
* yarnpkg add lunr
@@ -35,5 +35,5 @@ var idx = lunr(function () {
fs.writeFileSync(process.argv[3], JSON.stringify(idx), {encoding: 'utf8'})
fs.writeFileSync(process.argv[4], JSON.stringify(
- Object.fromEntries(documents.map(x => [x.link, x.title]))
+ Object.fromEntries(documents.map(x => [x.link, {"title": x.title, "tags": x.tags}]))
), {encoding: 'utf8'})
diff --git a/site.hs b/site.hs
index 918fdff..e012f04 100644
--- a/site.hs
+++ b/site.hs
@@ -348,13 +348,17 @@ renderTags = use (htags . to M.keys) >>= traverse_ renderTag
-- | Transform one mounted PageInfo to the base search data
mkSearchData :: FilePath -> PageInfo -> Site Y.Value
mkSearchData mount pi = do
+ link <- rootUrl mount
text <- io . runIOorExplode $ writePlain plainWriteOpts (pi ^. pageDoc)
let title = pi ^? pageMeta . key "title" . _String
- link <- rootUrl mount
+ let tags =
+ pi ^.. pageMeta . key "tags" . values . _String .
+ to (Y.array . map fromString . splitDirectories . T.unpack)
pure $
Y.object
[ ("link", fromString link)
, ("title", maybe (fromString mount) Y.String title)
+ , ("tags", Y.array tags)
, ("text", Y.String text)
]