Skip to content

Update to basic-ssg script for local dev, and CONTRIBUTING instructions #184

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

# local dev website files
dist
build
main

# generated docs
Expand Down
22 changes: 14 additions & 8 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand All @@ -49,4 +55,4 @@ View the website:
```
cd ./build
simple-http-server --nocache --index
```
```
64 changes: 64 additions & 0 deletions main.roc
Original file line number Diff line number Diff line change
@@ -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,
]
Loading