initial draft of markdown and typst both working

This commit is contained in:
Pagwin 2024-08-17 16:16:58 -04:00
parent 324a6b5a22
commit 80970cc18c
No known key found for this signature in database
GPG key ID: 81137023740CA260
3 changed files with 31 additions and 9 deletions

View file

@ -6,6 +6,7 @@ outputDir = "publish"
assetGlobs :: [String]
assetGlobs = ["static//*"]
-- CAN ONLY BE TYPST DOCS UNLESS YOU CHANGE THINGS AT THE `pages` RULE in `Main.hs
pagePaths :: [String]
pagePaths = ["links.typ"]

View file

@ -20,6 +20,7 @@ import Config
import Types
import Utilities
import Templates
import Data.Time
-- target = thing we want
-- Rule = pattern of thing being made + actions to produce the thing
-- Action = actions to produce a thing
@ -68,8 +69,8 @@ assets = map (outputDir </>) assetGlobs |%> \target -> do
pages :: Rules ()
pages = map indexHtmlOutputPath pagePaths |%> \target -> do
let src = indexHtmlSourcePath target
let metaSrc = indexHtmlMetaPath target
let src = indexHtmlTypstSourcePath target
let metaSrc = indexHtmlTypstMetaPath target
html <- typstToHtml src
meta <- yamlToPost metaSrc
let page = Page (postTitle meta) html
@ -78,7 +79,7 @@ pages = map indexHtmlOutputPath pagePaths |%> \target -> do
typstPostsRule :: Rules ()
typstPostsRule = map indexHtmlOutputPath postGlobs |%> \target -> do
let src = indexHtmlSourcePath target
let src = indexHtmlTypstSourcePath target
post <- readTypstPost src
postHtml <- applyTemplate "post.html" post
@ -88,7 +89,7 @@ typstPostsRule = map indexHtmlOutputPath postGlobs |%> \target -> do
markdownPostsRule :: Rules ()
markdownPostsRule = map indexHtmlOutputPath postGlobs |%> \target -> do
let src = indexHtmlSourcePath target
let src = indexHtmlMarkdownSourcePath target
post <- readMarkdownPost src
postHtml <- applyTemplate "post.html" post
@ -116,6 +117,13 @@ rss = outputDir </> "index.xml" %> \target -> do
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 postPath = do
html <- typstToHtml postPath

View file

@ -20,15 +20,28 @@ indexHtmlOutputPath :: FilePath -> FilePath
indexHtmlOutputPath srcPath =
outputDir </> Shake.dropExtension srcPath </> "index.html"
indexHtmlSourcePath :: FilePath -> FilePath
indexHtmlSourcePath =
Shake.dropDirectory1
-- were applicative shenanigans necessary? no
-- but using them felt cool
indexHtmlSourcePaths :: FilePath -> [FilePath]
indexHtmlSourcePaths path = [indexHtmlTypstSourcePath, indexHtmlMarkdownSourcePath] <*> [path]
indexHtmlTypstSourcePath :: FilePath -> FilePath
indexHtmlTypstSourcePath =
Shake.dropDirectory1
. (<.> "typ")
. Shake.dropTrailingPathSeparator
. Shake.dropFileName
indexHtmlMetaPath :: FilePath -> FilePath
indexHtmlMetaPath = typstMetaPath . indexHtmlSourcePath
indexHtmlMarkdownSourcePath :: FilePath -> FilePath
indexHtmlMarkdownSourcePath =
Shake.dropDirectory1
. (<.> "md")
. Shake.dropTrailingPathSeparator
. Shake.dropFileName
indexHtmlTypstMetaPath :: FilePath -> FilePath
indexHtmlTypstMetaPath = typstMetaPath . indexHtmlTypstSourcePath
typstMetaPath :: FilePath -> FilePath
typstMetaPath typstPath = Shake.dropExtension typstPath <.> "yaml"