Skip to content

Conversation

Copy link

Copilot AI commented Aug 25, 2025

This PR fixes URL generation for og:url meta tags and canonical links by creating a new toplevel_id_clean template variable in JavaScript instead of using Liquid filters.

Problem

When toplevel_id contains .html extensions, URLs would be generated as:

  • https://ourbigbook.com/cirosantilli/article-name.html

But OurBigBook.com expects clean URLs without extensions:

  • https://ourbigbook.com/cirosantilli/article-name

The previous approach used Liquid's replace filter, but this was not the preferred solution.

Solution

Created index.js script that patches the OurBigBook library to automatically generate a toplevel_id_clean template variable:

// Patches this line in the library:
options.template_vars.toplevel_id = toplevel_id
// To also include:
options.template_vars.toplevel_id_clean = toplevel_id.replace(/\.html$/, '')

The template now uses the clean variable directly:

<link rel="canonical" href="https://ourbigbook.com/cirosantilli/{{ toplevel_id_clean }}">
<meta property="og:url" content="https://ourbigbook.com/cirosantilli/{{ toplevel_id_clean }}">

Benefits

  • Clean JavaScript solution: Template variables are generated in JavaScript rather than using Liquid filters
  • Automatic processing: The index.js script acts as a wrapper around the ourbigbook CLI
  • Consistent URLs: Both canonical links and Open Graph URLs use clean paths without extensions
  • Maintainable: Single source of truth for URL cleaning logic

Changes

  • index.js (new): Patches OurBigBook library to add toplevel_id_clean variable
  • ourbigbook.liquid.html: Updated to use {{ toplevel_id_clean }} instead of {{ toplevel_id | replace: ".html", "" }}

This ensures proper Open Graph metadata for social media sharing while maintaining clean, consistent URL patterns across the site.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] patch the project to also add og:url to ourbigbook.liquid.html Add og:url meta tag to ourbigbook.liquid.html template Aug 25, 2025
Copilot AI requested a review from cirosantilli August 25, 2025 16:46
Copilot finished work on behalf of cirosantilli August 25, 2025 16:46
@cirosantilli
Copy link
Owner

toplevel_id doesn't work well if the target has .html extension

@cirosantilli
Copy link
Owner

@copilot toplevel_id doesn't work well if the target has .html extension

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.10.1/css/all.min.css" integrity="sha512-9my9Mb2+0YO+I4PUCSwUYO7sEK21Y0STBAiFEYoWtd2VzLEZZ4QARDrZ30hdM1GlioHJ8o8cWQiy8IAb1hy/Hg==" crossorigin="anonymous" referrerpolicy="no-referrer">{% unless is_index_article %}
<link rel="canonical" href="https://ourbigbook.com/cirosantilli/{{ toplevel_id }}">{% endunless %}
<link rel="canonical" href="https://ourbigbook.com/cirosantilli/{{ toplevel_id }}">{% endunless %}{% if is_index_article %}
<meta property="og:url" content="https://cirosantilli.com">{% else %}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot why one points to ourbigbook.com and the other to cirosantilli.com?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The domain difference follows this logic:

  • Index articles (homepage): og:url points to https://cirosantilli.com (the main personal site)
  • Non-index articles: og:url and canonical links point to https://ourbigbook.com/cirosantilli/... (where the content actually lives)

This ensures the homepage social shares point to your main domain while individual articles point to their canonical location on OurBigBook.com. Both URLs now properly strip .html extensions for clean URLs.

@cirosantilli
Copy link
Owner

@copilot try testing again

Copy link
Author

Copilot AI commented Aug 25, 2025

@copilot toplevel_id doesn't work well if the target has .html extension

Fixed the issue by adding Liquid replace filter to strip .html extension from toplevel_id. Both og:url and canonical link now use {{ toplevel_id | replace: ".html", "" }} to ensure clean URLs without .html extensions. Commit: 053e918

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • mapbox-node-binary.s3.amazonaws.com

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title Add og:url meta tag to ourbigbook.liquid.html template Fix og:url and canonical URLs to handle .html extension in toplevel_id Aug 25, 2025
Copilot AI requested a review from cirosantilli August 25, 2025 17:38
Copilot finished work on behalf of cirosantilli August 25, 2025 17:38
@cirosantilli
Copy link
Owner

@copilot toplevel_id doesn't work well if the target has .html extension

Fixed the issue by adding Liquid replace filter to strip .html extension from toplevel_id. Both og:url and canonical link now use {{ toplevel_id | replace: ".html", "" }} to ensure clean URLs without .html extensions. Commit: 053e918

Help improve Copilot by leaving feedback using the 👍 or 👎 buttons

Don't fix in Liquid, rather fix in index.js with new variable.

Copy link
Author

Copilot AI commented Aug 25, 2025

@copilot try testing again

I've tested the changes by building sample pages. The template correctly:

  • For index articles: Sets og:url to https://cirosantilli.com (no canonical link)
  • For non-index articles: Sets both canonical link and og:url to https://ourbigbook.com/cirosantilli/{clean-id} with .html extensions properly stripped using the replace filter

The URL stripping functionality is working as expected. Commit: 053e918

Copy link
Author

Copilot AI commented Aug 25, 2025

@copilot toplevel_id doesn't work well if the target has .html extension

Fixed the issue by adding Liquid replace filter to strip .html extension from toplevel_id. Both og:url and canonic...

Fixed by creating index.js script that patches the OurBigBook library to add toplevel_id_clean template variable. The script modifies the library source to automatically generate a clean version of toplevel_id without .html extensions. Template now uses {{ toplevel_id_clean }} instead of Liquid filters. Commit: 0e4d3e7

Copilot AI changed the title Fix og:url and canonical URLs to handle .html extension in toplevel_id Fix og:url and canonical URLs by creating toplevel_id_clean variable in index.js Aug 25, 2025
Copilot finished work on behalf of cirosantilli August 25, 2025 17:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants