Skip to content

Commit 91cda53

Browse files
update to basic-ssg script for local dev, and CONTRIBUTING instructions
1 parent 18e614c commit 91cda53

File tree

3 files changed

+79
-8
lines changed

3 files changed

+79
-8
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

22
# local dev website files
33
dist
4+
build
45
main
56

67
# generated docs

CONTRIBUTING.md

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,24 @@ Clone the Roc repo if you don't have it already:
2929
git clone https://github.com/roc-lang/roc.git
3030
```
3131

32-
Update the path in the file `./main.roc` (of the example repo):
33-
```
34-
packages { pf: "/PATH_TO_ROC_REPO/examples/static-site-gen/platform/main.roc" }
35-
```
3632
Generate the html files:
3733
```
38-
roc run main.roc -- examples build
34+
roc run main.roc -- examples build
3935
```
4036

41-
Copy the static assets from `./www` to `./build`:
37+
Copy the static assets from `./www` to `./build` (only need to do this one time):
4238
```
43-
cp ./wwww/* ./build
39+
wget -O build/site.js https://www.roc-lang.org/site.js
40+
wget -O build/site.css https://www.roc-lang.org/site.css
41+
42+
mkdir -p build/fonts/lato-v23-latin
43+
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
44+
45+
mkdir -p build/fonts/permanent-marker-v16-latin
46+
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
47+
48+
mkdir -p build/fonts/source-code-pro-v22-latin
49+
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
4450
```
4551

4652
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:
4955
```
5056
cd ./build
5157
simple-http-server --nocache --index
52-
```
58+
```

main.roc

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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

Comments
 (0)