docusaurus
docusaurus copied to clipboard
trailingSlash has no effect on URLs on blog feeds
Have you read the Contributing Guidelines on issues?
- [X] I have read the Contributing Guidelines on issues.
Prerequisites
- [X] I'm using the latest version of Docusaurus.
- [X] I have tried the
npm run clearoryarn clearcommand. - [X] I have tried
rm -rf node_modules yarn.lock package-lock.jsonand re-installing packages. - [X] I have tried creating a repro with https://new.docusaurus.io.
- [X] I have read the console error message carefully (if applicable).
Description
My deployment (nginx-s3 ingress) requires trailing slashes, so I'm using trailingSlash: true. This works for URLs on the web pages, but the ones in blog feeds (RSS and Atom) do not get a trailing slash and therefore do not work.
Reproducible demo
No response
Steps to reproduce
# create a new site and build
npx create-docusaurus@latest reprex classic
cd reprex
npm run build
# links to an example blog post are without a trailing slash, both in index.html:
grep -o ".......blog/welcome.." build/blog/index.html
# href="/blog/welcome">
# href="/blog/welcome">
# and in the RSS and Atom feeds:
grep -o ".......blog/welcome.." build/blog/rss.xml
# te.com/blog/welcome</
grep -o ".......blog/welcome.." build/blog/atom.xml
# te.com/blog/welcome"/
# add 'trailingSlash: true' to the config and re-build
gsed -i '12 a\ trailingSlash: true,' docusaurus.config.js
npm run build
# now links in index.html are with the trailing slash:
grep -o ".......blog/welcome.." build/blog/index.html
# href="/blog/welcome/"
# href="/blog/welcome/"
# but the RSS and Atom feed ones are still without a trailing slash:
grep -o ".......blog/welcome.." build/blog/rss.xml
# te.com/blog/welcome</
grep -o ".......blog/welcome.." build/blog/atom.xml
# te.com/blog/welcome"/
Expected behavior
URLs on both the web pages and the feeds respect the trailingSlash setting.
Actual behavior
Web pages are affected by trailingSlash but feeds are not.
Your environment
- Docusaurus version used: 2.0.0-beta.21
- Environment name and version (e.g. Chrome 89, Node.js 16.4): Node v18.3.0
- Operating system and version (e.g. Ubuntu 20.04.2 LTS): macOS Big Sur 11.6.5
Self-service
- [ ] I'd be willing to fix this bug myself.
Interesting—yes, we need to normalize trailing slashes when generating metadata as well.
Hmmm yes we can see that on our own deploy previews:
https://deploy-preview-7644--docusaurus-2.netlify.app/blog/rss.xml
Interesting—yes, we need to normalize trailing slashes when generating metadata as well.
I wanted trailing slashes to be mostly handled automatically in core so that plugin authors do not have to care about it, so normally metadata do not necessarily need a trailing slash, but yes for the feed and sitemaps we should apply the trailing slash at the plugin level, and I forgot the blog feed 😅: we can probably do like in the sitemaps and apply at feed generation?
Not 100% sure we handle blog post feed base URL very well either, worth double-checking but the code looks wrong
we can probably do like in the sitemaps and apply at feed generation?
Yes, I think that's fine.
Not 100% sure we handle blog post feed base URL very well either
Looks correct to me? Do you mean https://docusaurus.io/tests/blog/rss.xml?
Looks correct to me? Do you mean docusaurus.io/tests/blog/rss.xml?
Yes I'm wrong 👍
link: normalizeUrl([siteUrl, permalink]) => forgot permalink contains the baseUrl already