smalldocs.site
_site.class Page
Page(src: PurePosixPath, out: PurePosixPath, front: dict, meta: dict, body: str, html: str = '', env: dict = <factory>, mtime: float = 0.0)One page of the site: where it comes from and goes to, its options, and once rendered, its HTML.
| Parameter | Type | Default | Description |
|---|---|---|---|
src |
PurePosixPath | required | The source, relative to the project root, such as guide/intro.qmd |
out |
PurePosixPath | required | The output, relative to the output folder, such as guide/intro.html |
front |
dict | required | The page’s own front matter |
meta |
dict | required | Every option that applies to it: project, folder, then front matter |
body |
str | required | Its Markdown, without the front matter (a notebook already turned into Markdown) |
html |
str | '' |
The rendered body |
env |
dict | <factory> |
What rendering found: headings, search text, maths, … |
mtime |
float | 0.0 |
When the source last changed |
parse_date
parse_date(value: object, mtime: float = 0.0) -> date | NoneRead a date as Quarto does: ISO text, a YAML date, today, now or last-modified.
| Parameter | Type | Default | Description |
|---|---|---|---|
value |
object | required | The value of date: |
mtime |
float | 0.0 |
The source’s modification time, for last-modified |
| returns | date | None | The date, or None |
is_glob
is_glob(s: str) -> boolSay whether a path has glob characters.
| Parameter | Type | Default | Description |
|---|---|---|---|
s |
str | required | A path, as written in the config |
| returns | bool | Whether the string has glob characters |
rel
rel(target: PurePosixPath | str, page: Page | None) -> strWrite a link from a page to another output file, relative, as Quarto does.
| Parameter | Type | Default | Description |
|---|---|---|---|
target |
PurePosixPath | str | required | A path relative to the output root |
page |
Page | None | required | The page the link is written on; None for the root |
| returns | str | The path from the page to the target |
class Site
Site(project: Project, quiet: bool = False, preview: bool = False)A project being built.
| Parameter | Type | Default | Description |
|---|---|---|---|
project |
Project | required | The project to build |
quiet |
bool | False |
Print nothing but errors |
preview |
bool | False |
Add the reload script for smalldocs preview |
Site.say
Site.say(msg: str) -> NonePrint a line, unless quiet.
| Parameter | Type | Default | Description |
|---|---|---|---|
msg |
str | required | The line to print |
Site.warn
Site.warn(msg: str) -> NoneKeep a warning, once.
| Parameter | Type | Default | Description |
|---|---|---|---|
msg |
str | required | The warning |
Site.ignored
Site.ignored(path: Path) -> boolLeave out files under _ or . folders, the output folder, and virtual environments.
| Parameter | Type | Default | Description |
|---|---|---|---|
path |
Path | required | A file under the root |
| returns | bool | Whether a file is left out of the site |
Site.walk
Site.walk() -> list[Path]List the project’s files, in order, without the ones Quarto leaves out.
| Parameter | Type | Default | Description |
|---|---|---|---|
| returns | list[Path] | Every file under the root that is not left out |
Site.discover
Site.discover() -> list[PurePosixPath]Find the pages: project.render when it is given, else every .qmd, .md and .ipynb that is not left out.
| Parameter | Type | Default | Description |
|---|---|---|---|
| returns | list[PurePosixPath] | The sources of the pages to render |
Site.read
Site.read(src: PurePosixPath) -> PageRead a page’s source and options.
| Parameter | Type | Default | Description |
|---|---|---|---|
src |
PurePosixPath | required | The page’s source, relative to the root |
| returns | Page | The page with its options, not yet rendered |
Site.find_page
Site.find_page(target: PurePosixPath) -> Page | NoneFind the page a path points at: the source itself, or a folder’s index page.
| Parameter | Type | Default | Description |
|---|---|---|---|
target |
PurePosixPath | required | A path relative to the root: a source, an output, or a folder |
| returns | Page | None | The page for a source path, or a folder’s index |
Site.resolve
Site.resolve(href: str, page: Page | None, record: bool = True) -> strRewrite a link: pages to their .html, /x from the root, and local files copied as resources.
| Parameter | Type | Default | Description |
|---|---|---|---|
href |
str | required | A link as written in a page, or in the config |
page |
Page | None | required | The page it is written on; None for the config, which is relative to the root |
record |
bool | True |
Note a broken link |
| returns | str | The link to write in the HTML |
Site.run_scripts
Site.run_scripts(key: str, inputs: list[PurePosixPath]) -> NoneRun project.pre-render or project.post-render, with Quarto’s environment variables.
| Parameter | Type | Default | Description |
|---|---|---|---|
key |
str | required | pre-render or post-render |
inputs |
list[PurePosixPath] | required | The pages being rendered |
Site.load_symbols
Site.load_symbols() -> NoneRead the name index that turns a name in backticks into a link: _symbols.json, when linkify is on.
Site.render_page
Site.render_page(page: Page) -> NoneRender one page’s Markdown into HTML.
| Parameter | Type | Default | Description |
|---|---|---|---|
page |
Page | required | The page to render |
Site.check_output
Site.check_output() -> NoneRefuse an output folder that a build must not empty: the project, a folder above it, or a folder that is not a built site.
Site.build
Site.build() -> intBuild the whole site into the output folder.
| Parameter | Type | Default | Description |
|---|---|---|---|
| returns | int | The number of pages written |
Site.theme_files
Site.theme_files() -> list[tuple[str, str]]Find the themes in format.html.theme: one name, a list, or light: and dark:.
| Parameter | Type | Default | Description |
|---|---|---|---|
| returns | list[tuple[str, str]] | (name, mode) for each theme stylesheet the site uses |
Site.copy_assets
Site.copy_assets(nav: layout.SiteNav) -> NoneCopy the theme, Bootstrap, the icons, search and smalldocs’ own CSS and JavaScript into site_libs.
| Parameter | Type | Default | Description |
|---|---|---|---|
nav |
layout.SiteNav | required | The site’s navigation |
Site.copy_resources
Site.copy_resources() -> NoneCopy the files that pages link to, and project.resources, keeping their paths.
Site.walk_all
Site.walk_all() -> list[Path]List every file, for resources, which may name a hidden file such as .nojekyll.
| Parameter | Type | Default | Description |
|---|---|---|---|
| returns | list[Path] | Every file under the root but the output folder, hidden ones too |
Site.write_search
Site.write_search() -> NoneWrite search.json: one entry for each section of each page, as Quarto’s search reads.
Site.write_sitemap
Site.write_sitemap() -> NoneWrite sitemap.xml when website.site-url is set.
cell_defaults
cell_defaults(opts: dict) -> dictRead the options that hide code or output in every cell of a page: echo: false, or execute: {echo: false}.
| Parameter | Type | Default | Description |
|---|---|---|---|
opts |
dict | required | A page’s merged options |
| returns | dict | echo, output and include as the page and execute: set them |
build
build(root: Path | str = '.', quiet: bool = False, preview: bool = False) -> SiteLoad a project and build it.
| Parameter | Type | Default | Description |
|---|---|---|---|
root |
Path | str | '.' |
The project folder |
quiet |
bool | False |
Print nothing but errors and warnings |
preview |
bool | False |
Add the reload script, for smalldocs preview |
| returns | Site | The built site, with its warnings |