smalldocs.layout
as_list
as_list(v: object) -> listMake a config value that may be one item or a list into a list.
| Parameter | Type | Default | Description |
|---|---|---|---|
v |
object | required | A config value |
| returns | list | The value as a list: None is empty, a single value is one item |
inline_md
inline_md(text: str, site: Site, page: Page | None) -> strRender a short piece of Markdown from the config, such as a footer.
| Parameter | Type | Default | Description |
|---|---|---|---|
text |
str | required | Markdown on one line, from the config |
site |
Site | required | The site, to rewrite links |
page |
Page | None | required | The page the text goes on |
| returns | str | HTML without the paragraph around it |
format_date
format_date(d: date | None, fmt: str | None = None) -> strWrite a date in one of Quarto’s formats: the default is MMMM D, YYYY.
| Parameter | Type | Default | Description |
|---|---|---|---|
d |
date | None | required | A date |
fmt |
str | None | None |
Quarto’s date-format, such as MMMM D, YYYY, or None for that one |
| returns | str | The date as text |
class Item
Item(text: str, href: str = '', page: Page | None = None, children: list[Item] = <factory>, section: bool = False, icon: str = '', sep: bool = False)One entry of a sidebar or navbar: a page, a link, a section or a separator.
| Parameter | Type | Default | Description |
|---|---|---|---|
text |
str | required | What the entry says (HTML-safe text) |
href |
str | '' |
Where it goes: an output path from the root, or a full URL; empty for a section with no page |
page |
Page | None | None |
The page it is, if it is one |
children |
list[Item] | <factory> |
The entries of a section or menu |
section |
bool | False |
Whether it is a section |
icon |
str | '' |
A Bootstrap icon name |
sep |
bool | False |
Whether it is a separator line |
Item.pages
Item.pages() -> list[Page]List the pages under this entry, in order.
| Parameter | Type | Default | Description |
|---|---|---|---|
| returns | list[Page] | Every page in this entry and below it, in order |
Item.contains
Item.contains(page: Page) -> boolSay whether a page is in this entry.
| Parameter | Type | Default | Description |
|---|---|---|---|
page |
Page | required | A page |
| returns | bool | Whether the page is here or below |
is_glob_str
is_glob_str(s: str) -> boolSay whether a string is a glob.
| Parameter | Type | Default | Description |
|---|---|---|---|
s |
str | required | A string from the config |
| returns | bool | Whether the string has glob characters |
class Layout
Layout(site: Site, nav: SiteNav, page: Page)Lay out one page.
| Parameter | Type | Default | Description |
|---|---|---|---|
site |
Site | required | The site |
nav |
SiteNav | required | Its navigation |
page |
Page | required | The page to lay out |
Layout.href
Layout.href(item_href: str) -> strWrite an entry’s link from this page: an output path from the root, or a link as given in the config.
| Parameter | Type | Default | Description |
|---|---|---|---|
item_href |
str | required | An entry’s link: an output path, or a link from the config |
| returns | str | The link from this page |
Layout.root_rel
Layout.root_rel(href: str) -> strMake a link from the config start at the project root.
| Parameter | Type | Default | Description |
|---|---|---|---|
href |
str | required | A link from the config |
| returns | str | A config link, made to start at the root |
Layout.icon
Layout.icon(name: str) -> listMake a Bootstrap icon.
| Parameter | Type | Default | Description |
|---|---|---|---|
name |
str | required | A Bootstrap icon name, or empty |
| returns | list | An icon element, or nothing |
Layout.head
Layout.head() -> HeadMake the head: title, meta, the theme, icons, our CSS, the site’s CSS, and maths when the page has some.
| Parameter | Type | Default | Description |
|---|---|---|---|
| returns | Head | The <head> element |
Layout.offset
Layout.offset() -> strFind the path from the page’s folder up to the root.
| Parameter | Type | Default | Description |
|---|---|---|---|
| returns | str | The path from the page up to the root, such as ../ |
Layout.includes
Layout.includes(key: str) -> list[str]Read include-in-header, include-before-body or include-after-body: files, or text: entries.
| Parameter | Type | Default | Description |
|---|---|---|---|
key |
str | required | include-in-header, include-before-body or include-after-body |
| returns | list[str] | The text of each include |
Layout.search_on
Layout.search_on() -> boolSay whether the site has search: on, unless website.search: false.
| Parameter | Type | Default | Description |
|---|---|---|---|
| returns | bool | Whether the site shows a search box |
Layout.search_box
Layout.search_box() -> DivMake the search box; smalldocs.js fills the results.
| Parameter | Type | Default | Description |
|---|---|---|---|
| returns | Div | The search box |
Layout.side_item
Layout.side_item(it: Item, depth: int) -> LiMake one sidebar entry: a page, a link, or a section that folds.
| Parameter | Type | Default | Description |
|---|---|---|---|
it |
Item | required | The entry |
depth |
int | required | How deep it sits in the sidebar |
| returns | Li | The sidebar entry |
Layout.crumbs_html
Layout.crumbs_html() -> listMake the breadcrumbs: the sections that hold the page.
| Parameter | Type | Default | Description |
|---|---|---|---|
| returns | list | The breadcrumbs’ elements, or nothing |
Layout.title_block
Layout.title_block() -> listMake the title block: title, subtitle, categories, description, authors and date.
| Parameter | Type | Default | Description |
|---|---|---|---|
| returns | list | The title block’s elements |
Layout.category_link
Layout.category_link(cat: str) -> strLink a category to the listing page that lists this page, filtered to it, as Quarto does.
| Parameter | Type | Default | Description |
|---|---|---|---|
cat |
str | required | A category of the page |
| returns | str | HTML: the category, linked to the listing that shows it |
Layout.toc
Layout.toc() -> listMake the table of contents from the page’s headings, to toc-depth (3).
| Parameter | Type | Default | Description |
|---|---|---|---|
| returns | list | The table of contents’ elements, or nothing |
Layout.repo_actions
Layout.repo_actions() -> listMake the repository links under the table of contents: edit, source, issue.
| Parameter | Type | Default | Description |
|---|---|---|---|
| returns | list | The links’ elements, or nothing |
Layout.body_classes
Layout.body_classes(has_toc: bool) -> strName the layout in the body’s classes, as Quarto does.
| Parameter | Type | Default | Description |
|---|---|---|---|
has_toc |
bool | required | Whether the page shows a table of contents |
| returns | str | The classes of <body> |
Layout.render
Layout.render() -> strPut the page together.
| Parameter | Type | Default | Description |
|---|---|---|---|
| returns | str | The whole HTML document |
Layout.preview_script
Layout.preview_script() -> strMake the script that smalldocs preview adds: it asks for the build number and reloads when it changes.
| Parameter | Type | Default | Description |
|---|---|---|---|
| returns | str | JavaScript that reloads the page when the site is rebuilt |
page
page(site: Site, nav: SiteNav, p: Page) -> strLay out one page.
| Parameter | Type | Default | Description |
|---|---|---|---|
site |
Site | required | The site |
nav |
SiteNav | required | Its navigation |
p |
Page | required | The page to lay out |
| returns | str | The whole HTML document |
search_options
search_options(site: Site) -> strWrite the search options.
| Parameter | Type | Default | Description |
|---|---|---|---|
site |
Site | required | The site |
| returns | str | The options for the search script, as JSON |