fusch.online

git / lists / casts

git.fusch.online/planner

Generate static pages from a list of links
git clone git://git.fusch.online/planner
Log / Files / Readme / Issues

commit 9f64f8bff37fca4737f6c3cd2f2708a7adfe041f
parent 0b517a12ea33ecaa157e7a20275b65f88cb84ccb
Author: hbkk <tschugg@posteo.de>
Date:   Sun, 31 Mar 2019 23:32:55 +0200

tag pages

Diffstat:
Mlinks.sh | 150+++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------
1 file changed, 100 insertions(+), 50 deletions(-)

diff --git a/links.sh b/links.sh @@ -6,27 +6,18 @@ dateformat="+%a, %d %b %Y %H:%M:%S %z" builddate=$(date "$dateformat") -# main -[[ $1 == -n ]] && { - offline=true - shift -} - -mkdir -p ./site -touch ./db.csv -touch ./links.txt - -cat <<EOF > ./site/index.html +print_html_head() { + cat <<EOF <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> - <title>planner#home</title> + <title>planner#$1</title> <style> body { width: 50em; margin: 0 auto; - margin-top: 4em; + margin-top: 6em; margin-bottom: 4em; font-family: Tahoma, Verdana, Arial, sans-serif; font-size: 7pt; @@ -108,10 +99,29 @@ cat <<EOF > ./site/index.html </style> </head> <body> - <div class="header"><h1>planner</h1></div> + <div class="header"> + <a href="file:///home/hbkk/tmp/site/index.html"> + <h1>planner</h1> + </a> + <p>#${1:-tutti}<p> + </div> EOF +} -cat << EOF > ./site/rss +print_html_tail() { + cat << EOF + <div class="footer"> + <a class="read new" href="file:///home/hbkk/tmp/site/rss">rss</a> + <a class="read new" href="https://tutti.town">tutti.town</a> + <a class="read new" href="https://kuku.tutti.town">kuku</a> + </div> + </body> +</html> +EOF +} + +print_rss_head() { + cat << EOF <?xml version="1.0" encoding="UTF-8" ?> <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" @@ -126,6 +136,61 @@ cat << EOF > ./site/rss <pubDate>$builddate</pubDate> <atom:link href="file:///home/hbkk/tmp/site/rss" rel="self" type="application/rss+xml" /> EOF +} + +print_rss_tail() { + cat << EOF + </channel> + </rss> +EOF +} + + +print_rss_link() { + pubdate=$(date --date="$3" "$dateformat") + + cat << EOF + <item> + <title>$1</title> + <description>![CDATA[$2]]</description> + <link>$2</link> + <guid>$2</guid> + <dc:creator>tutti</dc:creator> + <pubDate>$pubdate</pubDate> + </item> +EOF +} + +print_link_head() { + cat << EOF + <div class="entry"> + <h2><a class="$class" href="$2">$1</a></h2> + <a class="link" href="$2">$2</a> +EOF +} + +print_link_tail() { + printf " </div>\n" +} + +print_link_tag() { + printf " <a class=\"tag\" href=\"%s\">%s</a>\n" "./$1.html" "$1" +} + + +# main +mkdir -p ./site +touch ./db.csv +touch ./links.txt +rm ./site/*.html ./site/rss + +[[ $1 == -n ]] && { + offline=true + shift +} + +print_html_head "" > ./site/index.html +print_rss_head > ./site/rss while read -r line; do date=$(cut -d, -f1 <<< "$line") @@ -169,49 +234,34 @@ while read -r line; do class="new $class" } - cat << EOF >> ./site/index.html - <div class="entry"> - <h2><a class="$class" href="$link">$title</a></h2> - <a class="link" href="$link">$link</a> -EOF + print_link_head "$title" "$link" >> ./site/index.html for tag in $tags; do [[ $tag == read ]] && continue - printf " <a class=\"tag\" href=\"%s\">%s</a>\n" \ - "./$tag.html" "$tag" >> ./site/index.html - done - - printf " </div>\n" >> ./site/index.html + print_link_tag "$tag" >> ./site/index.html - pubdate=$(date --date="$date" "$dateformat") + print_link_head "$title" "$link" >> ./site/"${tag}_build.html" + print_link_tag "$tag" >> ./site/"${tag}_build.html" + print_link_tail >> ./site/"${tag}_build.html" + done - cat << EOF >> ./site/rss - <item> - <title>$title</title> - <description>![CDATA[$link]]</description> - <link>$link</link> - <guid>$link</guid> - <dc:creator>tutti</dc:creator> - <pubDate>$pubdate</pubDate> - </item> -EOF + print_link_tail >> ./site/index.html + print_rss_link "$title" "$link" "$date" >> ./site/rss done < "${1:-./links.txt}" -cat << EOF >> ./site/index.html - <div class="footer"> - <a class="read new" href="file:///home/hbkk/tmp/site/rss">rss</a> - <a class="read new" href="https://tutti.town">tutti.town</a> - <a class="read new" href="https://kuku.tutti.town">kuku</a> - </div> - </body> -</html> -EOF - -cat << EOF >> ./site/rss -</channel> -</rss> -EOF +print_html_tail >> ./site/index.html +print_rss_tail >> ./site/rss mv "$tmp" ./db.csv + +for file in ./site/*; do + [[ $file != *_build.html ]] && continue + tag="$(sed -e 's_\./site/__' -e 's/_build.html//' <<< "$file")" + print_html_head "$tag" > ./site/"$tag.html" + cat "$file" >> ./site/"$tag.html" + print_html_tail >> ./site/"$tag.html" +done + +rm ./site/*_build.html