From 979a10c2a68746565f330e871da2a0a112fa1604 Mon Sep 17 00:00:00 2001 From: Cem Keylan Date: Mon, 6 Apr 2020 12:06:20 +0300 Subject: initial commit --- build | 152 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 152 insertions(+) create mode 100755 build (limited to 'build') diff --git a/build b/build new file mode 100755 index 0000000..e78d9fe --- /dev/null +++ b/build @@ -0,0 +1,152 @@ +#!/bin/sh -e +MARKDOWNOPTS="-html5 -squash" +export MARKDOWNOPTS + +header() { + cat < + + +$TITLE | 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() { + TITLE="$(gettitle "$1")" header + 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) +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 "$@" -- cgit v1.2.3