add optional toc and numbering fields
Signed-off-by: Amneesh Singh <natto@weirdnatto.in>
This commit is contained in:
@@ -117,6 +117,16 @@ h2 {
|
|||||||
font-size: 2rem;
|
font-size: 2rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.post-preview-item {
|
||||||
|
list-style-type: none;
|
||||||
|
padding: 2rem;
|
||||||
|
border: 0.5rem dotted var(--violet);
|
||||||
|
}
|
||||||
|
|
||||||
|
.post-preview-item:not(:last-child) {
|
||||||
|
margin-bottom: 3rem;
|
||||||
|
}
|
||||||
|
|
||||||
.post-title {
|
.post-title {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
color: var(--fg5) !important;
|
color: var(--fg5) !important;
|
||||||
@@ -149,13 +159,6 @@ article > section {
|
|||||||
overflow: auto;
|
overflow: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
.toc {
|
|
||||||
padding: 2rem;
|
|
||||||
float: right;
|
|
||||||
border-radius: 1rem;
|
|
||||||
background: var(--bg1);
|
|
||||||
}
|
|
||||||
|
|
||||||
.post-teaser > .toc {
|
.post-teaser > .toc {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
@@ -176,6 +179,13 @@ pre {
|
|||||||
overflow: scroll;
|
overflow: scroll;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.toc {
|
||||||
|
background: var(--bg1);
|
||||||
|
border-radius: 1rem;
|
||||||
|
float: right;
|
||||||
|
max-width: 40%;
|
||||||
|
}
|
||||||
|
|
||||||
@media (max-width: 319px) {
|
@media (max-width: 319px) {
|
||||||
body {
|
body {
|
||||||
width: 90%;
|
width: 90%;
|
||||||
@@ -189,10 +199,8 @@ pre {
|
|||||||
display: block;
|
display: block;
|
||||||
line-height: 1.6;
|
line-height: 1.6;
|
||||||
}
|
}
|
||||||
.sticky {
|
.toc {
|
||||||
position: fixed;
|
padding: 1rem;
|
||||||
top: 0;
|
|
||||||
background: white;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -209,6 +217,9 @@ pre {
|
|||||||
display: inline;
|
display: inline;
|
||||||
margin: 0 0.6rem;
|
margin: 0 0.6rem;
|
||||||
}
|
}
|
||||||
|
.toc {
|
||||||
|
padding: 1rem;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (min-width: 640px) {
|
@media (min-width: 640px) {
|
||||||
@@ -224,4 +235,7 @@ pre {
|
|||||||
footer {
|
footer {
|
||||||
text-align: right;
|
text-align: right;
|
||||||
}
|
}
|
||||||
|
.toc {
|
||||||
|
padding: 2rem;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,8 +1,10 @@
|
|||||||
---
|
---
|
||||||
title: alo
|
title: alo
|
||||||
tags: amaang, shararati
|
tags: amaang, shararati
|
||||||
|
enabletoc: true
|
||||||
---
|
---
|
||||||
|
|
||||||
|
#+OPTIONS: toc:nil
|
||||||
|
|
||||||
* The
|
* The
|
||||||
|
|
||||||
@@ -11,3 +13,6 @@ alo, i am a.
|
|||||||
#+BEGIN_EXPORT HTML
|
#+BEGIN_EXPORT HTML
|
||||||
<!--more-->
|
<!--more-->
|
||||||
#+END_EXPORT
|
#+END_EXPORT
|
||||||
|
|
||||||
|
** how
|
||||||
|
loda hai kya
|
||||||
|
18
posts/2022-12-06-placeholder2.org
Normal file
18
posts/2022-12-06-placeholder2.org
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
---
|
||||||
|
title: alo
|
||||||
|
tags: amaang
|
||||||
|
enabletoc: true
|
||||||
|
---
|
||||||
|
|
||||||
|
#+OPTIONS: toc:nil
|
||||||
|
|
||||||
|
* The
|
||||||
|
|
||||||
|
alo, i am a.
|
||||||
|
|
||||||
|
#+BEGIN_EXPORT HTML
|
||||||
|
<!--more-->
|
||||||
|
#+END_EXPORT
|
||||||
|
|
||||||
|
** how
|
||||||
|
loda hai kya
|
15
src/site.hs
15
src/site.hs
@@ -7,6 +7,7 @@ import qualified Data.Text as T
|
|||||||
import Hakyll
|
import Hakyll
|
||||||
import Text.Pandoc (WriterOptions (writerHighlightStyle, writerNumberSections, writerTOCDepth, writerTableOfContents, writerTemplate))
|
import Text.Pandoc (WriterOptions (writerHighlightStyle, writerNumberSections, writerTOCDepth, writerTableOfContents, writerTemplate))
|
||||||
import Text.Pandoc.Templates (Template, compileTemplate)
|
import Text.Pandoc.Templates (Template, compileTemplate)
|
||||||
|
import Data.Maybe (isJust)
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
@@ -47,8 +48,12 @@ main = hakyllWith config $ do
|
|||||||
|
|
||||||
match "posts/*org" $ do
|
match "posts/*org" $ do
|
||||||
route $ setExtension "html"
|
route $ setExtension "html"
|
||||||
compile $
|
compile $ do
|
||||||
pandocCompilerWith defaultHakyllReaderOptions writerOptions
|
identifier <- getUnderlying
|
||||||
|
toc <- getMetadataField identifier "enabletoc"
|
||||||
|
numbering <- getMetadataField identifier "enablenumbering"
|
||||||
|
let writerOptions' = maybe defaultHakyllWriterOptions (const $ writerOptions $ isJust numbering) toc
|
||||||
|
pandocCompilerWith defaultHakyllReaderOptions writerOptions'
|
||||||
>>= saveSnapshot "content"
|
>>= saveSnapshot "content"
|
||||||
>>= loadAndApplyTemplate "templates/post.html" (postCtx tags <> teaserField "teaser" "content")
|
>>= loadAndApplyTemplate "templates/post.html" (postCtx tags <> teaserField "teaser" "content")
|
||||||
>>= loadAndApplyTemplate "templates/default.html" (postCtx tags)
|
>>= loadAndApplyTemplate "templates/default.html" (postCtx tags)
|
||||||
@@ -126,10 +131,10 @@ defaultCtx =
|
|||||||
mkItem :: a -> Item a
|
mkItem :: a -> Item a
|
||||||
mkItem a = Item {itemIdentifier = "subdomain", itemBody = a}
|
mkItem a = Item {itemIdentifier = "subdomain", itemBody = a}
|
||||||
|
|
||||||
writerOptions :: WriterOptions
|
writerOptions :: Bool -> WriterOptions
|
||||||
writerOptions =
|
writerOptions withNumbering =
|
||||||
defaultHakyllWriterOptions
|
defaultHakyllWriterOptions
|
||||||
{ writerNumberSections = True,
|
{ writerNumberSections = withNumbering,
|
||||||
writerTableOfContents = True,
|
writerTableOfContents = True,
|
||||||
writerTOCDepth = 2,
|
writerTOCDepth = 2,
|
||||||
writerTemplate = Just tocTemplate
|
writerTemplate = Just tocTemplate
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
<ul>
|
<ul class="post-preview-item-list">
|
||||||
$for(posts)$
|
$for(posts)$
|
||||||
<li class="post-item post-preview-item" style="list-style-type: none;" >
|
<li class="post-preview-item" >
|
||||||
<article>
|
<article>
|
||||||
<h1 class="post-title">$title$</h1>
|
<h1 class="post-title">$title$</h1>
|
||||||
<div class="post-header">
|
<div class="post-header">
|
||||||
|
Reference in New Issue
Block a user