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 |
css_value
css_value(v: object) -> str | NoneCheck a value before it goes into CSS: no <, >, {, }, ;, backslash or line break.
| Parameter | Type | Default | Description |
|---|---|---|---|
v |
object | required | A value from the config, for a CSS property |
| returns | str | None | The value, or None when it could break out of a style block |
css_color
css_color(v: object) -> str | NoneTurn a colour of the config into CSS: a Bootstrap name reads the theme’s variable.
| Parameter | Type | Default | Description |
|---|---|---|---|
v |
object | required | A colour from the config: a Bootstrap name such as light, or a CSS colour |
| returns | str | None | The CSS colour, or None |
rgb_of
rgb_of(color: str) -> tuple[int, int, int] | NoneRead the red, green and blue of a hex or rgb() colour.
| Parameter | Type | Default | Description |
|---|---|---|---|
color |
str | required | A CSS colour: #rgb, #rrggbb, or rgb(r, g, b) |
| returns | tuple[int, int, int] | None | Its red, green and blue, or None for another form |
logo_images
logo_images(logo: object, alt: str = '') -> list[tuple[str, str, str]]Read a logo of the config: one image, or one for the light mode and one for the dark mode.
| Parameter | Type | Default | Description |
|---|---|---|---|
logo |
object | required | logo from the config: a path, {path, alt}, or {light, dark} where each is a path or {path, alt} |
alt |
str | '' |
logo-alt, for an image with no alt of its own |
| returns | list[tuple[str, str, str]] | (path, alt text, extra class) for each image: light-content and dark-content for two modes |
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, attrs: dict = <factory>)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 |
attrs |
dict | <factory> |
The link’s target, rel, aria-label and id, from the config |
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.logo
Layout.logo(own: object, alt: str = '') -> list[tuple[str, str, str]]Find the logo: the site’s own, or else the one its theme extension gives.
| Parameter | Type | Default | Description |
|---|---|---|---|
own |
object | required | The logo that the site sets, if any: a path, or a mapping such as {light, dark} |
alt |
str | '' |
logo-alt, the text of an image with no alt of its own |
| returns | list[tuple[str, str, str]] | (link, alt text, extra class) for each image: the site’s, else the theme’s; empty when there is none |
Layout.logo_html
Layout.logo_html(own: object, alt: str) -> strWrite the logo: one image, or an image for the light mode and one for the dark mode.
| Parameter | Type | Default | Description |
|---|---|---|---|
own |
object | required | The logo that the site sets, if any |
alt |
str | required | logo-alt |
| returns | str | The images, or empty when there is no logo |
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.option
Layout.option(key: str) -> objectRead an option of the page, or else of website:.
| Parameter | Type | Default | Description |
|---|---|---|---|
key |
str | required | An option that a page or website: can set, such as back-to-top-navigation |
| returns | object | The page’s value, else the website’s |
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.absolute
Layout.absolute(img: object) -> strWrite the full URL of the page’s image, for Open Graph and Twitter.
| Parameter | Type | Default | Description |
|---|---|---|---|
img |
object | required | An image path from the front matter or the config |
| returns | str | Its full URL, from website.site-url |
Layout.page_style
Layout.page_style() -> strTurn mainfont, monofont, fontsize, linestretch, linkcolor, backgroundcolor, fontcolor and max-width into CSS variables.
| Parameter | Type | Default | Description |
|---|---|---|---|
| returns | str | CSS that sets the page’s fonts, colours and width, or empty |
Layout.twitter_card
Layout.twitter_card(full: str, desc: object, img: object) -> listMake the Twitter card tags from website.twitter-card: true, or card-style, creator, site, title, description and image.
| Parameter | Type | Default | Description |
|---|---|---|---|
full |
str | required | The title of the page, as the browser tab shows it |
desc |
object | required | The description of the page, or None |
img |
object | required | The image of the page, or None |
| returns | list | The twitter: meta tags, or nothing |
Layout.analytics
Layout.analytics() -> listMake Google Analytics’ gtag scripts from website.google-analytics: a tracking id, or tracking-id, anonymize-ip and storage.
| Parameter | Type | Default | Description |
|---|---|---|---|
| returns | list | The Google Analytics scripts, or nothing |
Layout.comments
Layout.comments() -> dictRead comments: the website’s, merged with the page’s; comments: false on a page turns them off.
| Parameter | Type | Default | Description |
|---|---|---|---|
| returns | dict | The comment services of the page: giscus, utterances, hypothesis |
Layout.hypothesis
Layout.hypothesis() -> listMake the scripts of Hypothesis, the annotation service: comments.hypothesis is true or its options.
| Parameter | Type | Default | Description |
|---|---|---|---|
| returns | list | The scripts of Hypothesis, in the head, or nothing |
Layout.comment_threads
Layout.comment_threads() -> listMake the comment threads of giscus or utterances, with their options.
| Parameter | Type | Default | Description |
|---|---|---|---|
| returns | list | The scripts of giscus and utterances, after the page’s content, or nothing |
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_opts
Layout.search_opts() -> dictRead the options of website.search, when it is a mapping.
| Parameter | Type | Default | Description |
|---|---|---|---|
| returns | dict | The options of website.search, or an empty dict |
Layout.search_where
Layout.search_where() -> str | NoneFind where the search box goes: the navbar, unless search.location: sidebar or the site has no navbar.
| Parameter | Type | Default | Description |
|---|---|---|---|
| returns | str | None | navbar, sidebar, or None for no search box |
Layout.tool_attrs
Layout.tool_attrs(t: dict) -> dictRead the attributes of a tool’s link: its label, from aria-label, text or icon, and target, rel and id.
| Parameter | Type | Default | Description |
|---|---|---|---|
t |
dict | required | A tool from the config: icon, href or url, text, and link attributes |
| returns | dict | The tool link’s aria-label, target, rel and id |
Layout.search_box
Layout.search_box() -> DivMake the search box; smalldocs.js fills the results. search.type: overlay shows an icon that opens the box.
| 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.panel_look
Layout.panel_look(opts: dict, name: str, where: str) -> tuple[str, dict]Read background, foreground and border of the sidebar or the footer: CSS variables on it, and its classes.
| Parameter | Type | Default | Description |
|---|---|---|---|
opts |
dict | required | website.sidebar or website.page-footer |
name |
str | required | sidebar or footer, for the classes and the variables |
where |
str | required | The option’s name in a warning, such as page-footer |
| returns | tuple[str, dict] | Classes to add to the panel, and its attributes |
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, date and keywords.
| 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_location
Layout.toc_location() -> tuple[str | None, bool]Read toc-location: right, left, body, left-body or right-body.
| Parameter | Type | Default | Description |
|---|---|---|---|
| returns | tuple[str | None, bool] | left, right or None for the table beside the text; whether one is in the body too |
Layout.toc_expand
Layout.toc_expand() -> int | NoneRead toc-expand: true shows every level, false the top level, a number that many levels.
| Parameter | Type | Default | Description |
|---|---|---|---|
| returns | int | None | How many levels show before the reader scrolls to a section; None shows every level |
Layout.toc
Layout.toc(body: bool = False, ids: bool = True, extra: list | None = None) -> listMake the table of contents from the page’s headings, to toc-depth (3).
| Parameter | Type | Default | Description |
|---|---|---|---|
body |
bool | False |
The table in the text, toc-location: body, with plain links |
ids |
bool | True |
Give the links their toc- ids; a second table on the page has none |
extra |
list | None | None |
More elements at its end, such as other-links |
| returns | list | The table of contents’ elements, or nothing |
Layout.extra_links
Layout.extra_links() -> listMake other-links and code-links: lists of links under the table of contents, as Quarto writes them.
| Parameter | Type | Default | Description |
|---|---|---|---|
| returns | list | The lists of other-links and code-links, 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.back_to_top
Layout.back_to_top() -> listMake Quarto’s Back to top link, when back-to-top-navigation is on; smalldocs.js shows it as the reader scrolls up.
| Parameter | Type | Default | Description |
|---|---|---|---|
| returns | list | The link, or nothing |
Layout.license_html
Layout.license_html(lic: object) -> strWrite the licence: a Creative Commons name links to its deed, as Quarto does.
| Parameter | Type | Default | Description |
|---|---|---|---|
lic |
object | required | license: a Creative Commons name such as CC BY, a URL, text, or {text, url} |
| returns | str | HTML for the Reuse section |
Layout.appendix
Layout.appendix() -> listMake Quarto’s appendix at the end of the page: Reuse, from license, and Copyright, from copyright.
| Parameter | Type | Default | Description |
|---|---|---|---|
| returns | list | The appendix’s 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.pinned
Layout.pinned() -> boolRead navbar.pinned, or with no navbar sidebar.pinned: smalldocs keeps the header on the screen unless one is false.
| Parameter | Type | Default | Description |
|---|---|---|---|
| returns | bool | Whether the header stays on the screen as the reader scrolls |
Layout.main_attrs
Layout.main_attrs() -> dictPass link-external-icon and link-external-filter to smalldocs.js, which marks the links to other sites.
| Parameter | Type | Default | Description |
|---|---|---|---|
| returns | dict | Data attributes for smalldocs.js on <main>, or none |
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 |