commit 40b6f99e742a52d6f3dbade9cff99e5cb9c52d27 parent 9ed098263ead592c9e8c50b6f7030e041c76d868 Author: Matsuda Kenji <contact2655@matsudakenji.xyz> Date: Mon, 13 Dec 2021 19:30:11 +0900 change update script Diffstat:
D | bin/ssg | | | 41 | ----------------------------------------- |
M | bin/update | | | 48 | ++++++++++++++++++++++++++++++++++++++++++------ |
2 files changed, 42 insertions(+), 47 deletions(-)
diff --git a/bin/ssg b/bin/ssg @@ -1,41 +0,0 @@ -#!/bin/sh -e - -cd $(dirname $0)/.. -man=$(pwd)/man -pub=$(pwd)/pub - -list_dirs(){ - cd "$1" && eval "find . -type d ! -name '.' ! -path '*/_*'" -} - -list_dependent_files(){ - e="\\( -name '*.html' -o -name '*.css' -o -name '*.js' \\)" - cd "$1" && eval "find . -type f ! -name '.' ! -path '*/_*' $e" -} - -list_files_to_replace(){ - fs=$(cd "$1" && eval "find . -type f ! -name '.' -newer $2") - if echo "$fs" | grep -qE '^./_.*\.html$|^./_.*\.js$|^./_.*\.css$'; then - list_dependent_files "$1" - else - echo "$fs" - fi -} - -list_dirs "$man" | (cd "$man" && cpio -pdu "$pub") -fs=$( - if [ -f "$pub/.files" ]; then - list_files_to_replace "$man" "$pub"/.files - else - cd "$man" && find . -type f ! -name '.' ! -path '*/_*' - fi -) -if [ -n "$fs" ]; then - echo "$fs" | tee "$pub/.files" - echo "$fs" | grep '\.html$' | - while read f; do - cat "$man"/_header.html "$man"/$f $man/_footer.html > "$pub/$f" - done - echo "$fs" | grep -Ev '\.html$' | - (cd "$man" && cpio -pu "$pub") -fi diff --git a/bin/update b/bin/update @@ -1,9 +1,45 @@ -#!/bin/sh +#!/bin/sh -e + cd $(dirname $0)/.. +man=$(pwd)/man +pub=$(pwd)/pub + +list_dirs(){ + cd "$1" && eval "find . -type d ! -name '.' ! -path '*/_*'" +} + +list_dependent_files(){ + e="\\( -name '*.html' -o -name '*.css' -o -name '*.js' \\)" + cd "$1" && eval "find . -type f ! -name '.' ! -path '*/_*' $e" +} + +list_files_to_replace(){ + fs=$(cd "$1" && eval "find . -type f ! -name '.' -newer $2") + if echo "$fs" | grep -qE '^./_.*\.html$|^./_.*\.js$|^./_.*\.css$'; then + list_dependent_files "$1" + else + echo "$fs" + fi +} -# apply template to html files -find man -type f | grep html$ | sed 's;^man/;;' | - xargs -I% sh -c 'sed -n "/<\!--content-->/!p; /<\!--content-->/r man/%" templates/base.html > pub/%' +list_dirs "$man" | (cd "$man" && cpio -pdu "$pub") +fs=$( + if [ -f "$pub/.files" ]; then + list_files_to_replace "$man" "$pub"/.files + else + cd "$man" && find . -type f ! -name '.' ! -path '*/_*' + fi +) +if [ -n "$fs" ]; then + echo "$fs" | tee "$pub/.files" + echo "$fs" | grep '\.html$' | + while read f; do + cat "$man"/_header.html "$man"/$f $man/_footer.html > "$pub/$f" + done + echo "$fs" | grep -Ev '\.html$' | + (cd "$man" && cpio -pu "$pub") +fi -# copy non-html files -find man -type f ! -name *.swp | grep -v html$ | sed 's;^man/;;' | xargs -I% cp man/% pub/% +(cd $man && find .) | sed 's/^.*$/\! -path "&"/' | tr '\n' ' ' | + sed 's;^.*$;\(cd '$pub' \&\& find . \! -path ./.files & -delete\);' | + sh -s