Trame

site: a project's website

src/site (#import "trame:site", or site :: #import "<toolkit>/src/site") makes the pages of a project's site from its own sources, and checks them in a real browser. The toolkit's site uses it (trame site_build), so do Tower's (ocntools site build) and Wren's documentation (its docsite tool). A project gives its names, address and colours (Meta, Docs), its home page as the template (site/index.html), its CHANGELOG.md and its documents (docs/).

Less text

A program's home page shows; it does not explain. It holds:

  • the name and the short label of the program;
  • one download or install line per system;
  • screenshots, with captions of a few words;
  • if needed, short cards: a title and one line each, for facts that the screenshots do not show.

Do not write stories, scenarios, design rationale or long explanations of features. These go in the README, the documentation or the intent folder.

The changelog's pages

build_changelog(site, out, {changes, version_mark, downloads, meta}) copies the folder site to out, then writes:

  • index.html: the home page, the last 3 versions in place of <!-- whats-new --> (news_html). version_mark (for example {{version}}) is replaced by the last version, so a download link can name the files of that release.
  • changelog/index.html: every version, the last 6 open, with a filter. It wears the home page's head, bar, footer and first script, their links made relative to its folder (from_home). Beside its title, a Subscribe menu (subscribe_html): the releases' feed (feed.xml) and, with Meta.repository, its releases on GitHub; its style is in the page, from the variables every site has (--bg1, --bg2, --bg3, --text, --weak, --edge, --sans, --mono). Its lead names the roadmap when the project has one.
  • roadmap/index.html: the ROADMAP.md beside CHANGELOG.md (Now, Next, Later), in the changelog's dress; an empty section says so. Linked from the changelog's lead, not from the bar.
  • classic/: the same in a classic presentation (classic/, classic/features/, classic/screenshots/, classic/changelog/), a line of plain links and a column of text, with classic/classic.css of the site. Each modern page's footer links its classic page ("Classic version"), each classic page the modern one ("Modern version").
  • with meta.shop, the shop's six pages (licence_pages, below): they are made before build_meta, which gives them their canonical address like every other page.

Every page is a folder and its index.html, and every link names the folder: changelog/, ../, ./, never index.html. The pages' links are written root-absolute, then made relative to each page by the shortest way (relative_links: from classic/, /classic/features/ is features/), so a site served under a path of its own works. GitHub Pages serves a folder both as /x/ and as /x/index.html: the canonical tag of each page (build_meta) makes them one page for search engines. meta.name titles the pages ("Changelog · name"); without it, the home page's title does.

CHANGELOG.md follows Keep a Changelog: ## [x.y.z] - date, ### Added..., [x.y.z]: url at the end. The home page must hold these parts, or the step says which one is missing: <!-- whats-new -->, <a href="classic/">Classic version</a> in its footer, a hero section (its h1, its logo img.mark, its .actions and p.small), figure.shot.wide, section.gallery, a download section, a features section of article.card items, a nav#nav.

The pages were first made by JavaScript and were compared with these byte for byte. The parts that read text say which regular expression they match, with what JavaScript gives its whitespace, ., UTF-16 lengths and $ in a replacement (html.fm).

Every program's site has the same bar and the same footer: the home page holds two marks, and build_changelog puts there what Changelog_Options.meta says (with_frame). A program declares data, not HTML.

  • <!-- site-nav --> in the bar (after its brand and its menu button) becomes the nav#nav: Features (#features), with Meta.docs Docs (docs/: the site's Docs section, made by build_docs below), Download (#download, DOWNLOAD_ID), Changelog (changelog/), GitHub (Meta.repository), and last, with Meta.shop, "Buy license" (BUY_LABEL, to pricing/), drawn as the site's small accent button (NAV_BUY_CLASS: btn accent nav-buy; the site's style.css makes .nav-buy small), as Wren's nav. The home page has the sections those anchors name.
  • <!-- site-footer --> becomes the footer: "By" the publisher (Meta.publisher, Meta.author_url, its mark Meta.publisher_logo); the shop's pages (SHOP_LINKS, in Wren's order: Pricing, Privacy, Terms, Refunds, Imprint) and GitHub; the code's licence (Meta.licence: "MIT License"), Meta.footer_note (HTML), the toolkit, and CLASSIC_LINK.

The shop's pages list the same pages in their own footer, with the home, GitHub (Shop.repository) and the seller. A mark and no Meta.repository is refused. A home page without the marks keeps its own nav and footer (the toolkit's site).

The download for the reader's system

Changelog_Options.downloads lists the systems the program is published for (Download: os "windows", "linux" or "macos", label, href, detail), the first one shown when the reader's is not known (no JavaScript, a phone). In the home page, <!-- download --> becomes one button per system (a.btn.accent.get, the system's mark in .get-icon, "Download for <label>" in .get-main, the detail in .get-sub), and <!-- download-others --> a line that offers the other systems ("Also for Linux"; with one system, nothing). A script put before </body> shows the button and the line of the system the browser says it runs on. The version mark is replaced after, so href and detail can name it. The other systems' buttons carry hidden: the site's stylesheet keeps them hidden even where a .btn sets its display ([hidden] { display: none !important; }).

The shop's pages

A program that sells a licence (licence.md) has a pricing page and a thank-you page. Their marks become the blocks of its Shop (with_licence(page, shop)): <!-- licence-buy --> the offer and the script that opens Paddle's checkout (licence_buy_block), <!-- licence-thanks --> the licence of the purchase, asked of the licence Worker (licence_thanks_block). The button says "Coming soon" until the shop has its client token, its price and its Worker (shop_open). The pages carry their own style (LICENCE_CSS), drawn from the site's colours. licence_pages(shop) fills the six template pages of src/site/licence_pages/ (pricing, thanks, terms, refunds, privacy, imprint) for a program that keeps none of its own; Meta.shop makes build_changelog write them. Their titles say "Pricing · name", "License terms · name", "Refunds · name", "Privacy · name", "Imprint · name": "Pricing" is the word of every footer and of the page; the nav's entry is "Buy license", as Wren's.

What a page says when shared

build_meta(m, from, out) gives each page of out its canonical address (page_address: a folder for its index.html, so / and /index.html are one page), its Open Graph and Twitter tags from its own title and description (the card's width and height read from the picture), and the home page its structured data (m.ld_type, m.ld_fields). A redirect or a page marked noindex is left alone. It writes feed.xml (Atom, the last 30 versions), sitemap.xml, site.webmanifest, llms.txt, a 404.html when there is none, and with m.root_domain also robots.txt and favicon.ico. The sharing card (m.card) must be there: draw_card(m, site) draws it once, by hand, in a local Chromium (CHROME, or the usual places).

Light pictures

build_images(out, o) makes the pictures of the folder o.dir of a built site WebP, at their own width and at each of o.widths narrower than it, with o.encoder (toolbox.webp_encoder: the system's cwebp, nix libwebp, Debian webp; libwebp's own build on Windows, fetched once and pinned). A PNG is encoded at its width too; a WebP is published as it is (a project keeps its screenshots in WebP: toolbox.webp_encode). -preset text -q 90: a screenshot's small text stays as sharp as in the PNG, the file some twenty times smaller. Each <img> of a picture made gets its WebP and a srcset of its widths; the page says how wide it shows it with sizes, its own. Every other mention of the PNG (a link that opens it whole) gets the WebP at its own width, and the PNGs replaced are removed. o.keep names the PNGs left as they are: what other sites read (the sharing card, a logo, a favicon). Run it on the built site, after build_meta.

A project's site command does it at site build when its Project_Site.images names a folder: images = site.images_default() (img, copies at 720 and 1100 pixels, the logo, the card and the publisher's logo kept). The publishing machine needs cwebp (the Pages workflow installs Ubuntu's webp).

The documentation pages

build_docs(&d) makes a page of each Markdown document of d.source (the repository's docs/) in d.out (the site's docs/): a document cdp.md is the page cdp/index.html, at the address /docs/cdp/. Every page has the site's header (d.header) and footer (d.footer), and:

  • a menu of every page: open beside the page on a wide screen, folded under a "Documentation" toggle at 860 px and less (a checkbox: no script), with a search box, the sections, and the groups as <details> (open around the page shown);
  • a breadcrumb (Docs, the section, the page), the previous and next pages in the menu's order, an "On this page" table of the headings of levels 2 and 3 (from 2 of them, beside the page from 1180 px), and "Edit this page on GitHub" (d.repository, d.branch);
  • docs.css (docs_css(d.css)), search.js (search_js) and search-index.json (search_index_json: each page's address, title, section and the first SEARCH_TEXT_MAX bytes of its text). The search needs no server.

The menu is docs/_nav.txt:

# a comment
Section
  page.md  Label     a page of the section; without a label, its first heading
  dir/*    Label     every document of the folder, as a group; its README.md or index.md first, as "Overview"

A document that no line names goes to a last section, "More". A path that starts with _ is not a document. Without an index.md of its own, the documentation's home (docs/index.html) lists the pages by section.

What Docs gives besides: name (titles say "<page> · <name> docs"), note (the first line of every page: a comment that names writer.tool), head (the icon, the style sheets), expand (the project's directives in a document), rendered (called after each page: a second presentation of it), assets (folders of docs/ copied beside the pages, linked there: pictures), languages (the project's code languages), and moved (each page also at its old address docs/<name>.html, a page that sends the reader on, its canonical address under site_url). Every address given is root-absolute ("/img/logo.png"); site_relative makes each relative to its page, as a site served under a path of its own needs. rooted does the reverse for a piece of a page.

A link of a document is resolved from its folder: another document is its page (its #anchor kept), a file of an asset folder is its copy, ../site/<page>/index.html is that page of the site, and any other file of the repository is its page on GitHub. An address with a scheme stays.

The style sheet lays over the site's own. It reads the site's colours under these names: --bg, --surface, --surface-2, --line, --line-2, --text, --muted, --soft, --accent, --accent-dim. Docs_Css gives its first line (note), the height of the site's top bar (bar, in px), the project's colours (theme) and its own rules (extra, before the narrow-screen rules). DOCS_CODE_CSS styles the code blocks, their colours, the tables and the skip link, for a site whose style sheet has none: a code block and a table scroll sideways in their frame.

The pages are written through a Writer (write_generated): a file is written only when its bytes change, and with writer.check nothing is written and each file out of date is counted in writer.problems: a check that committed pages are up to date. prune_generated removes the pages the tool made (its name in their first 300 bytes) that nothing makes any more.

Markdown

render_markdown(source, &ctx) gives the HTML of a document, its headings (Heading: level, text, unique id) and its plain text. It reads ATX headings (GitHub's ids, heading_id, each with its # anchor), paragraphs, hard breaks (two trailing spaces), *emphasis* and _emphasis_ (not inside a word: gui_toolkit), **strong**, `code`, links with a title, pictures, <autolinks>, entities, backslash escapes, fenced code (``` or ~~~), nested lists, blockquotes, thematic breaks, tables (aligned, in a div.table-box; a | in a code span does not split a cell) and HTML blocks that start with a known tag (copied). Markdown_Context.link says what a link's address becomes ("": as written). markdown_title(md) is the plain text of the first # heading. A construct it does not read shows up as text.

A code block is coloured when the page is made (write_code_block, highlight): .k keyword, .s string, .c comment, .f call or directive, .t type or number. CODE_LANGUAGES has Formula, C, JavaScript, PowerShell, JSON and Rust, and labels for HTML, CSS and shell; a project adds its own Code_Language (Wren: WIDL), looked at first. A language it does not know is plain.

check_links(root, rules) reads every page under root (no browser): each href and src, resolved from the page's folder, must name a file there, and a #fragment an id of that page. A link that starts with / or climbs out of the site is wrong. Link_Rules.not_files lists the starts of addresses that are not files (Wren's wren-https:); with folders, a page is linked by its folder, never by its .html. It returns what is wrong, sorted, and the number of pages. trame site_build runs it on what it made.

The check in a browser

check(o) makes the pages with o.generate(site, out, o.user) into a temporary folder, serves them on 127.0.0.1, and drives Chrome or Edge with no window over src/cdp:

  • the image viewer of gallery.js on the home page and the classic screenshots: a click opens it, the picture loads at its size, the arrows go through the captures, Esc closes and gives the keyboard back to the link;
  • every page: the links, pictures, styles and scripts on the site are there, and the anchors they point at; the home page and the changelog link their classic page, and back;
  • the classic pages: a main, header, nav and footer, a text for every picture, a skip link that Tab reaches first, no sideways scrolling on a phone or a desktop, light and dark, a home page 1.5 screens high at most;
  • the documentation pages (build_docs): nothing sticks out of a 390 px screen but inside a code block's or a table's frame, the menu is closed there and beside the page at 1400 px; on docs/index.html, the toggle opens the menu and the search finds pages. A page left at an old address (a refresh) is not opened;
  • then the project's own checks (o.extra), with check_go, check_true, check_text, check_call, check_expect.

check_arguments reads --site folder, --shot file.png and --browser program. What the browser leaves (its processes, its profile) is removed, and a run that cannot remove it fails.

The vendor's fields

meta_default(name, url, repository, tagline, theme, accent, card = "img/main.png") -> Meta is a program's Meta with the vendor's fields filled: author, author_url and publisher from SELLER_FROMENT (licence.md), publisher_logo (img/froment-software-64.png), licence ("MIT"), ld_type ("SoftwareApplication"), changes (CHANGELOG.md), logo (img/logo.png), logo_file (site/img/logo.png) and root_domain off. A site that differs sets a field after the call; ld_fields and shop stay the program's.

Formula
site_meta :: proc() -> site.Meta {
	m := site.meta_default(name = "Papier", url = "https://papier.froment.software/", repository = REPOSITORY,
		tagline = "A fast clipboard history, searched as you type", theme = "#131315", accent = "#cbbca3")
	m.ld_fields = SITE_LD[:]
	m.shop = SHOP
	return m
}

The site command of a project's tool

command(Project_Site) -> toolbox.Command is the site command of a project's tool (toolbox.md). The Project_Site (copied; its slices must live as long as the tool) says what the site is:

  • meta: its Meta (its address, names, colours; Meta.changes its CHANGELOG.md);
  • dir: its sources in the repository ("": site);
  • pages: the Changelog_Options of its pages, the home page's version mark and downloads (changes "": Meta.changes; meta: always Project_Site.meta, so its nav, footer and shop);
  • extra: the project's own checks of site check (s.user is the ^Project_Site).
LineWhat it does
site build <site> <out>build_changelog then build_meta into <out>: what is published (project_build).
site check [--site folder] [--shot file.png] [--browser program]check, the pages made by build_changelog.
site carddraw_card into the site's folder, once, by hand.

Another line is refused: the command ends with .Usage (exit code 2).

Formula
@(rodata) DOWNLOADS := [?]site.Download{{os = "linux", label = "Linux", href = "...", detail = "..."}}
toolbox.tool_main("classeurtool", {..., site.command({meta = site_meta(), pages = {version_mark = "{{version}}", downloads = DOWNLOADS[:]}, extra = site_downloads})}, toolbox.ROOT_MARK_DEFAULT)

Tests

src/site/site_test.fm (the changelog, the classic links, what a page says when shared), check_test.fm (the files the server gives and refuses, the links and anchors, the browser's port file), markdown_test.fm (the Markdown and the colours of code), images_test.fm (a page pointed at its pictures in WebP), docs_test.fm (a documentation site made end to end in a scratch folder, checked again, its links read back).

Edit this page on GitHub