Compare commits

..

2 Commits

5 changed files with 118 additions and 77 deletions

View File

@@ -4,6 +4,8 @@
--color-tag2: darkolivegreen; --color-tag2: darkolivegreen;
--color-bg: white; --color-bg: white;
--color-notice: #fb4f4f; --color-notice: #fb4f4f;
--color-link: #0645ad;
--color-link-visited: #551a8b;
} }
html { html {
@@ -25,9 +27,18 @@ body {
} }
body a { body a {
color: var(--color-link);
text-decoration: none; text-decoration: none;
} }
body a:visited {
color: var(--color-link-visited);
}
body a[href^="#"]:visited {
color: var(--color-link);
}
body a:hover { body a:hover {
text-decoration: underline; text-decoration: underline;
} }
@@ -89,10 +100,9 @@ html body div.text-space main ul.post-list {
header { header {
font-weight: 400; font-weight: 400;
font-family: "IosevkaC", sans-serif; font-family: "IosevkaC", sans-serif;
} font-size: 2rem;
nav a {
display: inline-block;
text-decoration: none; text-decoration: none;
line-height: 120%;
} }
.uri { .uri {
@@ -322,18 +332,18 @@ code {
margin-bottom: 0.5em; margin-bottom: 0.5em;
padding-left: 1em; padding-left: 1em;
line-height: 1.2; line-height: 1.2;
list-style-type: decimal;
margin-left: 0
}
div#contents-big ul ul {
list-style-type: none; list-style-type: none;
margin-left: 0
} }
div#contents-big li+li { div#contents-big li+li {
margin-top: 0.5em margin-top: 0.5em
} }
div#contents-big .toc-section-number {
margin-right: 0.2em;
}
div#contents-big { div#contents-big {
font-size: 80%; font-size: 80%;
padding-top: 0; padding-top: 0;

View File

@@ -25,13 +25,15 @@
</div> </div>
<div class="text-space"> <div class="text-space">
<header class="no-print"> <header class="no-print">
<nav> <a href="/">/</a>
<a href="/">Home</a> $title$
</nav>
</header> </header>
<main role="main"> <main role="main">
<h1 class="pagetitle">$title$</h1> <article>
<section class="body">
$body$ $body$
</section>
</article>
</main> </main>
<footer></footer> <footer></footer>
</div> </div>

View File

@@ -1,5 +0,0 @@
<article>
<section class="body">
$body$
</section>
</article>

View File

@@ -1,13 +1,22 @@
{-# LANGUAGE BlockArguments #-} {-# LANGUAGE BlockArguments #-}
{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE StandaloneKindSignatures #-}
module ChaoDoc (chaoDocRead, chaoDocWrite, chaoDocPandocCompiler, chaoDocCompiler) where module ChaoDoc
( ChaoDocFiles (..),
chaoDocRead,
chaoDocWrite,
chaoDocPandocCompiler,
chaoDocCompiler,
)
where
import Control.Monad (guard) import Control.Monad (guard)
import Control.Monad.State import Control.Monad.State
import Data.Char (isSpace) import Data.Char (isSpace)
import Data.Either import Data.Either
import Data.Functor import Data.Functor
import Data.Kind (Type)
import Data.List (find) import Data.List (find)
import qualified Data.Map as M import qualified Data.Map as M
import Data.Maybe import Data.Maybe
@@ -16,19 +25,16 @@ import qualified Data.Text as T
import Hakyll import Hakyll
import Pangu (isCJK, pangu) import Pangu (isCJK, pangu)
import SideNoteHTML (usingSideNotesHTML) import SideNoteHTML (usingSideNotesHTML)
import System.IO.Unsafe
import Text.Pandoc import Text.Pandoc
-- import Text.Pandoc.Builder -- import Text.Pandoc.Builder
import Text.Pandoc.Walk (query, walk, walkM) import Text.Pandoc.Walk (query, walk, walkM)
cslFile :: String type ChaoDocFiles :: Type
cslFile = "assets/bib_style.csl" data ChaoDocFiles = ChaoDocFiles
{ chaoDocCslFile :: FilePath,
bibFile :: String chaoDocBibFile :: FilePath,
bibFile = "ref.bib" chaoDocMacroFile :: FilePath
}
macroFile :: String
macroFile = "assets/math-macros.tex"
-- On mac, please do `export LANG=C` before using this thing -- On mac, please do `export LANG=C` before using this thing
chaoDocRead :: ReaderOptions chaoDocRead :: ReaderOptions
@@ -52,23 +58,23 @@ chaoDocWrite =
writerTOCDepth = 2 writerTOCDepth = 2
} }
chaoDocPandocCompiler :: Compiler (Item Pandoc) chaoDocPandocCompiler :: ChaoDocFiles -> Compiler (Item Pandoc)
chaoDocPandocCompiler = do chaoDocPandocCompiler paths = do
macros <- T.pack <$> loadBody (fromFilePath macroFile) macros <- T.pack <$> loadBody (fromFilePath $ chaoDocMacroFile paths)
csl <- load $ fromFilePath cslFile csl <- load $ fromFilePath $ chaoDocCslFile paths
bib <- load $ fromFilePath bibFile bib <- load $ fromFilePath $ chaoDocBibFile paths
body <- getResourceBody body <- getResourceBody
let bodyWithMacros = let bodyWithMacros =
fmap (T.unpack . prependMacros macros . normalizeTheoremFenceTitles . T.pack) body fmap (T.unpack . prependMacros macros . normalizeTheoremFenceTitles . T.pack) body
prepare = prepare =
addMeta "link-citations" (MetaBool True) addMeta "link-citations" (MetaBool True)
. addMeta "reference-section-title" (MetaInlines [Str "References"]) . addMeta "reference-section-title" (MetaInlines [Str "References"])
. myFilter . myFilter macros
readPandocWith chaoDocRead bodyWithMacros readPandocWith chaoDocRead bodyWithMacros
>>= processPandocBiblio csl bib . fmap prepare >>= processPandocBiblio csl bib . fmap prepare
chaoDocCompiler :: Compiler (Item String) chaoDocCompiler :: ChaoDocFiles -> Compiler (Item String)
chaoDocCompiler = chaoDocPandocCompiler <&> writePandocWith chaoDocWrite chaoDocCompiler paths = chaoDocPandocCompiler paths <&> writePandocWith chaoDocWrite
addMeta :: T.Text -> MetaValue -> Pandoc -> Pandoc addMeta :: T.Text -> MetaValue -> Pandoc -> Pandoc
addMeta name value (Pandoc meta a) = addMeta name value (Pandoc meta a) =
@@ -77,8 +83,8 @@ addMeta name value (Pandoc meta a) =
newMeta = Meta newMap newMeta = Meta newMap
in Pandoc newMeta a in Pandoc newMeta a
myFilter :: Pandoc -> Pandoc myFilter :: Text -> Pandoc -> Pandoc
myFilter = usingSideNotesHTML chaoDocWrite . theoremFilter . panguFilter . equationFilter myFilter macros = usingSideNotesHTML chaoDocWrite . theoremFilter macros . panguFilter . equationFilter
pandocToInline :: Pandoc -> [Inline] pandocToInline :: Pandoc -> [Inline]
pandocToInline (Pandoc _ blocks) = go (reverse blocks) pandocToInline (Pandoc _ blocks) = go (reverse blocks)
@@ -184,8 +190,9 @@ normalizeTheoremClass :: Attr -> Text -> Attr
normalizeTheoremClass (ident, classes, attrs) theoremType = normalizeTheoremClass (ident, classes, attrs) theoremType =
(ident, theoremType : filter ((`notElem` theoremClasses) . normalizeBlockClass) classes, attrs) (ident, theoremType : filter ((`notElem` theoremClasses) . normalizeBlockClass) classes, attrs)
theoremFilter :: Pandoc -> Pandoc theoremFilter :: Text -> Pandoc -> Pandoc
theoremFilter doc = walk makeTheorem $ autorefFilter $ evalState (walkM preprocessTheorems doc) 1 theoremFilter macros doc =
walk (makeTheorem macros) $ autorefFilter $ evalState (walkM preprocessTheorems doc) 1
-- [index, type, idx] -- [index, type, idx]
theoremIndex :: Block -> [(Text, (Text, Text))] theoremIndex :: Block -> [(Text, (Text, Text))]
@@ -281,27 +288,16 @@ equationAutoref x (Cite citations inlines)
linkTitle = "Eq. (" <> num <> ")" linkTitle = "Eq. (" <> num <> ")"
equationAutoref _ y = y equationAutoref _ y = y
-- processCitations works on AST. If you want to use citations in theorem name,
-- then you need to convert citations there to AST as well and then use processCitations\
-- Thus one need to apply the theorem filter first.
-- autoref still does not work.
mathMacros :: Text
mathMacros = unsafePerformIO (pack <$> readFile macroFile)
{-# NOINLINE mathMacros #-}
prependMacros :: Text -> Text -> Text prependMacros :: Text -> Text -> Text
prependMacros macros body = macros <> "\n\n" <> body prependMacros macros body = macros <> "\n\n" <> body
prependMathMacros :: Text -> Text thmNamePandoc :: Text -> Text -> Pandoc
prependMathMacros = prependMacros mathMacros thmNamePandoc macros x =
thmNamePandoc :: Text -> Pandoc
thmNamePandoc x =
fromRight (Pandoc nullMeta []) . runPure $ fromRight (Pandoc nullMeta []) . runPure $
readMarkdown chaoDocRead (prependMathMacros x) readMarkdown chaoDocRead (prependMacros macros x)
makeTheorem :: Block -> Block makeTheorem :: Text -> Block -> Block
makeTheorem (Div attr xs) makeTheorem macros (Div attr xs)
| isNothing t = Div attr xs | isNothing t = Div attr xs
| otherwise = Div (addClass attr "theorem-environment") (Plain [header] : xs) | otherwise = Div (addClass attr "theorem-environment") (Plain [header] : xs)
where where
@@ -318,8 +314,8 @@ makeTheorem (Div attr xs)
nametext = nametext =
if isNothing name if isNothing name
then Str "" then Str ""
else Span (addClass nullAttr "name") (pandocToInline $ thmNamePandoc $ fromJust name) else Span (addClass nullAttr "name") (pandocToInline $ thmNamePandoc macros $ fromJust name)
makeTheorem x = x makeTheorem _ x = x
-- pangu filter -- pangu filter
lastChar :: Inline -> Maybe Char lastChar :: Inline -> Maybe Char

View File

@@ -9,8 +9,46 @@ import Hakyll
import System.FilePath import System.FilePath
import Text.Pandoc import Text.Pandoc
mds :: Pattern mdfiles :: Pattern
mds = "main.md" mdfiles = "main.md"
images :: Pattern
images = "images/**"
mathMacro :: FilePath
mathMacro = "assets/math-macros.tex"
cslfile :: FilePath
cslfile = "assets/bib_style.csl"
reference :: FilePath
reference = "ref.bib"
fonts :: Pattern
fonts = "assets/fonts/*"
favicon :: FilePath
favicon = "assets/favicon.ico"
css :: Pattern
css = "assets/css/*"
templatesPattern :: Pattern
templatesPattern = "assets/templates/*"
templateDefault :: Identifier
templateDefault = fromFilePath "assets/templates/default.html"
templatePostlist :: Identifier
templatePostlist = fromFilePath "assets/templates/post-list.html"
chaoDocFiles :: ChaoDocFiles
chaoDocFiles =
ChaoDocFiles
{ chaoDocCslFile = cslfile,
chaoDocBibFile = reference,
chaoDocMacroFile = mathMacro
}
config :: Configuration config :: Configuration
config = config =
@@ -22,52 +60,51 @@ config =
main :: IO () main :: IO ()
main = hakyllWith config $ do main = hakyllWith config $ do
match "images/**" $ do match images $ do
route idRoute route idRoute
compile copyFileCompiler compile copyFileCompiler
match "assets/math-macros.tex" $ compile getResourceBody match (fromGlob mathMacro) $ compile getResourceBody
match "assets/bib_style.csl" $ compile cslCompiler match (fromGlob cslfile) $ compile cslCompiler
match "ref.bib" $ compile biblioCompiler match (fromGlob reference) $ compile biblioCompiler
match "assets/fonts/*" $ do match fonts $ do
route $ gsubRoute "assets/fonts/" (const "fonts/") route $ gsubRoute "assets/fonts/" (const "fonts/")
compile copyFileCompiler compile copyFileCompiler
match "assets/favicon.ico" $ do match (fromGlob favicon) $ do
route $ constRoute "favicon.ico" route $ constRoute "favicon.ico"
compile copyFileCompiler compile copyFileCompiler
match "assets/css/*" $ do match css $ do
route $ gsubRoute "assets/css/" (const "css/") route $ gsubRoute "assets/css/" (const "css/")
compile compressCssCompiler compile compressCssCompiler
match mds $ do match mdfiles $ do
route $ setExtension "html" route $ setExtension "html"
compile $ do compile $ do
tocCtx <- getTocCtx defaultContext tocCtx <- getTocCtx defaultContext
chaoDocCompiler chaoDocCompiler chaoDocFiles
>>= loadAndApplyTemplate "assets/templates/post.html" tocCtx >>= loadAndApplyTemplate templateDefault tocCtx
>>= loadAndApplyTemplate "assets/templates/default.html" tocCtx
>>= relativizeUrls >>= relativizeUrls
create ["index.html"] $ do create ["index.html"] $ do
route idRoute route idRoute
compile $ do compile $ do
posts <- loadAll mds posts <- loadAll mdfiles
let indexCtx = let indexCtx =
constField "title" "Notes" constField "title" ""
`mappend` constField "toc" "" `mappend` constField "toc" ""
`mappend` listField "posts" postCtx (return posts) `mappend` listField "posts" postCtx (return posts)
`mappend` defaultContext `mappend` defaultContext
makeItem "" makeItem ""
>>= loadAndApplyTemplate "assets/templates/post-list.html" indexCtx >>= loadAndApplyTemplate templatePostlist indexCtx
>>= loadAndApplyTemplate "assets/templates/default.html" indexCtx >>= loadAndApplyTemplate templateDefault indexCtx
>>= relativizeUrls >>= relativizeUrls
match "assets/templates/*" $ compile templateBodyCompiler match templatesPattern $ compile templateBodyCompiler
postCtx :: Context String postCtx :: Context String
postCtx = postCtx =
@@ -80,7 +117,7 @@ getTocCtx :: Context a -> Compiler (Context a)
getTocCtx ctx = do getTocCtx ctx = do
noToc <- (Just "true" ==) <$> (getUnderlying >>= (`getMetadataField` "no-toc")) noToc <- (Just "true" ==) <$> (getUnderlying >>= (`getMetadataField` "no-toc"))
writerOpts <- mkTocWriter defaultHakyllWriterOptions writerOpts <- mkTocWriter defaultHakyllWriterOptions
toc <- writePandocWith writerOpts <$> chaoDocPandocCompiler toc <- writePandocWith writerOpts <$> chaoDocPandocCompiler chaoDocFiles
pure $ pure $
mconcat mconcat
[ ctx, [ ctx,
@@ -94,6 +131,7 @@ getTocCtx ctx = do
pure $ pure $
writerOpts writerOpts
{ writerTableOfContents = True, { writerTableOfContents = True,
writerNumberSections = True,
writerTOCDepth = 2, writerTOCDepth = 2,
writerTemplate = tmpl, writerTemplate = tmpl,
writerHTMLMathMethod = MathML writerHTMLMathMethod = MathML