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 = []
|
||||
|
||||
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
|
||||
home
|
||||
assets
|
||||
pages
|
||||
postsRule
|
||||
rss
|
||||
|
||||
|
@ -70,28 +69,6 @@ assets =
|
|||
let src = FP.dropDirectory1 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
|
||||
postsRule :: Rules ()
|
||||
postsRule =
|
||||
|
@ -105,33 +82,12 @@ postsRule =
|
|||
when
|
||||
should
|
||||
( case FP.takeExtension path of
|
||||
".typ" -> typstPost path
|
||||
".md" -> markdownPost path
|
||||
_ -> error $ "invalid file extension for post " <> target
|
||||
)
|
||||
)
|
||||
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 src = do
|
||||
Shake.need [src]
|
||||
|
@ -195,21 +151,9 @@ rss =
|
|||
readPost :: FilePath -> Action Post
|
||||
readPost postPath = do
|
||||
case FP.takeExtension postPath of
|
||||
".typ" -> readTypstPost postPath
|
||||
".md" -> readMarkdownPost 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 postPath = do
|
||||
(post, html) <- markdownToHtml postPath
|
||||
|
|
|
@ -25,14 +25,7 @@ indexHtmlOutputPath srcPath =
|
|||
-- were applicative shenanigans necessary? no
|
||||
-- but using them felt cool
|
||||
indexHtmlSourcePaths :: FilePath -> [FilePath]
|
||||
indexHtmlSourcePaths path = [indexHtmlTypstSourcePath, indexHtmlMarkdownSourcePath] <*> [path]
|
||||
|
||||
indexHtmlTypstSourcePath :: FilePath -> FilePath
|
||||
indexHtmlTypstSourcePath =
|
||||
FP.dropDirectory1
|
||||
. (<.> "typ")
|
||||
. FP.dropTrailingPathSeparator
|
||||
. FP.dropFileName
|
||||
indexHtmlSourcePaths path = [indexHtmlMarkdownSourcePath] <*> [path]
|
||||
|
||||
indexHtmlMarkdownSourcePath :: FilePath -> FilePath
|
||||
indexHtmlMarkdownSourcePath =
|
||||
|
@ -41,25 +34,6 @@ indexHtmlMarkdownSourcePath =
|
|||
. FP.dropTrailingPathSeparator
|
||||
. 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 filePath = do
|
||||
content <- Shake.readFile' filePath
|
||||
|
@ -137,14 +111,11 @@ yamlToPost path = do
|
|||
-- let post' = dateTransform post
|
||||
return post
|
||||
|
||||
isTypstPost :: FilePath -> Bool
|
||||
isTypstPost path = FP.takeExtension path == ".typ"
|
||||
|
||||
isMarkdownPost :: FilePath -> Bool
|
||||
isMarkdownPost path = FP.takeExtension path == ".md"
|
||||
|
||||
postHandles :: [(FilePath -> Bool, FilePath -> Action Post)]
|
||||
postHandles = [(isTypstPost, yamlToPost . typstMetaPath), (isMarkdownPost, markdownToPost)]
|
||||
postHandles = [(isMarkdownPost, markdownToPost)]
|
||||
|
||||
isDraft :: FilePath -> Action Bool
|
||||
isDraft path = do
|
||||
|
|
Loading…
Reference in a new issue