#!/bin/bash USAGE="koala-webtree data-path web [topic [depth]] can be run anywhere. Arguments: data-path is the data directory of your TWiki installation web is the web to dump the tree of topic is the root topic. defaults to WebHome. depth is the max depth printed. defaults to 1000 " # we use fast greps (egrep + -m & --mmap options) # the goal is to build a directory $tmp of files, each files having the # name of a parent topic and containing one son per line, sorted # Each level is indented by INDENT_STRING # Each node is printed via the NODE_TEMPLATE, with {} meaning the topic name # note that this $tmp could be stored and reused in a # working/work_areas/FastTreePlugin area, that will be compared to the web # directory and .cache to evaluate its freshness # a C version could be faster as it would have to read only the first 2 # lines of topics tmp=/tmp/webtree.$$ mkdir $tmp if test -n "${PATH_INFO}"; then cd "../data${PATH_INFO%/*}" TOPIC="${PATH_INFO##*/}" WEB="${PATH_INFO%/*}" WEB="${WEB#/}" MAXDEPTH=100000 INDENT_STRING=" " NODE_TEMPLATE="* [[$WEB.{}][{}]]" ROOT_TEMPLATE= echo "Content-Type: text/plain";echo else WEB="${2:-Main}" TOPIC="${3:-WebHome}" MAXDEPTH="${4:-1000}" cd "${1:-../data}"/"$WEB" INDENT_STRING=" " NODE_TEMPLATE="* [[$WEB.{}][{}]]" ROOT_TEMPLATE="$INDENT_STRING$NODE_TEMPLATE" fi ( egrep --exclude=WebHome.txt -L --mmap -m 1 '^%META:TOPICPARENT{name=' *.txt|\ sed -e 's/[.]txt$/ WebHome/'; \ egrep --mmap -m 1 '^%META:TOPICPARENT{name=' *.txt |\ sed -e 's|^[./]*\([^.]*\)[.]txt:%META:TOPICPARENT{name="\([^"]*\).*|\1 \2|' \ ) | sort | while read s p; do echo "$s" >>$tmp/"$p"; done # $1=parent $2=indent_string $3=current_path $4=depth $5=node_template print_sons () { local depth="$4" indent="$2" case "$3" in */"$"1/* ) echo "### LOOP $3/$1"; return ;; esac #loop if test -n "$5"; then echo "$indent${5//{\}/$1}"; fi if let "depth