dotfiles

Dotfiles for my OpenBSD environment.
git clone https://git.mtkn.jp/dotfiles
Log | Files | Refs

commit 5d6dcf206f74e29779f945dce0b6de7be5a4725f
parent d5241dca716cb4ee4f28ba3fd8ce4ec2918b178c
Author: Matsuda Kenji <contact2655@matsudakenji.xyz>
Date:   Fri, 29 Jul 2022 12:25:40 +0900

implement rss

Diffstat:
Mbin/kagero | 63++++++++++++++++++++++++++++++++++++++++++++++++---------------
1 file changed, 48 insertions(+), 15 deletions(-)

diff --git a/bin/kagero b/bin/kagero @@ -1,4 +1,4 @@ -#!/bin/sh -e +#!/bin/sh -ex #TODO: stat(1) is not in POSIX: 7/14 removed stat(1) but not yet tested well. # pathnames should not contain white spaces #BUG: non html files are not copied after changed its directory. @@ -10,7 +10,9 @@ data=$(pwd)/data weblog=$data/weblog header="$temp/header.html" footer="$temp/footer.html" -url="https://www.mtkn.jp" +rss="$pub/rss.xml" + +. $data/conf ignore=$(printf ' ! -name "." ! -path "*/.*" ') @@ -54,8 +56,7 @@ render_sitemap(){ echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' (cd "$man" && eval "find . -type f $e $ignore" | ls_files_with_date ) | - # I coded this line at night - #-exec stat -f '%Sm %N' -t '%Y-%m-%d' {} + ") | + awk '{print strftime("%Y-%m-%d", $1), $2}' | sort -hr | sed 's! \./! /!;s!/index.html!/!' | sed -E 's;(^....-..-..?) (.*$);<url><loc>'"$url"'\2</loc><lastmod>\1</lastmod></url>;' @@ -63,13 +64,40 @@ render_sitemap(){ } render_rss(){ - echo "render_rss: not implemented" >&2 + build_date=$(date '+%a, %e %b %Y %H:%M:%S %z') + echo '<?xml version="1.0" encoding="UTF-8"?>' + echo '<rss version="2.0">' + echo '<channel>' + echo '<title>'"$title"'</title>' + echo '<description>'"$rss_description"'</description>' + echo '<language>ja-jp</language>' + echo '<link>'"$url"'</link>' + echo '<lastBuildDate>'"$build_date"'</lastBuildDate>' + echo '<pubDate>'"$build_date"'</pubDate>' + echo '<docs>https://www.rssboard.org/rss-specification</docs>' + + cat | + while read date file; do + atitle=$(grep '<h1>' $man$file | sed 's;<h1>\(.*\)</h1>;\1;') + date=$(echo $date | awk '{print strftime("%a, %e %b %Y %H:%M:%S %z", $1)}') + echo '<item>' + echo '<title>'"$atitle"'</title>' + echo '<link>'"$url$file"'</link>' + echo '<guid>'"$url$file"'</guid>' + echo '<pubDate>'"$date"'</pubDate>' + printf '<description><![CDATA[' + cat "$man$file" + echo ']]></description>' + echo '</item>' + done + echo '</channel>' + echo '</rss>' } render_weblog(){ e=$(printf ' -name "*.html" ! -name "." ! -path "./error/*" ! -path "./draft/*"') if [ -f "$weblog" ]; then - (cd "$man" && eval "find . -type f $e $ignore -newer $weblog" | + (cd "$man" && eval "find . -type f $e $ignore -newer $weblog" | ls_files_with_date ) | sort -h | sed 's! \./! /!' >> "$weblog" @@ -77,18 +105,22 @@ render_weblog(){ (cd "$man" && eval "find . -type f $e $ignore" | ls_files_with_date ) | sort -h | - sed 's! \./! /!' >> "$weblog" + sed 's! \./! /!' > "$weblog" fi } ls_files_with_date(){ Y=$(date "+%Y") - ls -l $(cat) | - awk '{print $8, $6, $7, $9}' | - awk -v Y=$Y '$1!~/:/{print}$1~/:/{$1=Y; print}' | - sed 's/Jan/01/; s/Feb/02/; s/Mar/03/; s/Apr/04/; s/May/05/; s/Jun/06/; - s/Jul/07/; s/Aug/08/; s/Sep/09/; s/Oct/10/; s/Nov/11/; s/Dec/12/' | - awk '{printf "%s-%02s-%02s %s\n", $1, $2, $3, $4}' + fs=$(cat | tr '\n' ' ') + if [ -n "$fs" ]; then + eval "ls -l $fs" | + awk '{print $8, $6, $7, $9}' | + awk -v Y=$Y '$1!~/:/{print}$1~/:/{$1=Y; print}' | + sed 's/Jan/01/; s/Feb/02/; s/Mar/03/; s/Apr/04/; s/May/05/; s/Jun/06/; + s/Jul/07/; s/Aug/08/; s/Sep/09/; s/Oct/10/; s/Nov/11/; s/Dec/12/' | + awk '{printf "%s %02s %02s 00 00 00 %s\n", $1, $2, $3, $4}' | + awk '{print mktime($1" "$2" "$3" "$4" "$5" "$6), $7}' + fi } # main @@ -127,8 +159,9 @@ render) sh -s render_sitemap > "$pub/sitemap.xml" - render_rss - render_weblog + render_weblog #>> "$weblog" # this redirect doesn't work + sort -k2 -r "$weblog" | uniq -f1 | sort -k1 -r | grep -v index.html | + render_rss > "$rss" ;; *) usage >&2