Plugins
A plugin is a Tcl file of a site. It changes the build of that site: the list of pages, the Markdown and the HTML of a page, its code blocks and links, and the files of the output. The key plugins of the site file names the plugin files, relative to the folder of the site file. The build runs the hooks of the plugins in the order of that list.
The sandbox
Each plugin runs in a safe child interpreter of its own. It has no command of a capability: no file, no open, no exec, no socket, and no clock. It has ztcl::markdown and ztcl::json. With the word file in the key allow of the site file, it also has these commands:
| Command | What it does |
|---|---|
fm::read PATH |
Gives the text of a file of the source folder. |
fm::files DIR |
Gives each file below the folder DIR of the source folder, sorted. |
fm::kind PATH |
Gives file, dir, or an empty string. |
A path is relative to the source folder (-root, or the folder of the site file). A path with .. that leaves the source folder is an error.
Flight Manual needs the capability interp of ztcl for the child interpreters.
The hooks
A plugin defines a proc for each hook that it uses. A hook that a plugin does not define is skipped. PAGE is the dict of a page: src, page, group, and label. An error of a hook stops the build, and the message names the plugin and the hook.
| Hook | Gives |
|---|---|
pages LIST |
The list of pages. Each plugin gets the list of the plugin before it. |
source PAGE TEXT |
The Markdown of the page, before the build reads it. |
fence PAGE INFO TEXT |
The HTML of a fenced code block, or an empty string for the next plugin and then the highlight of the build. |
link PAGE HREF |
The URL to write for a link, or an empty string for the next plugin and then the rules of the build. |
html PAGE BODY |
The HTML of the page, after the build reads it. |
head PAGE |
More lines for the <head> of the page. |
files |
More files of the output: a list of paths and their text. The build calls it after pages, so a page can link to these files. |
A page of the list of pages is a dict with the keys src, page, group, and label. A plugin can add a page with its HTML and no Markdown file: src is empty, and these keys give the page:
| Key | Value |
|---|---|
body |
The HTML of the page, for the slot {{content}}. |
title |
The title. The default is the text of the first <h1> of body. |
description |
The meta description, as text. |
head |
More lines for the <head>. |
menu |
0 keeps the page out of the menu and out of the links to the previous and the next page. |
open |
1 with menu 0: the menu of the page opens the group of the page, as for a page of the group. |
within |
A page path, such as toys/pond/. The menu shows the page only on the pages below this path, such as the steps of one tutorial. The links to the previous and the next page stay. |
kind |
The group of the page in the results of the search. The default is the group of the menu before its /. |
entry |
The kind of the entry of the page in the index of the search, such as tutorial. The default is command for a page with usage, and guide for another page (Search). |
usage |
The usage line of a command, such as lsort ?-option ...? list. A page with usage is a command: its title is the name of the command, and the panel of the search shows the usage line. |
class |
The class of the <body> of the page. A page of a Markdown file can have it too: the hook pages sets it in the dict of the page. |
The build does not check the links of the HTML of a plugin. tools/compare-sites.tcl checks each link of a built site.
Example
# Each page gets a line at the end, and a block `note` is an aside.
proc html {page body} {
return "$body<p>Page [dict get $page page]</p>\n"
}
proc fence {page info text} {
if {[lindex $info 0] ne "note"} { return "" }
return "<aside>[string map {& & < < > >} $text]</aside>\n"
}
sites/ztcl/ztcl.tcl is the plugin of the ztcl docs site.
The examples of the hooks
| Hook | Example |
|---|---|
pages |
examples/api/api.tcl: a page for each function of a JSON file |
source, fence, link, html, head, files |
examples/plugin/plugins/extra.tcl |
CI builds both examples with -strict and compares the output.
Next: The checks.