commit 9a36a15a8aaa8d5abcba911e0a828ed2c2f1cc64
parent 5d6dcf206f74e29779f945dce0b6de7be5a4725f
Author: Matsuda Kenji <contact2655@matsudakenji.xyz>
Date: Fri, 29 Jul 2022 13:39:51 +0900
clean up
Diffstat:
M | bin/kagero | | | 45 | +++++++++++++++++++-------------------------- |
1 file changed, 19 insertions(+), 26 deletions(-)
diff --git a/bin/kagero b/bin/kagero
@@ -1,4 +1,4 @@
-#!/bin/sh -ex
+#!/bin/sh -e
#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,8 +10,10 @@ data=$(pwd)/data
weblog=$data/weblog
header="$temp/header.html"
footer="$temp/footer.html"
+title="No Title"
+rss_description="RSS"
rss="$pub/rss.xml"
-
+url="https://www.example.com"
. $data/conf
ignore=$(printf ' ! -name "." ! -path "*/.*" ')
@@ -21,44 +23,34 @@ should_exist_dir() { [ ! -d "$1" ] && error "$1 should exist and be a directory"
should_not_exist() { [ -e "$1" ] && error "$1 should not exist"; }
usage(){
- echo 'usage: '$(basename "$0")' [init|render]'
+ echo 'usage: '${0##*/}' [init|render]'
echo ' init: initialize current directory for static site'
echo ' render: render static pages'
}
-list_dirs(){
- cd "$man" && eval "find . -type d $ignore"
-}
-
-list_dependent_files(){
- e="\\( -name '*.html' -o -name '*.css' -o -name '*.js' \\)"
- cd "$man" && eval "find . -type f $ignore $e"
-}
-
list_files_to_replace(){
new_temp=$(cd "$temp" && eval "find . -type f ! -name '.' $ignore -newer $weblog")
if [ "$new_temp" ]; then
- list_dependent_files
+ (cd "$man" && eval "find . -type f -name '*.html' $ignore"
+ eval "find . -type f ! -name '*.html' $ignore -newer $weblog")
else
- (cd "$man" && eval "find . -type f ! -name '.' $ignore -newer $weblog")
+ (cd "$man" && eval "find . -type f $ignore -newer $weblog")
fi
}
render_html(){
- title=$(grep '<h1>' "$man/$1" | sed -E 's/<\/?h1>//g' | sed 's;/;\\/;g')
+ title=$(grep '<h1>' "$man/$1" | sed 's;^.*<h1>\(.*\)</h1>.*$;\1;' | sed 's;/;\\/;g')
cat "$header" "$man/$1" "$footer" |
sed 's/<!--title-->/'"$title"'/'
}
render_sitemap(){
- e=$(printf ' -name "*.html" ! -name "." ! -path "./error/*" ! -path "./draft/*"')
echo '<?xml version="1.0" encoding="UTF-8"?>'
echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'
- (cd "$man" && eval "find . -type f $e $ignore" |
- ls_files_with_date ) |
+ cat |
awk '{print strftime("%Y-%m-%d", $1), $2}' |
sort -hr |
- sed 's! \./! /!;s!/index.html!/!' |
+ sed 's! \./! /!;s!/index.html!/!' |
sed -E 's;(^....-..-..?) (.*$);<url><loc>'"$url"'\2</loc><lastmod>\1</lastmod></url>;'
echo '</urlset>'
}
@@ -99,12 +91,12 @@ render_weblog(){
if [ -f "$weblog" ]; then
(cd "$man" && eval "find . -type f $e $ignore -newer $weblog" |
ls_files_with_date ) |
- sort -h |
+ sort -h |
sed 's! \./! /!' >> "$weblog"
else
(cd "$man" && eval "find . -type f $e $ignore" |
ls_files_with_date ) |
- sort -h |
+ sort -h |
sed 's! \./! /!' > "$weblog"
fi
}
@@ -135,7 +127,7 @@ init)
exit 1;
;;
render)
- list_dirs | (cd "$man" && cpio -pdu "$pub")
+ (cd "$man" && eval "find . -type d $ignore" | cpio -pdu "$pub")
fs=$(
if [ -f "$weblog" ]; then
list_files_to_replace
@@ -145,7 +137,7 @@ render)
)
if [ -n "$fs" ]; then
echo "$fs" | grep '\.html$' |
- while read f; do
+ while read f; do #bottle neck
render_html "$f" > "$pub/$f"
touch -r "$man/$f" "$pub/$f"
done
@@ -158,10 +150,11 @@ render)
sed 's;^.*$;\(cd '$pub' \&\& find . & -delete\);' |
sh -s
- render_sitemap > "$pub/sitemap.xml"
- render_weblog #>> "$weblog" # this redirect doesn't work
+ render_weblog #>> "$weblog" # this redirect doesn't work for some reason
+ sort -k2 -r "$weblog" | uniq -f1 | sort -k1 -r |
+ render_sitemap > "$pub/sitemap.xml"
sort -k2 -r "$weblog" | uniq -f1 | sort -k1 -r | grep -v index.html |
- render_rss > "$rss"
+ render_rss > "$rss" #bottle neck
;;
*)
usage >&2