Utils
Constants
Tags whose boundaries separate words. Inline tags (a, em, code, ...) don't: "Nicolino," must read "Nicolino," not "Nicolino ,", which is how Lexbor's inner_text joined them too.
Elements whose raw text content is never visible
Class methods
Glob patterns for markdown, html and pandoc content under a base path
Create the right content file for a source based on its extension kind is used in error messages (e.g. "post", "page")
Truncate already-plain text (see plain_text) at a word boundary
Find all files with given extension in path, if two files are alternative languages of one another they are grouped together.
Suffix to append to a filename for a given language (empty for the default language, ".#{lang}" otherwise)
Alternate-language links for a generated page. Two output conventions exist (issue #54):
- :file_suffix (default): "<stem>.<lang>.html" / "<stem>.html", used by post and folder index pages (output/posts/index.es.html)
- :dir_suffix: the FIRST directory under output/ carries the language marker (output/tags.es/foo/index.html), used by taxonomies, the archive and galleries roots
Returns one {lang, link, title} hash per other configured language. This is the site-level helper behind translation switcher menus.
The configured output directory with a trailing slash, for building URL prefixes (e.g. "output/", "public/site/")
Process inputs in parallel chunks, returning per-chunk results in order. Errors in a chunk are logged and that chunk is skipped.
Convert path to link, optionally changing extension
path_to_link("output/foo/../bar") # => "/bar"
Plain text of an HTML fragment: block-level tags become spaces (so words on either side of a block boundary stay apart), inline tags vanish, entities are decoded, whitespace is collapsed. Both the reading-time word count and the meta description derive from this, so a page computes it once instead of running two full Lexbor parses of its HTML.
A single pass over the bytes: about 20x faster than parsing with Lexbor and 5x faster than a regex strip, on a typical page. Tag and comment contents are dropped wholesale, quoted attribute values and "-->" included.
Filter out files from directories that correspond to disabled features
Plain-text excerpt of an HTML fragment, for meta description tags: at most limit characters, cut at a word boundary with an ellipsis.
Word count of an HTML fragment's text, for reading-time estimates in themes.