mirror of
http://101.35.51.105:3000/congyu/Hakysidian.git
synced 2026-04-27 21:40:50 +08:00
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:
@@ -264,6 +264,20 @@ ul {
|
||||
list-style-type: square;
|
||||
padding-left: 2em;
|
||||
}
|
||||
.notes-list {
|
||||
list-style: none;
|
||||
padding-left: 0;
|
||||
margin-left: 0;
|
||||
}
|
||||
.notes-list li {
|
||||
position: relative;
|
||||
padding-left: 1em;
|
||||
}
|
||||
.notes-list li::before {
|
||||
content: "-";
|
||||
position: absolute;
|
||||
left: 0;
|
||||
}
|
||||
li {
|
||||
margin-bottom: 0.15em;
|
||||
}
|
||||
@@ -404,6 +418,12 @@ code {
|
||||
margin-left: 0
|
||||
}
|
||||
|
||||
div#contents ul.notes-list,
|
||||
div#contents-big ul.notes-list {
|
||||
list-style: none;
|
||||
padding-left: 0;
|
||||
}
|
||||
|
||||
div#contents-big ul ul {
|
||||
list-style-type: none;
|
||||
}
|
||||
|
||||
+9
-3
@@ -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 ""
|
||||
|
||||
+2
-1
@@ -11,6 +11,7 @@ $partial("templates/head.html")$
|
||||
that are big enough -->
|
||||
<div id="contents-big">
|
||||
<p class="mini-header">Notes <a id="up-arrow" href="/">←</a></p>
|
||||
$partial("templates/notes-list.html")$
|
||||
<p class="mini-header">Contents <a id="up-arrow" href="#">↑</a></p>
|
||||
$toc$
|
||||
</div>
|
||||
@@ -38,4 +39,4 @@ $partial("templates/head.html")$
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
</html>
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
<ul class="notes-list">
|
||||
$for(notes)$
|
||||
<li>
|
||||
<a href="$url$">$title$</a>
|
||||
</li>
|
||||
$endfor$
|
||||
</ul>
|
||||
@@ -1,8 +1,2 @@
|
||||
<h1 class="pagetitle">$title$</h1>
|
||||
<ul>
|
||||
$for(posts)$
|
||||
<li>
|
||||
<a href="$url$">$title$</a>
|
||||
</li>
|
||||
$endfor$
|
||||
</ul>
|
||||
$partial("templates/notes-list.html")$
|
||||
|
||||
Reference in New Issue
Block a user