Add notes list and integrate into templates
New partial templates/notes-list.html to render the notes list. Add .notes-list CSS for styling and ensure contents areas use it. Refactor site.hs: add loadNoteLinks and provide a "notes" listField used by index and note pages.
This commit is contained in:
12
src/site.hs
12
src/site.hs
@@ -26,6 +26,11 @@ cleanIndexHtmls = return . fmap (replaceAll pattern replacement)
|
||||
pattern :: String = "/index.html"
|
||||
replacement :: String -> String = const "/"
|
||||
|
||||
loadNoteLinks :: Compiler [Item String]
|
||||
loadNoteLinks = do
|
||||
noteIds <- sortOn toFilePath <$> getMatches "notes/*"
|
||||
pure [Item noteId "" | noteId <- noteIds]
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
config :: Configuration
|
||||
@@ -103,7 +108,8 @@ main = hakyllWith config $ do
|
||||
match "notes/*" $ do
|
||||
route cleanRoute
|
||||
compile $ do
|
||||
tocCtx <- getTocCtx defaultContext
|
||||
notes <- loadNoteLinks
|
||||
tocCtx <- getTocCtx $ listField "notes" defaultContext (return notes) <> defaultContext
|
||||
chaoDocCompiler
|
||||
>>= loadAndApplyTemplate "templates/note.html" tocCtx
|
||||
>>= relativizeUrls
|
||||
@@ -111,9 +117,9 @@ main = hakyllWith config $ do
|
||||
create ["index.html"] $ do
|
||||
route idRoute
|
||||
compile $ do
|
||||
notes <- sortOn (toFilePath . itemIdentifier) <$> loadAll "notes/*"
|
||||
notes <- loadNoteLinks
|
||||
let notesCtx =
|
||||
listField "posts" defaultContext (return notes)
|
||||
listField "notes" defaultContext (return notes)
|
||||
`mappend` constField "title" "Notes"
|
||||
`mappend` defaultContext
|
||||
makeItem ""
|
||||
|
||||
Reference in New Issue
Block a user