Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ feat(header): add support for canonical URLs #168

Merged
merged 1 commit into from
Sep 18, 2023

Conversation

welpo
Copy link
Owner

@welpo welpo commented Sep 18, 2023

Description

This PR enhances tabi's SEO capabilities by introducing a flexible system for setting canonical URLs.

The feature allows for setting canonical URLs at individual page or section levels, with a fallback to a dynamically generated global base_canonical_url, if specified.

Resolves #151.

Changes

  • Added canonical_url as an optional front matter attribute in both pages and sections under the [extra] section.
  • Introduced a dynamic fallback mechanism that crafts the canonical URL by replacing the $base_url in the current URL with the base_canonical_url specified in config.toml.
  • Updated HTML templates to conditionally include <link rel="canonical"> and <meta property="og:url"> based on the newly introduced logic.

How to Test

  1. Add canonical_url to the [extra] section of a page or section's front matter.
    [extra]
    canonical_url = "https://example.com/custom-canonical-url"
  2. Alternatively, set a dynamic global base_canonical_url in config.toml.
    base_canonical_url = "https://example.com"
  3. Build the site and verify that the canonical URLs in the HTML headers are set as expected.

Additional Information

This feature is beneficial for those running multiple domains with the same content. By setting base_canonical_url dynamically, it will automatically adapt the canonical URLs based on the current URL's $base_url. For example, for a page with URL $base_url/blog/post1, and a base_canonical_url set to "https://example.com", the generated canonical URL will be "https://example.com/blog/post1".

@welpo welpo added the enhancement New feature or request label Sep 18, 2023
@welpo welpo linked an issue Sep 18, 2023 that may be closed by this pull request
@welpo welpo merged commit 88cc68f into main Sep 18, 2023
1 check passed
@welpo welpo deleted the feat/custom-canonical-url branch September 18, 2023 20:11
Smtbook pushed a commit to Smtbook/zola-theme-tabi that referenced this pull request Feb 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Option to specify canonical url
1 participant