From 8fb8b3c1762aa2b253afbc410672f74342412361 Mon Sep 17 00:00:00 2001 From: Pagwin Date: Thu, 16 Jan 2025 02:15:49 -0500 Subject: [PATCH] ripped out typst, next step is to supplant pandoc for markdown with a custom parser --- app/Config.hs | 2 +- app/Main.hs | 56 ------------------------------------------------ app/Utilities.hs | 33 ++-------------------------- 3 files changed, 3 insertions(+), 88 deletions(-) diff --git a/app/Config.hs b/app/Config.hs index 17ba566..275c7a7 100644 --- a/app/Config.hs +++ b/app/Config.hs @@ -11,4 +11,4 @@ pagePaths :: [String] pagePaths = [] postGlobs :: [String] -postGlobs = ["posts/*.typ", "posts/*.md"] +postGlobs = ["posts/*.md"] diff --git a/app/Main.hs b/app/Main.hs index 474e1db..62f09a7 100644 --- a/app/Main.hs +++ b/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 diff --git a/app/Utilities.hs b/app/Utilities.hs index 2186cbe..b741827 100644 --- a/app/Utilities.hs +++ b/app/Utilities.hs @@ -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