#!/bin/sh -e header() { cat < $1 | Carbs Linux

Carbs Linux - a simple busybox linux distribution

EOF } footer() { [ -z "$1" ] || printf 'View Page Source' "$1" cat < EOF } gettitle() { sed 1q "$1" | grep -q '^Title:' || { basename "$1" .md return 0 } sed 1q "$1" | cut -d' ' -f2- } genpages() { # Create directories in docs find src -type d | while read -r dir ; do mkdir -p "docs${dir#src}" ; done # Generate html and txt files for page in $(cd src || return 1 ; find . -name '*.md') ; do tohtml "src/$page" > "docs/${page%.md}.html" cp "src/$page" "docs/${page%.md}.txt" sed -i '/^Title:/d' "docs/${page%.md}.txt" done # Copy rest of the files (cd src || return 1 ; find . -type f ! -name '*.md' -exec cp -u \{\} ../docs/\{\} \; ) } tohtml() { header "$(gettitle "$1")" sed '/Title:/d' "$1" | markdown footer "$(echo "$1" | sed 's/.md$/.txt/;s/src\/.//')" } wiki_index() { sed -i '/^Content/,$d' src/wiki/index.md printf 'Content\n-------\n\n' >> src/wiki/index.md for page in $(find src/wiki -type f | grep -v 'src/wiki/index.md' | sort) ; do printf '* [%s](%s)\n' "$(gettitle "$page")" "$(printf "$page" | sed 's#src/wiki/##;s/.md/.html/')" >> src/wiki/index.md done } blog_index() { cat < src/blog/index.md Blog Index ========== This is the Carbs Linux Blog Index. You can find every post here. [RSS Feed] [RSS Feed]: /rss.xml EOF find src/blog -type f ! -name index.md | sort -r | while read -r post ; do postdate="${post##*/}"; postdate="${postdate%%.*}" printf '* %s - [%s](%s)\n' "$(date --date="$postdate" +%b\ %d\ %Y)" "$(gettitle "$post")" "$(printf "$post" | sed 's#src/blog/##;s/.md/.html/')" >> src/blog/index.md done } site_index() { cp index/index.md src/index.md find index -name '*.news' | sort -r | while read -r news ; do newsdate="${news##*/}" ; newsdate="${newsdate%.news}" printf '\n### %s\n\n' "$(date --date="$newsdate" +%b\ %d\ %Y)" >> src/index.md cat "$news" >> src/index.md done } genrss() { cat < Carbs Linux a simple busybox linux distribution https://carbslinux.org $(date -u +%b\ %a\ %Y\ %H):00 EOF find "$1" -type f ! -name index.md | sort -r | while read -r post ; do postdate="${post##*/}" ; postdate="${postdate%.*}" cat < $(gettitle "$post") $(date --date="$postdate" +%a,\ %d\ %b\ %Y) Cem Keylan https://carbslinux.org/${3:-blog/$(printf "${post##*/}" | sed 's/.md/.html/')} $(grep -v '^Title:' "$post" | markdown -f cdata) EOF done cat < EOF } main() { # Create docs directory if it doesn't exist mkdir -p docs # Remove all html, txt, and rss files find docs \( -name '*.html' -o -name '*.txt' -o -name '*.xml' \) -delete # Generate the indexes for blog and the wiki site_index; wiki_index; blog_index # Generate rss feeds genrss index news index.html > docs/news.xml ; genrss src/blog > docs/rss.xml # Generate pages genpages } main "$@"