retroforth/example/publish-examples.forth
crc e286415d2b add publish-examples.forth
FossilOrigin-Name: c8b4c66ad9d0fbf8a126c12a6066b70e173299b9b83426d8318d62a0c4de7e74
2019-03-29 13:50:53 +00:00

49 lines
1.1 KiB
Forth
Executable file

#!/usr/bin/env retro
This program generates an HTML index and exports (using the
`export-as-html.forth` example) the samples to HTML. The files
are stored in `/home/crc/public/examples`.
~~~
:unix:count-files (-n)
'ls_-1_|_wc_-l file:R unix:popen
[ file:read-line s:trim s:to-number ] [ unix:pclose ] bi ;
:unix:for-each-file (q-)
'ls_-1_-p file:R unix:popen
unix:count-files-in-cwd
[ [ file:read-line s:temp over call ] sip ] times
unix:pclose drop ;
:dir? (s-sf)
dup s:length over + n:dec fetch $/ eq? ;
~~~
# Generate index.html
~~~
'/home/crc/public/examples/index.html file:W file:open 'FID const
:index:put [ FID file:write ] s:for-each ;
:css
'<style>*{background:#111;color:#fff;font-family:monospace;}</style>
index:put ;
:header '<!DOCTYPE_html> index:put css ;
:link dup '<a_href="/examples/%s.html">%s</a><br> s:format index:put $. c:put ;
header
[ dir? &drop &link choose ] unix:for-each-file nl
FID file:close
~~~
# Generate HTML Files
~~~
:export dup './export-as-html.forth_%s_>/home/crc/public/examples/%s.html
s:format unix:system $. c:put ;
[ dir? &drop [ export ] choose ] unix:for-each-file nl
~~~