Fossil: learning TH1
2021-Aug-20
Having wrapped some of my brain around the various features and differences between wiki pages and tech docs I'm ready to start exploring how I might leverage TH1 scripts to extend fossil-as-cms to cover my use case (porting my website of static html files to fossil rendering of markdown files).
I've been looking through the docs and fossil code for *.th1 and sending interesting looking fragments through the /admin_th1 page. Very little of what I've tried so far works though so it's not proving to be a fruitful learning path.
What are some existing scripts that work out of the box that I can look at and study and learn from?
If it helps, here's a pseudo code description of my initial goal:
for *.md recursive:
get first "#" to end of line as Title
get next nn characters as Intro
append [Title, Intro] to Entries
with "index.md" open for writing:
for Entries:
write "[Title][path/to/my_page.md]"
write "_Intro ..._"
save and close
render index.md
Learnings
/admin_th1
Only the last command entered has a visible result. Same commands, different order:
Within the skin files, the <th1> … </th1> block can be run within the admin_th1 page
A simple loop:
set values {one two three four five}
html "<h2>List items in 'values'</h2><ol>"
foreach x $values {html "<li>$x</li>"}
html "</ol>"
puts “”
Values list
one
two
three
four
five
Ok, so how to populate a list from the output from another command?
info vars
gives us the names of all current variables.
puts
, render
, or html $varname
will give us the value of a variable.
info vars
name nonce home index_page project_name expr values login compiler_name manifest_version x default_csp release_version stylesheet_url url current_page project_description csrf_token current_feature baseurl background_image_url logo_image_url tcl_platform manifest_date secureurl class mainmenu
html “This is 'current_page' value: $current_page”
This is 'current_page' value: admin_th1
----
Of use, however:
fossil test-th-render
fossil test-th-eval
fossil test-th-source (that the real difference is between this and test-th-render, i'm not sure)
The difference between render and eval is that the latter expects its input to be only th1 code, whereas the former expects it to be a text file with th1 code wrapped in <th1>...</th1> blocks.
Be sure to see fossil help test-th-... for details.
From < https://fossil-scm.org/forum/forumpost/4dcf49910a>
---
The web interface, for example, typically only uses the repository database.
From < https://fossil-scm.org/home/doc/trunk/www/tech_overview.wiki>
The checkout database records information such as the following:
The name of the repository database file.
The version that is currently checked out.
From < https://fossil-scm.org/home/doc/trunk/www/tech_overview.wiki>
how do we get the hash ID of the version checked out?
Associated with every check-in is a special file called the "manifest". The manifest is a listing of all other files in that source tree. The manifest contains the (complete) artifact ID of the file and the name of the file as it appears on disk, and thus serves as a mapping from artifact ID to disk name.
From < https://fossil-scm.org/home/doc/trunk/www/concepts.wiki>
the fossil setting manifest on
command will cause the manifest file to be materialized to disk,
From < https://fossil-scm.org/home/doc/trunk/www/concepts.wiki>
--------
YES! Thanks to patient guidiance from Stephan Beale here a th1 script that fetches and displays (to console) the first few characters from a markdown file from the latest commit to trunk.
puts "\n=======================================\n"
puts "Reinitializing TH1 interpreter [reinitialize]\n"
# open the repo
puts "[repository 1]\n"
# get the highest reference id associated with 'trunk' tag (latest commit)
query {SELECT rid,value FROM tagxref where rid=(select max(rid) from tagxref) AND value like ('trunk');} {puts "$value, $rid\n"}
# get the blob uuid associated with that ref-id
# (The same hash as would be reported from `fossil info trunk`)
query {SELECT rid,uuid,content FROM blob WHERE rid=$rid} {puts "$rid, $uuid, $content\n"}
# from that uuid get content of a fil
catch "artifact $uuid blog/index.md" article
puts "\n---------------------------------------\n"
puts [string range "$article" 0 100]...
puts "\n---------------------------------------\n"
puts "\n=======================================\n"
puts ""
Output:
=======================================
Reinitializing TH1 interpreter
D:/Matt/www/maphew.com-fossil/maphew.com.fossil
trunk, 432
432, 9f6d0f581b494a1101f8eb473551f847eecaeada64545ef7ea134af17ab37dd6,
---------------------------------------
# Sitemap
- [Home](index.md)
- [About Maphew](About_Maphew.md)
- Batch files:
...
---------------------------------------
=======================================
From < https://fossil-scm.org/forum/forumpost/5f5765e984>
fossil test-th-render
fossil test-th-eval
fossil test-th-source (that the real difference is between this and test-th-render, i'm not sure)
The difference between render and eval is that the latter expects its input to be only th1 code, whereas the former expects it to be a text file with th1 code wrapped in <th1>...</th1> blocks.
Be sure to see fossil help test-th-... for details.
with "index.md" open for writing: