mirror of
http://101.35.51.105:3000/congyu/Hakysidian.git
synced 2026-04-28 14:00:50 +08:00
Introduce CLI, watch server, and bundled assets
Add data-files and bundled templates/fonts/css to the package and rename the executable to hakysidian (autogen Paths_hakysidian). Refactor site.hs to parse CLI commands (build/clean/rebuild/watch), start a preview server, snapshot inputs and run an incremental watch loop, and move rules into a siteRules function. Update ChaoDoc and filters to accept math-macros, and add favicon links to templates.
This commit is contained in:
+20
-33
@@ -124,9 +124,9 @@ preprocessTheorems (Div attr xs)
|
||||
attr' = addAttr attr "type" theoremType
|
||||
preprocessTheorems x = return x
|
||||
|
||||
theoremFilter :: Pandoc -> Pandoc
|
||||
theoremFilter doc =
|
||||
walk makeTheorem $
|
||||
theoremFilter :: Text -> Pandoc -> Pandoc
|
||||
theoremFilter mathMacros doc =
|
||||
walk (makeTheorem mathMacros) $
|
||||
autorefFilter $
|
||||
evalState (walkM preprocessTheorems normalizedDoc) 1
|
||||
where
|
||||
@@ -171,24 +171,13 @@ autorefFilter x = walk (autoref links) x
|
||||
where
|
||||
links = query theoremIndex x
|
||||
|
||||
-- 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 "math-macros.md")
|
||||
{-# NOINLINE mathMacros #-}
|
||||
|
||||
prependMacros :: Text -> Text -> Text
|
||||
prependMacros macros body = macros <> "\n\n" <> body
|
||||
|
||||
prependMathMacros :: Text -> Text
|
||||
prependMathMacros = prependMacros mathMacros
|
||||
|
||||
thmNamePandoc :: Text -> Pandoc
|
||||
thmNamePandoc x =
|
||||
thmNamePandoc :: Text -> Text -> Pandoc
|
||||
thmNamePandoc mathMacros x =
|
||||
fromRight (Pandoc nullMeta []) . runPure $
|
||||
readMarkdown chaoDocRead (prependMathMacros x)
|
||||
readMarkdown chaoDocRead (prependMacros mathMacros x)
|
||||
|
||||
obsidianTheoremFilter :: Pandoc -> Pandoc
|
||||
obsidianTheoremFilter = attachStandaloneLabels . walk rewriteObsidianBlockQuote
|
||||
@@ -390,8 +379,8 @@ unsnoc (x : xs) = do
|
||||
(prefix, lastElem) <- unsnoc xs
|
||||
return (x : prefix, lastElem)
|
||||
|
||||
makeTheorem :: Block -> Block
|
||||
makeTheorem (Div attr xs)
|
||||
makeTheorem :: Text -> Block -> Block
|
||||
makeTheorem mathMacros (Div attr xs)
|
||||
| isNothing t = Div attr xs
|
||||
| otherwise = Div (addClass attr "theorem-environment") (Plain [header] : xs)
|
||||
where
|
||||
@@ -408,26 +397,23 @@ makeTheorem (Div attr xs)
|
||||
nametext =
|
||||
if isNothing name
|
||||
then Str ""
|
||||
else Span (addClass nullAttr "name") (pandocToInline $ thmNamePandoc $ fromJust name)
|
||||
makeTheorem x = x
|
||||
else Span (addClass nullAttr "name") (pandocToInline $ thmNamePandoc mathMacros $ fromJust name)
|
||||
makeTheorem _ x = x
|
||||
|
||||
-- bib from https://github.com/chaoxu/chaoxu.github.io/tree/develop
|
||||
cslFile :: String
|
||||
cslFile = "bib_style.csl"
|
||||
|
||||
bibFile :: String
|
||||
bibFile :: T.Text
|
||||
bibFile = "reference.bib"
|
||||
|
||||
chaoDocPandocCompiler :: Compiler (Item Pandoc)
|
||||
chaoDocPandocCompiler = do
|
||||
chaoDocPandocCompiler :: FilePath -> Compiler (Item Pandoc)
|
||||
chaoDocPandocCompiler cslPath = do
|
||||
macros <- T.pack <$> loadBody "math-macros.md"
|
||||
void (loadBody "reference.bib" :: Compiler String)
|
||||
body <- getResourceBody
|
||||
let bodyWithMacros =
|
||||
fmap (T.unpack . prependMacros macros . T.pack) body
|
||||
myReadPandocBiblio chaoDocRead (T.pack cslFile) (T.pack bibFile) myFilter bodyWithMacros
|
||||
myReadPandocBiblio chaoDocRead (T.pack cslPath) bibFile (myFilter macros) bodyWithMacros
|
||||
|
||||
chaoDocCompiler :: Compiler (Item String)
|
||||
chaoDocCompiler = chaoDocPandocCompiler <&> writePandocWith chaoDocWrite
|
||||
chaoDocCompiler :: FilePath -> Compiler (Item String)
|
||||
chaoDocCompiler cslPath = chaoDocPandocCompiler cslPath <&> writePandocWith chaoDocWrite
|
||||
|
||||
addMeta :: T.Text -> MetaValue -> Pandoc -> Pandoc
|
||||
addMeta name value (Pandoc meta a) =
|
||||
@@ -465,8 +451,9 @@ myReadPandocBiblio ropt csl biblio pdfilter item = do
|
||||
-- let a x = itemSetBody (pandoc' x)
|
||||
return $ fmap (const pandoc') item
|
||||
|
||||
myFilter :: Pandoc -> Pandoc
|
||||
myFilter = usingSideNotesHTML chaoDocWrite . theoremFilter . panguFilter . displayMathFilter
|
||||
myFilter :: Text -> Pandoc -> Pandoc
|
||||
myFilter mathMacros =
|
||||
usingSideNotesHTML chaoDocWrite . theoremFilter mathMacros . panguFilter . displayMathFilter
|
||||
|
||||
-- pangu filter
|
||||
lastChar :: Inline -> Maybe Char
|
||||
|
||||
Reference in New Issue
Block a user