def canonical_url(app, pagename, templatename, context, doctree):
    """Build the canonical URL for a page. Appends the path for the
    page to the base URL specified by the
    ``html_context["canonical_url"]`` config and stores it in
    ``html_context["page_canonical_url"]``.
    """
    base = context.get("canonical_url")

    if not base:
        return

    target = app.builder.get_target_uri(pagename)
    context["page_canonical_url"] = base + target
Build the canonical URL for a page. Appends the path for the
    page to the base URL specified by the
    ``html_context["canonical_url"]`` config and stores it in
    ``html_context["page_canonical_url"]``.