On this page
Build pipeline module that scans docs/ templates, resolves directives against source code, renders HTML, and generates sitemap, feed, and search index.
#selfdoc.build
#selfdoc.build
Build pipeline for selfdoc: template scanning, directive resolution, HTML output.
#_read_png_dimensions
def _read_png_dimensions(filepath)Read width and height from a PNG file's IHDR chunk.
The IHDR chunk starts at byte 16. Width is 4 bytes big-endian at offset 16, height is 4 bytes big-endian at offset 20. Returns (width, height) or None if the file is too short or invalid.
#_read_gif_dimensions
def _read_gif_dimensions(filepath)Read width and height from a GIF file header.
Bytes 6-7 are width (little-endian uint16), bytes 8-9 are height (little-endian uint16). Returns (width, height) or None if the file is too short or invalid.
#_read_jpeg_dimensions
def _read_jpeg_dimensions(filepath)Read width and height from a JPEG file by walking SOF markers.
Walks JPEG segments looking for SOF0-SOF3 markers (\xff\xc0 through \xff\xc3). When found, reads height (2 bytes BE) and width (2 bytes BE) after skipping the segment length and precision byte. Returns (width, height) or None if the file is invalid or unreadable.
#_read_webp_dimensions
def _read_webp_dimensions(filepath)Read width and height from a WebP file.
Supports VP8 (lossy), VP8L (lossless), and VP8X (extended) sub-formats. Returns (width, height) or None if the file is invalid or unreadable.
#_get_image_dimensions
def _get_image_dimensions(filepath)Read dimensions from an image file (PNG, GIF, JPEG, or WebP).
Returns (width, height) or None if the format is unsupported or the file cannot be read.
#_add_image_dimensions
def _add_image_dimensions(html_text, docs_dir, page_rel_path)Add width/height attributes to tags whose source files exist.
For each in html_text, resolve the src relative to the page's directory within docs_dir. If the file is a PNG, GIF, JPEG, or WebP, read its dimensions and insert width="X" height="Y" attributes.
#_minify_css
def _minify_css(css_text)Minify CSS by removing comments, collapsing whitespace, and trimming.
Simple regex-based approach suitable for well-formed CSS.
#_extract_critical_css
def _extract_critical_css(full_css)Split theme CSS into critical (above-the-fold) and full parts.
The theme CSS contains a marker comment that separates critical styles (needed for first paint) from non-critical styles (loaded async). Returns (critical_css, full_css) where critical_css is everything above the marker and full_css is the complete stylesheet.
#_minify_html
def _minify_html(html_text)Minify HTML by removing comments and collapsing inter-tag whitespace.
Preserves whitespace inside
, ,