From 80970cc18c6105bb8ffb3100d9e29150b0472214 Mon Sep 17 00:00:00 2001 From: Pagwin Date: Sat, 17 Aug 2024 16:16:58 -0400 Subject: [PATCH] initial draft of markdown and typst both working --- app/Config.hs | 1 + app/Main.hs | 16 ++++++++++++---- app/Utilities.hs | 23 ++++++++++++++++++----- 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/app/Config.hs b/app/Config.hs index 9e76f87..0519f7c 100644 --- a/app/Config.hs +++ b/app/Config.hs @@ -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"] diff --git a/app/Main.hs b/app/Main.hs index 35673e0..8071d2e 100755 --- a/app/Main.hs +++ b/app/Main.hs @@ -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 diff --git a/app/Utilities.hs b/app/Utilities.hs index 8d7e930..9ce280d 100644 --- a/app/Utilities.hs +++ b/app/Utilities.hs @@ -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"