pub struct HtmlRenderer { /* private fields */ }Expand description
Assembles complete HTML documents from rendered page bodies.
Implementations§
Source§impl HtmlRenderer
impl HtmlRenderer
Sourcepub fn with_theme(theme: ThemeAppearance) -> Self
pub fn with_theme(theme: ThemeAppearance) -> Self
Renderer with a color theme overriding the default palette.
Sourcepub fn with_style(style: SiteStyle) -> Self
pub fn with_style(style: SiteStyle) -> Self
Renderer with a fully caller-specified SiteStyle.
Sourcepub fn interactivity_script(&self) -> &'static str
pub fn interactivity_script(&self) -> &'static str
The built-in interactivity: spoiler toggles, and the parent half of the island resize bridge.
§The island resize protocol
An island is a sandboxed <iframe> with no allow-same-origin, so the
page holding it cannot read the embedded document’s height. Instead:
- On each frame’s
load, the parent posts{type: 'diaryx-html-attachment-measure'}into it (twice, 80ms apart, to catch a document whose own layout settles after load). - The child answers with
{type: 'diaryx-html-attachment-size', height}— seeISLAND_CHILD_SCRIPT, which is written to the site asISLAND_CHILD_SCRIPT_FILENAMEfor island documents to load. - The parent matches the reply to a frame by
event.sourceand sets that frame’s height, clamped to 200–4000px — the same range{height=…}is clamped to, so an island cannot make itself a pixel tall or taller than any screen.
An island whose document loads no child script simply keeps the
min-height its embed asked for; the protocol is an improvement on that
default, not a requirement of it.
Sourcepub fn render_page(
&self,
page: &PublishedPage,
site_title: &str,
single_file: bool,
) -> String
pub fn render_page( &self, page: &PublishedPage, site_title: &str, single_file: bool, ) -> String
Wrap a rendered page into a complete HTML document.
Sourcepub fn render_single_document(
&self,
pages: &[PublishedPage],
site_title: &str,
) -> String
pub fn render_single_document( &self, pages: &[PublishedPage], site_title: &str, ) -> String
Render all pages into a single combined document.
Sourcepub fn render_page_in_site(
&self,
page: &PublishedPage,
ctx: &PageContext<'_>,
) -> String
pub fn render_page_in_site( &self, page: &PublishedPage, ctx: &PageContext<'_>, ) -> String
Render a page with full site context (nav, breadcrumbs, SEO, feeds), into the caller’s shell template or the built-in one.
A page whose layout is PageLayout::Bare takes neither: it carries its
own frame, and gets only the head this crate must write for it. A
PageLayout::Verbatim page takes not even that — its body is already
the file, and the rendered document is those bytes and nothing else.
Sourcepub fn static_assets(&self) -> Vec<(String, Vec<u8>)>
pub fn static_assets(&self) -> Vec<(String, Vec<u8>)>
Static assets to write alongside output files: the stylesheet, the favicon when there is one, and the island child script.
The island script is written unconditionally because an island document
referencing it is written by hand, and a site that publishes one has no
way to ask for the file to appear. Returns (filename, content) pairs.