From 7be85f3c8ea51f53b9c974ea4d7ff98934da313f Mon Sep 17 00:00:00 2001 From: Luke Boswell Date: Mon, 17 Jun 2024 17:24:21 +1000 Subject: [PATCH] update to basic-ssg script for local dev, and CONTRIBUTING instructions --- .gitignore | 1 + CONTRIBUTING.md | 22 ++++++++++------- main.roc | 64 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+), 8 deletions(-) create mode 100644 main.roc diff --git a/.gitignore b/.gitignore index 66dd9c5..06513dc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ # local dev website files dist +build main # generated docs diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 533e697..e41b573 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -29,18 +29,24 @@ Clone the Roc repo if you don't have it already: git clone https://github.com/roc-lang/roc.git ``` -Update the path in the file `./main.roc` (of the example repo): -``` -packages { pf: "/PATH_TO_ROC_REPO/examples/static-site-gen/platform/main.roc" } -``` Generate the html files: ``` -roc run main.roc -- examples build +roc run main.roc -- examples build ``` -Copy the static assets from `./www` to `./build`: +Copy the static assets from `./www` to `./build` (only need to do this one time): ``` -cp ./wwww/* ./build +wget -O build/site.js https://www.roc-lang.org/site.js +wget -O build/site.css https://www.roc-lang.org/site.css + +mkdir -p build/fonts/lato-v23-latin +wget -O build/fonts/lato-v23-latin/lato-v23-latin-regular.woff2 https://www.roc-lang.org/fonts/lato-v23-latin/lato-v23-latin-regular.woff2 + +mkdir -p build/fonts/permanent-marker-v16-latin +wget -O build/fonts/permanent-marker-v16-latin/permanent-marker-v16-latin-regular.woff2 https://www.roc-lang.org/fonts/permanent-marker-v16-latin/permanent-marker-v16-latin-regular.woff2 + +mkdir -p build/fonts/source-code-pro-v22-latin +wget -O build/fonts/source-code-pro-v22-latin/source-code-pro-v22-latin-regular.woff2 https://www.roc-lang.org/fonts/source-code-pro-v22-latin/source-code-pro-v22-latin-regular.woff2 ``` If you're using the nix flake, simple-http-server will already be installed. Without nix you can do `cargo install simple-http-server`. @@ -49,4 +55,4 @@ View the website: ``` cd ./build simple-http-server --nocache --index -``` \ No newline at end of file +``` diff --git a/main.roc b/main.roc new file mode 100644 index 0000000..13514d8 --- /dev/null +++ b/main.roc @@ -0,0 +1,64 @@ +app [main] { pf: platform "https://github.com/lukewilliamboswell/basic-ssg/releases/download/0.1.0/EMH2OFwcXCUEzbwP6gyfeRQu7Phr-slc-vE8FPPreys.tar.br" } + +import pf.Task exposing [Task] +import pf.SSG +import pf.Types exposing [Args] +import pf.Html exposing [link, title, script, footer, div, text, p, html, head, body, meta] +import pf.Html.Attributes exposing [class, type, src, name, charset, href, rel, content, lang] + +main : Args -> Task {} _ +main = \{ inputDir, outputDir } -> + + # get the path and url of markdown files in content directory + files = SSG.files! inputDir + + # helper Task to process each file + processFile = \{ path, relpath, url } -> + + inHtml = SSG.parseMarkdown! path + + outHtml = transformFileContent url inHtml + + SSG.writeFile { outputDir, relpath, content: outHtml } + ## process each file + Task.forEach! files processFile + +transformFileContent : Str, Str -> Str +transformFileContent = \fileName, htmlContent -> Html.render (view fileName htmlContent) + +view : Str, Str -> Html.Node +view = \fileName, htmlContent -> + viewContent = + when fileName is + "index.html" -> viewIndex htmlContent + _ -> viewExample htmlContent + + html [lang "en"] [ + head [] [ + title [] [text "Roc Examples"], + meta [charset "utf-8"], + meta [name "viewport", content "width=device-width"], + link [rel "icon", href "/favicon.svg"], + link [rel "stylesheet", href "/site.css"], + script [type "text/javascript", src "/site.js"] [], + ], + body [] [ + div [class "top-header-extension"] [], + viewContent, + footer [] [ + p [] [text "Made by people who like to make nice things © 2023"], + ], + ], + ] + +viewIndex : Str -> Html.Node +viewIndex = \htmlContent -> + Html.main [] [ + text htmlContent, + ] + +viewExample : Str -> Html.Node +viewExample = \htmlContent -> + Html.main [] [ + text htmlContent, + ]