Classes
RedirectGenerator
Generates redirect HTML pages for page aliases.
For each page with aliases, creates lightweight HT…
RedirectGenerator
Generates redirect HTML pages for page aliases.
For each page with aliases, creates lightweight HTML files at the alias paths that redirect to the canonical URL. Includes proper SEO signals (canonical link, noindex, meta refresh).
Optionally generates a _redirects file for Netlify/Vercel for faster server-side redirects.
Methods 1
generate
Generate all redirect pages.
Iterates through all pages, generates redirect HT…
generate
def generate(self) -> int
Generate all redirect pages.
Iterates through all pages, generates redirect HTML for each alias, and optionally generates a _redirects file for platform-specific server-side redirects.
Returns
Number of redirects generatedint
—
Internal Methods 4
__init__
Initialize redirect generator.
__init__
def __init__(self, site: Site) -> None
Initialize redirect generator.
Parameters 1
site |
Site |
Site instance with pages containing aliases |
_generate_redirect
Generate a single redirect HTML page.
_generate_redirect
def _generate_redirect(self, from_path: str, to_url: str) -> bool
Generate a single redirect HTML page.
Parameters 2
from_path |
str |
Source path (alias), e.g., "/old/posts/my-post/" |
to_url |
str |
Target URL to redirect to, e.g., "/blog/my-post/" |
Returns
True if redirect was generated, False if skipped (conflict)bool
—
_render_redirect_html
Render redirect HTML with SEO hints.
Generates a minimal HTML page that:
- Red…
_render_redirect_html
def _render_redirect_html(self, from_path: str, to_url: str) -> str
Render redirect HTML with SEO hints.
Generates a minimal HTML page that:
- Redirects immediately via meta refresh
- Includes canonical link for SEO
- Has noindex to prevent redirect pages appearing in search
- Provides fallback link for browsers without JavaScript/meta refresh
Parameters 2
from_path |
str |
Original path (for display only) |
to_url |
str |
Target URL to redirect to |
Returns
HTML string for redirect pagestr
—
_generate_redirects_file
Generate _redirects file for Netlify/Vercel.
Only generates if enabled in conf…
_generate_redirects_file
def _generate_redirects_file(self, alias_map: dict[str, list[tuple[str, str]]]) -> None
Generate _redirects file for Netlify/Vercel.
Only generates if enabled in config:
[redirects]
generate_redirects_file = true
Parameters 1
alias_map |
dict[str, list[tuple[str, str]]] |
Map of alias -> [(target_url, title), ...] |