initial draft of markdown and typst both working
This commit is contained in:
parent
324a6b5a22
commit
80970cc18c
3 changed files with 31 additions and 9 deletions
|
@ -6,6 +6,7 @@ outputDir = "publish"
|
||||||
assetGlobs :: [String]
|
assetGlobs :: [String]
|
||||||
assetGlobs = ["static//*"]
|
assetGlobs = ["static//*"]
|
||||||
|
|
||||||
|
-- CAN ONLY BE TYPST DOCS UNLESS YOU CHANGE THINGS AT THE `pages` RULE in `Main.hs
|
||||||
pagePaths :: [String]
|
pagePaths :: [String]
|
||||||
pagePaths = ["links.typ"]
|
pagePaths = ["links.typ"]
|
||||||
|
|
||||||
|
|
16
app/Main.hs
16
app/Main.hs
|
@ -20,6 +20,7 @@ import Config
|
||||||
import Types
|
import Types
|
||||||
import Utilities
|
import Utilities
|
||||||
import Templates
|
import Templates
|
||||||
|
import Data.Time
|
||||||
-- target = thing we want
|
-- target = thing we want
|
||||||
-- Rule = pattern of thing being made + actions to produce the thing
|
-- Rule = pattern of thing being made + actions to produce the thing
|
||||||
-- Action = actions to produce a thing
|
-- Action = actions to produce a thing
|
||||||
|
@ -68,8 +69,8 @@ assets = map (outputDir </>) assetGlobs |%> \target -> do
|
||||||
|
|
||||||
pages :: Rules ()
|
pages :: Rules ()
|
||||||
pages = map indexHtmlOutputPath pagePaths |%> \target -> do
|
pages = map indexHtmlOutputPath pagePaths |%> \target -> do
|
||||||
let src = indexHtmlSourcePath target
|
let src = indexHtmlTypstSourcePath target
|
||||||
let metaSrc = indexHtmlMetaPath target
|
let metaSrc = indexHtmlTypstMetaPath target
|
||||||
html <- typstToHtml src
|
html <- typstToHtml src
|
||||||
meta <- yamlToPost metaSrc
|
meta <- yamlToPost metaSrc
|
||||||
let page = Page (postTitle meta) html
|
let page = Page (postTitle meta) html
|
||||||
|
@ -78,7 +79,7 @@ pages = map indexHtmlOutputPath pagePaths |%> \target -> do
|
||||||
|
|
||||||
typstPostsRule :: Rules ()
|
typstPostsRule :: Rules ()
|
||||||
typstPostsRule = map indexHtmlOutputPath postGlobs |%> \target -> do
|
typstPostsRule = map indexHtmlOutputPath postGlobs |%> \target -> do
|
||||||
let src = indexHtmlSourcePath target
|
let src = indexHtmlTypstSourcePath target
|
||||||
post <- readTypstPost src
|
post <- readTypstPost src
|
||||||
postHtml <- applyTemplate "post.html" post
|
postHtml <- applyTemplate "post.html" post
|
||||||
|
|
||||||
|
@ -88,7 +89,7 @@ typstPostsRule = map indexHtmlOutputPath postGlobs |%> \target -> do
|
||||||
|
|
||||||
markdownPostsRule :: Rules ()
|
markdownPostsRule :: Rules ()
|
||||||
markdownPostsRule = map indexHtmlOutputPath postGlobs |%> \target -> do
|
markdownPostsRule = map indexHtmlOutputPath postGlobs |%> \target -> do
|
||||||
let src = indexHtmlSourcePath target
|
let src = indexHtmlMarkdownSourcePath target
|
||||||
post <- readMarkdownPost src
|
post <- readMarkdownPost src
|
||||||
postHtml <- applyTemplate "post.html" post
|
postHtml <- applyTemplate "post.html" post
|
||||||
|
|
||||||
|
@ -116,6 +117,13 @@ rss = outputDir </> "index.xml" %> \target -> do
|
||||||
|
|
||||||
Shake.putInfo $ "Built " <> target
|
Shake.putInfo $ "Built " <> target
|
||||||
|
|
||||||
|
readPost :: FilePath -> Action Post
|
||||||
|
readPost postPath = do
|
||||||
|
case Shake.takeExtension postPath of
|
||||||
|
".typ" -> readTypstPost postPath
|
||||||
|
".md" -> readMarkdownPost postPath
|
||||||
|
_ -> error $ "unknown file extension for file" <> postPath
|
||||||
|
|
||||||
readTypstPost :: FilePath -> Action Post
|
readTypstPost :: FilePath -> Action Post
|
||||||
readTypstPost postPath = do
|
readTypstPost postPath = do
|
||||||
html <- typstToHtml postPath
|
html <- typstToHtml postPath
|
||||||
|
|
|
@ -20,15 +20,28 @@ indexHtmlOutputPath :: FilePath -> FilePath
|
||||||
indexHtmlOutputPath srcPath =
|
indexHtmlOutputPath srcPath =
|
||||||
outputDir </> Shake.dropExtension srcPath </> "index.html"
|
outputDir </> Shake.dropExtension srcPath </> "index.html"
|
||||||
|
|
||||||
indexHtmlSourcePath :: FilePath -> FilePath
|
|
||||||
indexHtmlSourcePath =
|
-- were applicative shenanigans necessary? no
|
||||||
|
-- but using them felt cool
|
||||||
|
indexHtmlSourcePaths :: FilePath -> [FilePath]
|
||||||
|
indexHtmlSourcePaths path = [indexHtmlTypstSourcePath, indexHtmlMarkdownSourcePath] <*> [path]
|
||||||
|
|
||||||
|
indexHtmlTypstSourcePath :: FilePath -> FilePath
|
||||||
|
indexHtmlTypstSourcePath =
|
||||||
Shake.dropDirectory1
|
Shake.dropDirectory1
|
||||||
. (<.> "typ")
|
. (<.> "typ")
|
||||||
. Shake.dropTrailingPathSeparator
|
. Shake.dropTrailingPathSeparator
|
||||||
. Shake.dropFileName
|
. Shake.dropFileName
|
||||||
|
|
||||||
indexHtmlMetaPath :: FilePath -> FilePath
|
indexHtmlMarkdownSourcePath :: FilePath -> FilePath
|
||||||
indexHtmlMetaPath = typstMetaPath . indexHtmlSourcePath
|
indexHtmlMarkdownSourcePath =
|
||||||
|
Shake.dropDirectory1
|
||||||
|
. (<.> "md")
|
||||||
|
. Shake.dropTrailingPathSeparator
|
||||||
|
. Shake.dropFileName
|
||||||
|
|
||||||
|
indexHtmlTypstMetaPath :: FilePath -> FilePath
|
||||||
|
indexHtmlTypstMetaPath = typstMetaPath . indexHtmlTypstSourcePath
|
||||||
|
|
||||||
typstMetaPath :: FilePath -> FilePath
|
typstMetaPath :: FilePath -> FilePath
|
||||||
typstMetaPath typstPath = Shake.dropExtension typstPath <.> "yaml"
|
typstMetaPath typstPath = Shake.dropExtension typstPath <.> "yaml"
|
||||||
|
|
Loading…
Reference in a new issue