Merge.
This commit is contained in:
commit
fed2cc5c2e
5 changed files with 81 additions and 68 deletions
35
bin/fltr_cache.rc
Executable file
35
bin/fltr_cache.rc
Executable file
|
|
@ -0,0 +1,35 @@
|
||||||
|
#!/usr/bin/env rc
|
||||||
|
|
||||||
|
fn fltr_cache {
|
||||||
|
a=()
|
||||||
|
tmpf=()
|
||||||
|
|
||||||
|
proc=$1
|
||||||
|
shift
|
||||||
|
|
||||||
|
if(~ $#* 0) {
|
||||||
|
tmpf=/tmp/fmttmp.$pid
|
||||||
|
f=$tmpf
|
||||||
|
score=`{{tee $tmpf || exit 1} | sha1sum}
|
||||||
|
}
|
||||||
|
if not {
|
||||||
|
f=$1
|
||||||
|
if(~ $f */) {
|
||||||
|
score=`{du -an $f | sha1sum || exit 1} # XXX using -n(bytes) instead of -t(lastmod) because sitemap proc touches files in tree.
|
||||||
|
a=$f
|
||||||
|
f=/dev/null
|
||||||
|
}
|
||||||
|
if not
|
||||||
|
score=`{sha1sum $f || exit 1}
|
||||||
|
}
|
||||||
|
cachedir=/tmp/fltr_cache/$score
|
||||||
|
mkdir -p $cachedir >[2]/dev/null
|
||||||
|
|
||||||
|
if(test -s $cachedir/$proc)
|
||||||
|
cat $cachedir/$proc
|
||||||
|
if not
|
||||||
|
if($proc $a < $f | tee $cachedir/$pid)
|
||||||
|
mv $cachedir/$pid $cachedir/$proc
|
||||||
|
|
||||||
|
rm $tmpf $cachedir/$pid >[2]/dev/null &
|
||||||
|
}
|
||||||
|
|
@ -1,19 +0,0 @@
|
||||||
#!/usr/bin/env rc
|
|
||||||
#. 9.rc # Not really needed when calling from werc, only would be needed if you use fproc_cache.rc standalone
|
|
||||||
# TODO: Allow to provide two arguments, second arg is a file name, use filename+size+mtime for hashing.
|
|
||||||
# Useful when dealing with many big files (eg., thumb gallery generation).
|
|
||||||
|
|
||||||
proc=$1
|
|
||||||
tmpfile=/tmp/fmttmp.$pid
|
|
||||||
score=`{{tee $tmpfile || exit 1} | sha1sum}
|
|
||||||
|
|
||||||
cachedir=/tmp/fproc_cache/$score
|
|
||||||
mkdir -p $cachedir >[2]/dev/null
|
|
||||||
|
|
||||||
if(test -s $cachedir/$proc)
|
|
||||||
cat $cachedir/$proc
|
|
||||||
if not
|
|
||||||
if($proc < $tmpfile | tee $cachedir/$pid)
|
|
||||||
mv $cachedir/$pid $cachedir/$proc
|
|
||||||
|
|
||||||
rm $tmpfile $cachedir/$pid >[2]/dev/null &
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
. ./werclib.rc
|
. ./werclib.rc
|
||||||
. ./wercconf.rc
|
. ./wercconf.rc
|
||||||
. ./corehandlers.rc
|
. ./corehandlers.rc
|
||||||
|
. ./fltr_cache.rc
|
||||||
cd ..
|
cd ..
|
||||||
|
|
||||||
forbidden_uri_chars='[^a-zA-Z0-9_+\-\/\.]'
|
forbidden_uri_chars='[^a-zA-Z0-9_+\-\/\.]'
|
||||||
|
|
@ -105,7 +106,7 @@ fn werc_exec_request {
|
||||||
if(! ~ $#debug 0)
|
if(! ~ $#debug 0)
|
||||||
dprint $"SERVER_NAME^$"REQUEST_URI - $"HTTP_USER_AGENT - $"REQUEST_METHOD - $"handler_body_main - $"master_template
|
dprint $"SERVER_NAME^$"REQUEST_URI - $"HTTP_USER_AGENT - $"REQUEST_METHOD - $"handler_body_main - $"master_template
|
||||||
|
|
||||||
template $headers $master_template #| awk_buffer
|
template $headers $master_template | awk_buffer
|
||||||
echo $res_tail
|
echo $res_tail
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
12
etc/initrc
12
etc/initrc
|
|
@ -9,17 +9,17 @@
|
||||||
|
|
||||||
# Location of your Plan 9 from User Space installation (usually /usr/local/plan9)
|
# Location of your Plan 9 from User Space installation (usually /usr/local/plan9)
|
||||||
plan9port=$PLAN9
|
plan9port=$PLAN9
|
||||||
|
#plan9port=/usr/local/plan9
|
||||||
|
|
||||||
# Path, make sure the plan9port /bin directory is included before /bin
|
# Path, make sure the plan9port /bin directory is included before /bin
|
||||||
# Keep '.' in path! It is needed.
|
# Keep '.' in path! It is needed.
|
||||||
path=($plan9port/bin/ . ./bin/ ./bin/contrib/ /bin/ /usr/bin/)
|
path=($plan9port/bin/ . ./bin/ ./bin/contrib/ /bin/ /usr/bin/)
|
||||||
|
|
||||||
# Set this to your favorite markdown formatter, eg., markdown.pl (fproc_cache
|
# Set this to your favorite markdown formatter, eg., markdown.pl (fltr_cache
|
||||||
# is a wrapper around a script it takes as an argument, in the default
|
# takes as an argument a filter, in the default configuration markdown.pl, that
|
||||||
# configuration markdown.pl, that caches output)
|
# caches output) Note that some werc components assume a markdown-like
|
||||||
# Note that some werc components assume a markdown-like formatter, but all
|
# formatter, but all major functionality should should be formatter agnostic.
|
||||||
# major functionality should should be formatter agnostic.
|
formatter=(fltr_cache markdown.pl)
|
||||||
formatter=(fproc_cache.rc markdown.pl)
|
|
||||||
|
|
||||||
# Enable debugging, to disable set to ()
|
# Enable debugging, to disable set to ()
|
||||||
debug=true
|
debug=true
|
||||||
|
|
|
||||||
|
|
@ -5,65 +5,61 @@ tmpfile=/tmp/werc_sitemap_$pid.txt
|
||||||
echo '' > $tmpfile
|
echo '' > $tmpfile
|
||||||
saveddf=$dirfilter
|
saveddf=$dirfilter
|
||||||
|
|
||||||
fn getMdDesc {
|
fn get_md_title {
|
||||||
sed 's/^(.......................................................................................................[^ ]*).*$/\1/g; 1q' < $1
|
sed 's/^(................................................................[^ ]*).*$/\1/g; 1q' < $1
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_html_title {
|
||||||
|
# H1 is not reliable because htmlroff doesn't use it :(
|
||||||
|
#desc=`{cat $1 | sed 32q | grep '<[Hh]1>' | sed 's/<[Hh]1>(.*)(<\/[Hh]1>|$)/\1/;s/<[^>]*>//g;1q'}
|
||||||
|
# Pick the first line of body instead
|
||||||
|
desc=`{sed -n '/<[Bb][Oo][Dd][Yy]/,/./s/(<[^>]*>|$)//gp' < $1}
|
||||||
|
if(~ $#desc 0)
|
||||||
|
desc=`{sed 's/<[^>]*>//g; 1q' < $1}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_file_title {
|
||||||
|
|
||||||
|
if(~ $1 */) {
|
||||||
|
if(test -f $1/index.md)
|
||||||
|
get_md_title $1/index.md
|
||||||
|
if not if(test -f $1/index.html)
|
||||||
|
get_html_title $1/index.html
|
||||||
|
}
|
||||||
|
if not if(~ $1 *.md)
|
||||||
|
get_md_title $1
|
||||||
|
if not if(~ $1 *.html)
|
||||||
|
get_html_title $1
|
||||||
|
if not
|
||||||
|
echo ''
|
||||||
}
|
}
|
||||||
|
|
||||||
# XXX Instead of recursion should use du(1) or similar.
|
|
||||||
fn listDir {
|
fn listDir {
|
||||||
d=$1
|
d=$1
|
||||||
if(~ $#d 0)
|
|
||||||
d=''
|
|
||||||
dirfilter=$saveddf
|
dirfilter=$saveddf
|
||||||
blogDirs=()
|
|
||||||
if(test -f $d/_werc/config)
|
if(test -f $d/_werc/config)
|
||||||
. ./$d/_werc/config
|
. ./$d/_werc/config
|
||||||
|
|
||||||
echo '<ul class="sitemap-list">'
|
echo '<ul class="sitemap-list">'
|
||||||
|
|
||||||
# Don't hide blog dirs for now
|
for(i in `{ls -dF $d^*/ $d^*.md $d^*.html $d^*.txt >[2]/dev/null | sed $dirfilter}) {
|
||||||
#if(! ~ $#blogDirs 0 || ~ $1 */blog */Blog)
|
desc=`{get_file_title $i}
|
||||||
# echo ''
|
u=`{echo $i|sed 's!'$sitedir'!!; '$dirclean's!/index$!/!; '}
|
||||||
#if not
|
|
||||||
if(! ~ $#redirectPermanent 1)
|
|
||||||
{
|
|
||||||
|
|
||||||
for(i in `{ls -dF $d^*/ $d^*.md $d^*.html $d^*.txt >[2]/dev/null | sed $dirfilter$dirclean}) {
|
|
||||||
desc=''
|
|
||||||
if(test -f $i.md)
|
|
||||||
desc=`{getMdDesc $i.md}
|
|
||||||
if not if(~ $i */ && test -f $i/index.md)
|
|
||||||
desc=`{getMdDesc $i/index.md}
|
|
||||||
if not if(test -f $i.html) {
|
|
||||||
# H1 is not reliable because htmlroff doesn't use it :(
|
|
||||||
#desc = `{cat $i.html |sed 32q | grep '<[Hh]1>' |sed 's/<[Hh]1>(.*)(<\/[Hh]1>|$)/\1/;s/<[^>]*>//g;1q'}
|
|
||||||
# Pick the first line of body instead
|
|
||||||
desc=`{sed -n '/<[Bb][Oo][Dd][Yy]/,/./s/(<[^>]*>|$)//gp' < $i.html}
|
|
||||||
if(~ $#desc 0)
|
|
||||||
desc=`{sed 's/<[^>]*>//g; 1q' < $i.html}
|
|
||||||
#desc=`{/bin/sed -e '0,/<[Bb][Oo][Dd][Yy]/d;s/<[^>]*>//g;/^$/d' < $i.html >[2]/dev/null | sed 1q}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(! ~ $#desc 0 && ! ~ $desc '')
|
if(! ~ $#desc 0 && ! ~ $desc '')
|
||||||
desc=' - '$"desc
|
desc=' - '$"desc
|
||||||
tit=`{echo /$i|sed 's/_/ /g; s,.*/([^/]+)/?$,\1,'}
|
n=`{echo /$u|sed 's/_/ /g; s,.*/([^/]+)/?$,\1,'}
|
||||||
echo '<li><a href="/'$i'">'^$"tit^'</a>' $"desc '</li>'
|
echo '<li><a href="'$base_url$u'">'^$"n^'</a>' $"desc '</li>'
|
||||||
echo -n $base_url^$i >> $tmpfile
|
echo $base_url^$u >> $tmpfile
|
||||||
if(test -d $i) {
|
if(test -d $i)
|
||||||
echo / >> $tmpfile
|
|
||||||
@{ listDir $i }
|
@{ listDir $i }
|
||||||
}
|
|
||||||
if not
|
|
||||||
echo >> $tmpfile
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
echo '</ul>'
|
echo '</ul>'
|
||||||
}
|
}
|
||||||
|
|
||||||
cd $sitedir
|
fltr_cache listDir $sitedir/
|
||||||
listDir ''
|
#listDir $sitedir/
|
||||||
|
|
||||||
cp $tmpfile ./sitemap.txt
|
if(test -s $tmpfile)
|
||||||
rm $tmpfile
|
mv $tmpfile $sitedir/sitemap.txt &
|
||||||
|
|
||||||
%}
|
%}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue