merge

Mirrored from GitHub

git clone https://github.com/christc4/merge.git

Jump to: README.md app.rc default-app.rc


README.md

1# merge
2
3credit goes to <https://github.com/dagle/merge>, I merely added a bit

app.rc

1fn conf_enable_merged {
2	enable_merge=yes
3	conf_enable_app merge
4}
5
6fn merge_init {
7	if(! ~ $#enable_merge 0 && ~ $local_path */index) {
8		handler_body_main=(merging $req_path)
9	}
10}
11
12fn merging {
13	d=`{basename -d $1}
14	if(~ $#d 0)
15		d='/'
16#	echo $d|sed 's,.*//,,g; s,/$,,; s,/,,g; s/[\-_]/ /g; s,.*,<h1 class="merge">&</h1>,'
17	idx=$sitedir$d^'/index.md'
18	files=`{ls -F $dir_listing_ls_opts $sitedir$d/. | sed $dirfilter$dirclean | uniq}
19	if(test -f $idx) {
20		cat $idx | $formatter
21		echo '<p>Jump to:'
22	for(f in $files) {
23		fi=$f.md
24		if(test -f $fi) {
25			echo $f | awk '{match($0, "/[^/]*/?$"); l=substr($0, RSTART+1, RLENGTH-1);n=l; gsub(/[\-_]/, " ", n); print "<a href=\"#"l"\">"n"</a>"; }'
26		}
27	}
28	}
29	# Symlinks suck: '/.' forces ls to list the linked dir if $d is a symlink.
30	for(f in $files) {
31		fi=$f.md
32		if(test -f $fi) {
33			echo $f | awk '{match($0, "/[^/]*/?$"); l=substr($0, RSTART+1, RLENGTH-1);n=l; gsub(/[\-_]/, " ", n); print "<h2 id=\""l"\"><a href=\""l"\">"n"</a></h2>"; }'
34			cat $fi | $formatter
35		}
36	}
37}

default-app.rc

1
2fn conf_enable_merged {
3	enable_merge=yes
4	conf_enable_app merge
5}
6
7fn merge_init {
8	if(! ~ $#enable_merge 0 && ~ $local_path */index) {
9		handler_body_main=(merging $req_path)
10	}
11}
12
13fn merging {
14	d=`{basename -d $1}
15	if(~ $#d 0)
16		d='/'
17#	echo $d|sed 's,.*//,,g; s,/$,,; s,/,,g; s/[\-_]/ /g; s,.*,<h1 class="merge">&</h1>,'
18	idx=$sitedir$d^'/index.md'
19	files=`{ls -F $dir_listing_ls_opts $sitedir$d/. | sed $dirfilter$dirclean | uniq}
20	if(test -f $idx) {
21		cat $idx | $formatter
22	}
23	# Symlinks suck: '/.' forces ls to list the linked dir if $d is a symlink.
24	for(f in $files) {
25		fi=$f.md
26		if(test -f $fi) {
27			echo $f | awk '{match($0, "/[^/]*/?$"); l=substr($0, RSTART+1, RLENGTH-1);n=l; gsub(/[\-_]/, " ", n); print "<h2 id=\""l"\"><a href=\""l"\">"n"</a></h2>"; }'
28			cat $fi | $formatter
29		}
30	}
31}