4# Inputs (set by Nix derivation):
5# $src - user's site source directory
6# $out - Nix output path
7# $layoutsDir - path to our default layouts
8# $themeDir - path to our theme directory
11trap 'rm -rf "$tmpdir"' EXIT
15# --- Step 1: Generate manifest from site.dhall ---
16echo "Generating site manifest..."
17manifest="$tmpdir/manifest.json"
18dhall-to-json --file "$src/site.dhall" > "$manifest"
20# --- Step 2: Extract site metadata ---
21siteTitle=$(jq -r '.title' "$manifest")
22baseUrl=$(jq -r '.baseUrl' "$manifest")
23description=$(jq -r '.description' "$manifest")
25# --- Step 3: Render nav HTML ---
26navHtmlFile="$tmpdir/nav.txt"
27jq -r '.nav[] | "<a href=\"\(.url)\">\(.label)</a>"' "$manifest" \
28 | tr '\n' ' ' > "$navHtmlFile"
30# --- Helper: render content ---
32 local content_json="$1"
33 local content_type content_value
34 content_type=$(echo "$content_json" | jq -r '.tag')
35 content_value=$(echo "$content_json" | jq -r '.value')
37 case "$content_type" in
39 pandoc "$src/$content_value" -f markdown -t html --no-highlight
42 echo "$content_value" | pandoc -f markdown -t html --no-highlight
45 dhall text --file "$src/$content_value"
48 echo "Unknown content type: $content_type" >&2
54# --- Helper: format date ---
58 year=$(echo "$date_json" | jq -r '.year')
59 month=$(echo "$date_json" | jq -r '.month')
60 day=$(echo "$date_json" | jq -r '.day')
61 printf "%04d-%02d-%02d" "$year" "$month" "$day"
64# --- Helper: render tags HTML ---
68 count=$(echo "$tags_json" | jq -r 'length')
69 if [ "$count" -eq 0 ]; then
73 local result='<ul class="tags">'
74 while IFS= read -r tag; do
75 result+="<li>$tag</li>"
76 done < <(echo "$tags_json" | jq -r '.[]')
81# --- Helper: apply a Dhall layout ---
83 local layout_file="$1"
86let layout = $layout_file
92# --- Step 4: Build pages ---
93echo "Building pages..."
94page_count=$(jq -r '.pages | length' "$manifest")
95for ((i = 0; i < page_count; i++)); do
96 page_json=$(jq -r ".pages[$i]" "$manifest")
97 pageTitle=$(echo "$page_json" | jq -r '.title')
98 pageSlug=$(echo "$page_json" | jq -r '.slug')
99 content_json=$(echo "$page_json" | jq -r '.content')
101 echo " Page: $pageTitle ($pageSlug)"
103 contentFile="$tmpdir/content.txt"
104 render_content "$content_json" > "$contentFile"
106 echo -n "$siteTitle" > "$tmpdir/siteTitle.txt"
107 echo -n "$pageTitle" > "$tmpdir/pageTitle.txt"
109 argsFile="$tmpdir/args.dhall"
110 cat > "$argsFile" <<DHALL
111{ siteTitle = $tmpdir/siteTitle.txt as Text
112, pageTitle = $tmpdir/pageTitle.txt as Text
113, navHtml = $navHtmlFile as Text
114, contentHtml = $contentFile as Text
118 outDir="$out/$pageSlug"
120 apply_layout "$layoutsDir/page.dhall" "$argsFile" > "$outDir/index.html"
123# --- Step 5: Build posts ---
124echo "Building posts..."
125post_count=$(jq -r '.posts | length' "$manifest")
126postsHtmlFile="$tmpdir/posts_list.txt"
127rssItemsFile="$tmpdir/rss_items.txt"
131for ((i = 0; i < post_count; i++)); do
132 post_json=$(jq -r ".posts[$i]" "$manifest")
133 draft=$(echo "$post_json" | jq -r '.draft')
135 if [ "$draft" = "true" ]; then
139 postTitle=$(echo "$post_json" | jq -r '.title')
140 postSlug=$(echo "$post_json" | jq -r '.slug')
141 content_json=$(echo "$post_json" | jq -r '.content')
142 date_json=$(echo "$post_json" | jq -r '.date')
143 tags_json=$(echo "$post_json" | jq -r '.tags')
144 dateStr=$(format_date "$date_json")
146 echo " Post: $postTitle ($postSlug)"
148 contentFile="$tmpdir/content.txt"
149 render_content "$content_json" > "$contentFile"
151 tagsFile="$tmpdir/tags.txt"
152 render_tags "$tags_json" > "$tagsFile"
154 echo -n "$siteTitle" > "$tmpdir/siteTitle.txt"
155 echo -n "$postTitle" > "$tmpdir/postTitle.txt"
156 echo -n "$dateStr" > "$tmpdir/dateStr.txt"
158 argsFile="$tmpdir/args.dhall"
159 cat > "$argsFile" <<DHALL
160{ siteTitle = $tmpdir/siteTitle.txt as Text
161, postTitle = $tmpdir/postTitle.txt as Text
162, dateStr = $tmpdir/dateStr.txt as Text
163, tagsHtml = $tagsFile as Text
164, navHtml = $navHtmlFile as Text
165, contentHtml = $contentFile as Text
169 outDir="$out/posts/$postSlug"
171 apply_layout "$layoutsDir/post.dhall" "$argsFile" > "$outDir/index.html"
173 cat >> "$postsHtmlFile" <<HTML
174<article class="post-summary">
175 <h2><a href="/posts/$postSlug/">$postTitle</a></h2>
176 <time>$dateStr</time>
180 contentForRss=$(cat "$contentFile")
181 cat >> "$rssItemsFile" <<XML
183 <title>$postTitle</title>
184 <link>$baseUrl/posts/$postSlug/</link>
185 <guid>$baseUrl/posts/$postSlug/</guid>
186 <pubDate>$dateStr</pubDate>
187 <description><![CDATA[$contentForRss]]></description>
192# --- Step 6: Build index page ---
193echo "Building index page..."
194echo -n "$siteTitle" > "$tmpdir/siteTitle.txt"
195echo -n "$description" > "$tmpdir/description.txt"
197argsFile="$tmpdir/args.dhall"
198cat > "$argsFile" <<DHALL
199{ siteTitle = $tmpdir/siteTitle.txt as Text
200, description = $tmpdir/description.txt as Text
201, navHtml = $navHtmlFile as Text
202, postsHtml = $postsHtmlFile as Text
206apply_layout "$layoutsDir/index.dhall" "$argsFile" > "$out/index.html"
208# --- Step 7: Build RSS feed ---
209echo "Building RSS feed..."
210echo -n "$baseUrl" > "$tmpdir/baseUrl.txt"
212argsFile="$tmpdir/args.dhall"
213cat > "$argsFile" <<DHALL
214{ siteTitle = $tmpdir/siteTitle.txt as Text
215, baseUrl = $tmpdir/baseUrl.txt as Text
216, description = $tmpdir/description.txt as Text
217, itemsXml = $rssItemsFile as Text
221apply_layout "$layoutsDir/rss.dhall" "$argsFile" > "$out/rss.xml"
223# --- Step 8: Copy theme ---
224echo "Copying theme..."
225cp "$themeDir/style.css" "$out/style.css"
227echo "Build complete!"
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list