Module

rendering.template_functions.seo

SEO helper functions for templates.

Provides 4 functions for generating SEO-friendly meta tags and content.

Functions

register
Register SEO helper functions with Jinja2 environment.
2 None
def register(env: Environment, site: Site) -> None

Register SEO helper functions with Jinja2 environment.

Parameters 2

Name Type Default Description
env Environment
site Site
meta_description
Generate meta description from text. Creates SEO-friendly description by: - Stripping HTML - Trunc…
2 str
def meta_description(text: str, length: int = 160) -> str

Generate meta description from text.

Creates SEO-friendly description by:

  • Stripping HTML
  • Truncating to length
  • Ending at sentence boundary if possible

Parameters 2

Name Type Default Description
text str

Source text

length int 160

Maximum length (default: 160 chars)

Returns

str

Meta description text

meta_keywords
Generate meta keywords from tags.
2 str
def meta_keywords(tags: list[str], max_count: int = 10) -> str

Generate meta keywords from tags.

Parameters 2

Name Type Default Description
tags list[str]

List of tags/keywords

max_count int 10

Maximum number of keywords (default: 10)

Returns

str

Comma-separated keywords

canonical_url
Generate canonical URL for SEO.
2 str
def canonical_url(path: str, base_url: str) -> str

Generate canonical URL for SEO.

Parameters 2

Name Type Default Description
path str

Page path (relative or absolute)

base_url str

Site base URL

Returns

str

Full canonical URL

og_image
Generate Open Graph image URL.
2 str
def og_image(image_path: str, base_url: str) -> str

Generate Open Graph image URL.

Parameters 2

Name Type Default Description
image_path str

Relative path to image

base_url str

Site base URL

Returns

str

Full image URL for og:image