theNewDynamic / gohugo-theme-ananke

Ananke: A theme for Hugo Sites
https://gohugo-ananke-theme-demo.netlify.com/
MIT License
1.1k stars 1.13k forks source link

Improve links for sitemap and taxonomies #569

Closed jhenstridge closed 1 year ago

jhenstridge commented 1 year ago

This PR makes a few changes to improve the links generated by the theme templates:

  1. use absURL to create the sitemap URL rather than concatenating with .Site.BaseURL. This avoids a non-canonical URL if BaseURL ends in a slash.
  2. use .GetTerms to get a list of the tags for the page. This returns a list of page objects that know their URL.
  3. use .Data.Pages to enumerate the terms in a taxonomy rather than .Data.Terms. Again, this lets Hugo generate the appropriate URL.

I noticed (2) and (3) in a Google search console report for my site, where the existing templates generate links without a trailing slash, resulting in a redirect. Letting Hugo generate the links itself avoids the problem. It also seems to work correctly with multi-lingual sites, after clicking around in the example site.

To test the example site, I modified its go.mod file to force it to use the in-tree version of the theme rather than downloading a second copy of the theme (which won't include any of the changes I'm trying to test). Looking at the git history, it seems the example site used to do this but it was reverted for some reason in ddf6a834. It's not clear from the commit message why that was done.

netlify[bot] commented 1 year ago

Deploy Preview for gohugo-ananke-theme-demo ready!

Name Link
Latest commit d44b79ef32029b488463267ec28d6a618f13ae0e
Latest deploy log https://app.netlify.com/sites/gohugo-ananke-theme-demo/deploys/6317fa7def879c0008f615c5
Deploy Preview https://deploy-preview-569--gohugo-ananke-theme-demo.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

regisphilibert commented 1 year ago

Looking at the git history, it seems the example site used to do this but it was reverted for some reason in https://github.com/theNewDynamic/gohugo-theme-ananke/commit/ddf6a834054bf08e773ffd26599a1b23af16e2e5. It's not clear from the commit message why that was done.

We have been trying to move the demo site to cloudflare but it breaks on the replace line...

I added it back as we are still using Netlify anyway. (you might have to fix the conflict I just introduced by fixing master :/)

jhenstridge commented 1 year ago

I've rebased the PR on current master, removing the revision altering the example site go.mod file.