ripped out typst, next step is to supplant pandoc for markdown with a custom parser
This commit is contained in:
parent
9d776d9c39
commit
8fb8b3c176
3 changed files with 3 additions and 88 deletions
|
@ -11,4 +11,4 @@ pagePaths :: [String]
|
||||||
pagePaths = []
|
pagePaths = []
|
||||||
|
|
||||||
postGlobs :: [String]
|
postGlobs :: [String]
|
||||||
postGlobs = ["posts/*.typ", "posts/*.md"]
|
postGlobs = ["posts/*.md"]
|
||||||
|
|
56
app/Main.hs
56
app/Main.hs
|
@ -59,7 +59,6 @@ buildRules :: Rules ()
|
||||||
buildRules = do
|
buildRules = do
|
||||||
home
|
home
|
||||||
assets
|
assets
|
||||||
pages
|
|
||||||
postsRule
|
postsRule
|
||||||
rss
|
rss
|
||||||
|
|
||||||
|
@ -70,28 +69,6 @@ assets =
|
||||||
let src = FP.dropDirectory1 target
|
let src = FP.dropDirectory1 target
|
||||||
Shake.copyFileChanged src target
|
Shake.copyFileChanged src target
|
||||||
|
|
||||||
-- Shake.putInfo $ "Copied " <> target <> " from " <> src
|
|
||||||
|
|
||||||
-- handling typst only because pages should only be typst no reason for backwards compat on that
|
|
||||||
pages :: Rules ()
|
|
||||||
pages =
|
|
||||||
map indexHtmlOutputPath pagePaths |%> \target -> do
|
|
||||||
let src = indexHtmlTypstSourcePath target
|
|
||||||
let metaSrc = indexHtmlTypstMetaPath target
|
|
||||||
html <- typstToHtml src
|
|
||||||
meta <- yamlToPost metaSrc
|
|
||||||
time <- Utilities.now
|
|
||||||
let page =
|
|
||||||
Page
|
|
||||||
{ pageTitle = postTitle meta,
|
|
||||||
pageContent = html,
|
|
||||||
pageNow = time,
|
|
||||||
pageSection = T.pack $ fromJust $ Shake.stripExtension "html" target
|
|
||||||
}
|
|
||||||
applyTemplateAndWrite "default.html" page target
|
|
||||||
|
|
||||||
-- Shake.putInfo $ "Built " <> target <> " from " <> src
|
|
||||||
|
|
||||||
-- there's probably a better way of doing this that allows for the target's origin file extension to get passed in but for now we're doing brute force
|
-- there's probably a better way of doing this that allows for the target's origin file extension to get passed in but for now we're doing brute force
|
||||||
postsRule :: Rules ()
|
postsRule :: Rules ()
|
||||||
postsRule =
|
postsRule =
|
||||||
|
@ -105,33 +82,12 @@ postsRule =
|
||||||
when
|
when
|
||||||
should
|
should
|
||||||
( case FP.takeExtension path of
|
( case FP.takeExtension path of
|
||||||
".typ" -> typstPost path
|
|
||||||
".md" -> markdownPost path
|
".md" -> markdownPost path
|
||||||
_ -> error $ "invalid file extension for post " <> target
|
_ -> error $ "invalid file extension for post " <> target
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
return ()
|
return ()
|
||||||
|
|
||||||
typstPost :: FP.FilePath -> Action ()
|
|
||||||
typstPost src = do
|
|
||||||
Shake.need [src]
|
|
||||||
let target = indexHtmlOutputPath src
|
|
||||||
|
|
||||||
post <- readTypstPost src
|
|
||||||
let rPost = fromPost post
|
|
||||||
postHtml <- applyTemplate "post.html" rPost
|
|
||||||
time <- Utilities.now
|
|
||||||
let page =
|
|
||||||
Page
|
|
||||||
{ pageTitle = rPostTitle rPost,
|
|
||||||
pageContent = postHtml,
|
|
||||||
pageNow = time,
|
|
||||||
pageSection = T.pack $ fromJust $ Shake.stripExtension "html" target
|
|
||||||
}
|
|
||||||
applyTemplateAndWrite "default.html" page target
|
|
||||||
|
|
||||||
-- Shake.putInfo $ "Built " <> target <> " from " <> src
|
|
||||||
|
|
||||||
markdownPost :: FP.FilePath -> Action ()
|
markdownPost :: FP.FilePath -> Action ()
|
||||||
markdownPost src = do
|
markdownPost src = do
|
||||||
Shake.need [src]
|
Shake.need [src]
|
||||||
|
@ -195,21 +151,9 @@ rss =
|
||||||
readPost :: FilePath -> Action Post
|
readPost :: FilePath -> Action Post
|
||||||
readPost postPath = do
|
readPost postPath = do
|
||||||
case FP.takeExtension postPath of
|
case FP.takeExtension postPath of
|
||||||
".typ" -> readTypstPost postPath
|
|
||||||
".md" -> readMarkdownPost postPath
|
".md" -> readMarkdownPost postPath
|
||||||
_ -> error $ "unknown file extension for file" <> postPath
|
_ -> error $ "unknown file extension for file" <> postPath
|
||||||
|
|
||||||
readTypstPost :: FilePath -> Action Post
|
|
||||||
readTypstPost postPath = do
|
|
||||||
html <- typstToHtml postPath
|
|
||||||
post <- yamlToPost $ typstMetaPath postPath
|
|
||||||
-- Shake.putInfo $ "Read " <> postPath
|
|
||||||
return $
|
|
||||||
post
|
|
||||||
{ postContent = Just html,
|
|
||||||
postLink = Just . T.pack $ "/" <> FP.dropExtension postPath <> "/"
|
|
||||||
}
|
|
||||||
|
|
||||||
readMarkdownPost :: FilePath -> Action Post
|
readMarkdownPost :: FilePath -> Action Post
|
||||||
readMarkdownPost postPath = do
|
readMarkdownPost postPath = do
|
||||||
(post, html) <- markdownToHtml postPath
|
(post, html) <- markdownToHtml postPath
|
||||||
|
|
|
@ -25,14 +25,7 @@ indexHtmlOutputPath srcPath =
|
||||||
-- were applicative shenanigans necessary? no
|
-- were applicative shenanigans necessary? no
|
||||||
-- but using them felt cool
|
-- but using them felt cool
|
||||||
indexHtmlSourcePaths :: FilePath -> [FilePath]
|
indexHtmlSourcePaths :: FilePath -> [FilePath]
|
||||||
indexHtmlSourcePaths path = [indexHtmlTypstSourcePath, indexHtmlMarkdownSourcePath] <*> [path]
|
indexHtmlSourcePaths path = [indexHtmlMarkdownSourcePath] <*> [path]
|
||||||
|
|
||||||
indexHtmlTypstSourcePath :: FilePath -> FilePath
|
|
||||||
indexHtmlTypstSourcePath =
|
|
||||||
FP.dropDirectory1
|
|
||||||
. (<.> "typ")
|
|
||||||
. FP.dropTrailingPathSeparator
|
|
||||||
. FP.dropFileName
|
|
||||||
|
|
||||||
indexHtmlMarkdownSourcePath :: FilePath -> FilePath
|
indexHtmlMarkdownSourcePath :: FilePath -> FilePath
|
||||||
indexHtmlMarkdownSourcePath =
|
indexHtmlMarkdownSourcePath =
|
||||||
|
@ -41,25 +34,6 @@ indexHtmlMarkdownSourcePath =
|
||||||
. FP.dropTrailingPathSeparator
|
. FP.dropTrailingPathSeparator
|
||||||
. FP.dropFileName
|
. FP.dropFileName
|
||||||
|
|
||||||
indexHtmlTypstMetaPath :: FilePath -> FilePath
|
|
||||||
indexHtmlTypstMetaPath = typstMetaPath . indexHtmlTypstSourcePath
|
|
||||||
|
|
||||||
typstMetaPath :: FilePath -> FilePath
|
|
||||||
typstMetaPath typstPath = FP.dropExtension typstPath <.> "yaml"
|
|
||||||
|
|
||||||
typstToHtml :: FilePath -> Action Text
|
|
||||||
typstToHtml filePath = do
|
|
||||||
content <- Shake.readFile' filePath
|
|
||||||
Shake.quietly . Shake.traced "Typst to HTML" $ do
|
|
||||||
doc <- runPandoc . Pandoc.readTypst readerOptions . T.pack $ content
|
|
||||||
html <- runPandoc . Pandoc.writeHtml5String writerOptions $ doc
|
|
||||||
return html
|
|
||||||
where
|
|
||||||
readerOptions =
|
|
||||||
Pandoc.def {Pandoc.readerExtensions = Pandoc.pandocExtensions}
|
|
||||||
writerOptions =
|
|
||||||
Pandoc.def {Pandoc.writerExtensions = Pandoc.pandocExtensions}
|
|
||||||
|
|
||||||
markdownToHtml :: (FromJSON a) => FilePath -> Action (a, Text)
|
markdownToHtml :: (FromJSON a) => FilePath -> Action (a, Text)
|
||||||
markdownToHtml filePath = do
|
markdownToHtml filePath = do
|
||||||
content <- Shake.readFile' filePath
|
content <- Shake.readFile' filePath
|
||||||
|
@ -137,14 +111,11 @@ yamlToPost path = do
|
||||||
-- let post' = dateTransform post
|
-- let post' = dateTransform post
|
||||||
return post
|
return post
|
||||||
|
|
||||||
isTypstPost :: FilePath -> Bool
|
|
||||||
isTypstPost path = FP.takeExtension path == ".typ"
|
|
||||||
|
|
||||||
isMarkdownPost :: FilePath -> Bool
|
isMarkdownPost :: FilePath -> Bool
|
||||||
isMarkdownPost path = FP.takeExtension path == ".md"
|
isMarkdownPost path = FP.takeExtension path == ".md"
|
||||||
|
|
||||||
postHandles :: [(FilePath -> Bool, FilePath -> Action Post)]
|
postHandles :: [(FilePath -> Bool, FilePath -> Action Post)]
|
||||||
postHandles = [(isTypstPost, yamlToPost . typstMetaPath), (isMarkdownPost, markdownToPost)]
|
postHandles = [(isMarkdownPost, markdownToPost)]
|
||||||
|
|
||||||
isDraft :: FilePath -> Action Bool
|
isDraft :: FilePath -> Action Bool
|
||||||
isDraft path = do
|
isDraft path = do
|
||||||
|
|
Loading…
Reference in a new issue