Skip to main content

HtmlRenderer

Struct HtmlRenderer 

Source
pub struct HtmlRenderer { /* private fields */ }
Expand description

Assembles complete HTML documents from rendered page bodies.

Implementations§

Source§

impl HtmlRenderer

Source

pub fn new() -> Self

Renderer with built-in default styling (no theme, bundled CSS).

Source

pub fn with_theme(theme: ThemeAppearance) -> Self

Renderer with a color theme overriding the default palette.

Source

pub fn with_style(style: SiteStyle) -> Self

Renderer with a fully caller-specified SiteStyle.

Source

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:

  1. 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).
  2. The child answers with {type: 'diaryx-html-attachment-size', height} — see ISLAND_CHILD_SCRIPT, which is written to the site as ISLAND_CHILD_SCRIPT_FILENAME for island documents to load.
  3. The parent matches the reply to a frame by event.source and sets that frame’s height, clamped to 200–4000px — the same range ![alt](x.html){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.

Source

pub fn render_page( &self, page: &PublishedPage, site_title: &str, single_file: bool, ) -> String

Wrap a rendered page into a complete HTML document.

Source

pub fn render_single_document( &self, pages: &[PublishedPage], site_title: &str, ) -> String

Render all pages into a single combined document.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Default for HtmlRenderer

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.