|
| 1 | +app [main] { pf: platform "https://github.com/lukewilliamboswell/basic-ssg/releases/download/0.1.0/EMH2OFwcXCUEzbwP6gyfeRQu7Phr-slc-vE8FPPreys.tar.br" } |
| 2 | + |
| 3 | +import pf.Task exposing [Task] |
| 4 | +import pf.SSG |
| 5 | +import pf.Types exposing [Args] |
| 6 | +import pf.Html exposing [link, title, script, footer, div, text, p, html, head, body, meta] |
| 7 | +import pf.Html.Attributes exposing [class, type, src, name, charset, href, rel, content, lang] |
| 8 | + |
| 9 | +main : Args -> Task {} _ |
| 10 | +main = \{ inputDir, outputDir } -> |
| 11 | + |
| 12 | + # get the path and url of markdown files in content directory |
| 13 | + files = SSG.files! inputDir |
| 14 | + |
| 15 | + # helper Task to process each file |
| 16 | + processFile = \{ path, relpath, url } -> |
| 17 | + |
| 18 | + inHtml = SSG.parseMarkdown! path |
| 19 | + |
| 20 | + outHtml = transformFileContent url inHtml |
| 21 | + |
| 22 | + SSG.writeFile { outputDir, relpath, content: outHtml } |
| 23 | + ## process each file |
| 24 | + Task.forEach! files processFile |
| 25 | + |
| 26 | +transformFileContent : Str, Str -> Str |
| 27 | +transformFileContent = \fileName, htmlContent -> Html.render (view fileName htmlContent) |
| 28 | + |
| 29 | +view : Str, Str -> Html.Node |
| 30 | +view = \fileName, htmlContent -> |
| 31 | + viewContent = |
| 32 | + when fileName is |
| 33 | + "index.html" -> viewIndex htmlContent |
| 34 | + _ -> viewExample htmlContent |
| 35 | + |
| 36 | + html [lang "en"] [ |
| 37 | + head [] [ |
| 38 | + title [] [text "Roc Examples"], |
| 39 | + meta [charset "utf-8"], |
| 40 | + meta [name "viewport", content "width=device-width"], |
| 41 | + link [rel "icon", href "/favicon.svg"], |
| 42 | + link [rel "stylesheet", href "/site.css"], |
| 43 | + script [type "text/javascript", src "/site.js"] [], |
| 44 | + ], |
| 45 | + body [] [ |
| 46 | + div [class "top-header-extension"] [], |
| 47 | + viewContent, |
| 48 | + footer [] [ |
| 49 | + p [] [text "Made by people who like to make nice things © 2023"], |
| 50 | + ], |
| 51 | + ], |
| 52 | + ] |
| 53 | + |
| 54 | +viewIndex : Str -> Html.Node |
| 55 | +viewIndex = \htmlContent -> |
| 56 | + Html.main [] [ |
| 57 | + text htmlContent, |
| 58 | + ] |
| 59 | + |
| 60 | +viewExample : Str -> Html.Node |
| 61 | +viewExample = \htmlContent -> |
| 62 | + Html.main [] [ |
| 63 | + text htmlContent, |
| 64 | + ] |
0 commit comments