[pmwiki-users] wiki page creation

Peter & Melodye Bowers pbowers at pobox.com
Sat Mar 22 10:33:00 CDT 2008


> Is there an easy way to automatically create a bunch of
> wiki pages from a text file, which consists of a list of sections,
> and each section shall become a new wiki page?
> 
> The sections are mainly of plain text with some wiki markup,
> the beginning of each section is determined by some text marker
> string, the end of each section by the beginning of the next.
> The wiki page name needs to be determined by a string in each section.

This is exactly the kind of thing WikiSh can do very nicely...

Here is roughly the script I would put into the (:wikish_controlpanel:)
window (no need to put it on another page since presumably it is a once-off
activity...) (I am assuming a textfile called foo.txt in your "pmwiki root"
directory and "===Group.Pagename===" as the section delimiter - you would
need to modify the 2 regexes to fit your actual pattern):

===(snip)===
set -s outfile = NotAPage
cat TEXTFILE--foo.txt | while read line
do
   if test "${line}" ~= "/^===.*===$/"
   then
      set -s outfile = `echo ${line} | sed 's/^===(.*)===$/$1/'`
      echo "Outputting to ${outfile}"
      if test -f ${outfile}
      then
         rm ${outfile}
      fi
   else
      echo ${line} >>${outfile}
   fi
done
===(snip)===

Note that if you are dealing with thousands of lines of text this is not
going to be the most efficient processor.  For each line it's going to have
to re-read and re-write the outfile since there's no optimization that I
know of to simply append a line of text to a page.  But if you're OK with a
slight delay this should do the trick...

(You could get fancier and save up the lines in a variable and write out to
the page only once, but that is more complicated and something you'd
probably only want to do if you were dealing with significant performance
issues...)

-Peter




More information about the pmwiki-users mailing list