add tags to the search metadata
This commit is contained in:
parent
32a49d3179
commit
33cb84713f
|
@ -3,8 +3,8 @@
|
||||||
* make-search-index.js
|
* make-search-index.js
|
||||||
*
|
*
|
||||||
* This converts a "search data" file produced by the haskell site builder into
|
* 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)
|
* a lunr.js index and saves it in JSON. Metadata for rendering search output
|
||||||
* are stored separately in an extra file.
|
* (currently titles and tags) are stored separately in an extra file.
|
||||||
*
|
*
|
||||||
* Installing dependencies:
|
* Installing dependencies:
|
||||||
* yarnpkg add lunr
|
* 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[3], JSON.stringify(idx), {encoding: 'utf8'})
|
||||||
fs.writeFileSync(process.argv[4], JSON.stringify(
|
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'})
|
), {encoding: 'utf8'})
|
||||||
|
|
6
site.hs
6
site.hs
|
@ -348,13 +348,17 @@ renderTags = use (htags . to M.keys) >>= traverse_ renderTag
|
||||||
-- | Transform one mounted PageInfo to the base search data
|
-- | Transform one mounted PageInfo to the base search data
|
||||||
mkSearchData :: FilePath -> PageInfo -> Site Y.Value
|
mkSearchData :: FilePath -> PageInfo -> Site Y.Value
|
||||||
mkSearchData mount pi = do
|
mkSearchData mount pi = do
|
||||||
|
link <- rootUrl mount
|
||||||
text <- io . runIOorExplode $ writePlain plainWriteOpts (pi ^. pageDoc)
|
text <- io . runIOorExplode $ writePlain plainWriteOpts (pi ^. pageDoc)
|
||||||
let title = pi ^? pageMeta . key "title" . _String
|
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 $
|
pure $
|
||||||
Y.object
|
Y.object
|
||||||
[ ("link", fromString link)
|
[ ("link", fromString link)
|
||||||
, ("title", maybe (fromString mount) Y.String title)
|
, ("title", maybe (fromString mount) Y.String title)
|
||||||
|
, ("tags", Y.array tags)
|
||||||
, ("text", Y.String text)
|
, ("text", Y.String text)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue