Created
September 24, 2014 08:27
-
-
Save ryuichiueda/9b4bbd031d19cbb778ca to your computer and use it in GitHub Desktop.
index.glue for kiyou 2014
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func mkNavi page: | |
grep -B 1 -A 1 "$page" | |
tr '\n' ' ' | |
awk '{print $1,$NF}' | |
tr ' ' '\n' | |
awk 'NR==1{print "前の記事",$1}NR==2{print "後の記事",$1}' | |
grep -v "$page" | |
sed 's/_/\\_/g' | |
proc fixPage dir page: | |
| test "$page" = "" : | |
tail -n 1 | |
| test -d "$dir/pages/$page" : | |
echo $page | |
| othewise : | |
tail -n 1 | |
func diaryList dir: | |
ls -f $dir/pages/ | |
grep -E "^[0-9]{14}_" | |
sort | |
proc mkHeader page list: | |
| grep -Eq "^[0-9]{14}_" <<< "$page" : | |
mkNavi $page < "$list" | |
| othewise : | |
true | |
func getDay page: | |
self -d 1.1.14 "$page" | |
dayslash "yyyy年m月d日H時M分" 1 | |
func getCategory dir page: | |
sed 's/_/\\_/g' "$dir/pages/$page/categories" | |
sed 's/ /_/g' | |
func trackBack page : | |
awk -v p=$page '$2=p' | |
sort -s -k1,1 | |
getlast 1 1 | |
awk '$3=="OK"' | |
func trackBackSub id p ok : | |
nkf --url-input $dir/trackback/$id.$p | |
tr '&' '\n' | |
tr -d '<>"' | |
grep -E '^(url|title|blog_name)=' | |
sed 's/^[^=]*=//' | |
LANG=C sort | |
yarr | |
func outHTTP page navi category trackback upload host : | |
sed 's/^/\t\t\t/' | |
sed "s;\(href\|src\)=\";&/pages/$page/;g" | |
sed "s;\"/pages/$page/\([^:\"]*\)://;\"\1://;g" | |
sed "s;\"/pages/$page//;\"?p=;g" | |
filehame -lDOCUMENT $dir/template.html - | |
mojihame -lNAVI_HEADER - $navi | |
mojihame -lNAVI_FOOTER - $navi | |
mojihame -lCATEGORIES - $category | |
mojihame -lTRACKBACK - $trackback | |
sed "s/@HTTP_HOST/$host/" | |
sed "s/@PAGE/$page/" | |
sed "s/@UPLOAD/$upload/" | |
sed "s/@TITLE/$(self 2 $dir/cache/$page.title)/" | |
func titleCache page: | |
head -n 1 | |
sed -e 's;<h1>;;' -e 's;</h1>;;' | |
sed 's;_;\\_;g' | |
sed 's; ;_;g' | |
awk -v f="$page" '{gsub(/_/,"\\_",f);print f,$0}' | |
proc main: | |
str dir = echo /var/www/bashcms | |
exec 2> $dir/../www-data/$(basename $0).$(date +%Y%m%d%H%M%S).$$ | |
str raw_page = tr -dc 'a-zA-Z0-9_' <<< "${QUERY_STRING:2}" | |
file diarylist = diaryList $dir | |
str pagename = fixPage $dir $raw_page < $diarylist | |
file navi = mkHeader $pagename $diarylist | |
str day = getDay $pagename | |
file category = getCategory $dir $pagename | |
file ttmp = trackBack "$pagename" < "$dir/trackback/accept" | |
file trackback = foreach trackBackSub < $ttmp | |
str host = echo $HTTP_HOST | |
echo "Content-Type: text/html" | |
echo "" | |
outHTTP $pagename $navi $category $trackback $upload $host < "$dir/pages/$pagename/html" | |
file tcache = titleCache $pagename < "$dir/pages/$pagename/html" | |
mv $tcache "$dir/cache/$pagename.title" | |
echo -n 1 >> "$dir/cache/$pagename.counter" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment