Allowing redirect pages to use a template

If you use aliases or redirect_to for sections, an html page is generated to perform a redirect. However, it would be beneficial to allow these redirect pages to have access to template, to update titles and set various meta tags.

For example:

This is an example of how a link to my blog post looks when I share it in a messaging app:

For contrast, here is a preview to a link that performs a redirect:

Being able to template the redirect page would allow the title to be set, as well as a description, and meta tags for SEO and social media previews.

1 Like

I think this could be done by supplying the necessary context to the render_redirect_template function:

/// Renders the `internal/alias.html` template that will redirect
/// via refresh to the url given
pub fn render_redirect_template(url: &str, tera: &Tera) -> Result<String> {
    let mut context = Context::new();
    context.insert("url", &url);

    tera.render("internal/alias.html", &context)
        .with_context(|| format!("Failed to render alias for '{}'", url))
}

And then the user could just make their own template file under internal/alias.html.

However, there’s a chance then that the user might break the redirect functionality by not including the correct HTML in the template, so more work would have to be done no the rust side to prevent that from happening.

I’m interested @keats has any suggestions or doesn’t think this is a good idea to begin with.

We could put the title automatically in the built-in template but for meta tags it would need to be a template yes, and zola needs to check whether the correct redirect is present