[REBOL] Autogenerating TOC
From: sharriff::aina::med-iq::de at: 17-Nov-2000 8:52
Hi guys!
If there was an award for the most clumsy or silly looking code , I would
definately win. I´m trying to code a function that would automatically
generate a TOC of of files in a directory
Main TOC:
A
B
C
D and so on and so forth
and every alphabet is a link to a sublist HTML file that contains links to
files starting with the alphabet displayed in the main TOC HTML file
A --> link to a file, a.html that contains links to files that all start
with a, example ahouse .html. aaa.html, asbc.html e.t.c
B ->link to a file, b.html that contains links to files that all start
with b, example boing .html. badcode.html, blooper.html e.t.c
heres what I´ve done so far
( simplified, I´ve removed the HTML basic and other formatting tags)
; initialize containers
toc-list: temp-block: file-list: sorted-files: file-dir: sub-list: make
block! 0
; initialize link bits
link-begin: {<a href="}
close-link: {">}
end-link: {</a>}
file-dir: read %./
sort file-dir
; creates a block of files as strings
foreach file file-dir [ append file-list (to-string file) ]
; generates first char of every file and saves result to "toc-list"
foreach file file-list [append toc-list first :file sort file-list
; appends the real file
names to "toc-list" block
append toc-list file
; writes the toclist
[ foreach char toc-list [ write (append
sub-list ((join (to-file :toc-list) ".html") (
I gave up eventually. I really don´t know how to link the generated TOC
link list with the separate HTML files containing links to files in the
directory to files sorted per alphabet or number.
Suprisingly, this works. (har! har! "Tim Allen" code)
files: read %./
sort files
foreach file files [ append temp-block (to-string file) ]
foreach file files [write %toc.html file-dir (append file-dir "<p></p>"
append file-dir (join (join (join (join link-begin file) close-link) file)
(end-link)))]
but I dont know how to connect both code snippets together, I know this
code looks weird, If I can get the principles right I´ll try to clean it up
somehow. I hope theres someone out there that can point me in the right
direction.
Best regards and thanks list for the anticipated help
Sharriff Aina
med.iq information & quality in healthcare AG