facebook / docusaurus

Easy to maintain open source documentation websites.
https://docusaurus.io
MIT License
56.89k stars 8.56k forks source link

Blog Atom/RSS feed urls should be absolute instead of relative #9136

Closed gotson closed 1 year ago

gotson commented 1 year ago

Have you read the Contributing Guidelines on issues?

Prerequisites

Description

If a blog post contains internal links, when the blog post is made available via feeds (rss/atom/json), the links should be made absolute, instead of relative.

Here is an example of Json feed from my site:

{
    "version": "https://jsonfeed.org/version/1",
    "title": "Announcements",
    "home_page_url": "https://komga.org/blog",
    "description": "Latest Komga announcements",
    "items": [
        {
            "id": "https://komga.org/blog/prepare-v1",
            "content_html": "<p>The future v1.0.0 will bring some breaking changes, this guide will help you to prepare for the next major version.</p><h2 class=\"anchor anchorWithStickyNavbar_LWe7\" id=\"before-upgrading\">Before upgrading<a href=\"#before-upgrading\" class=\"hash-link\" aria-label=\"Direct link to Before upgrading\" title=\"Direct link to Before upgrading\">​</a></h2><ul><li>If you run Docker, it is advisable to use the <code>0.x</code> tag instead of <code>latest</code>. You will be able to decide when you want to upgrade, especially if you are updating containers automatically.</li><li>Backup your <code>database.sqlite</code>. You can find it in the configuration directory, by default:<ul><li>on Windows: <code>%USERPROFILE%/.komga/database.sqlite</code></li><li>on Unix: <code>~/.komga/database.sqlite</code></li><li>on Docker: in the directory you mounted as <code>/config</code></li></ul></li></ul><h2 class=\"anchor anchorWithStickyNavbar_LWe7\" id=\"breaking-changes\">Breaking changes<a href=\"#breaking-changes\" class=\"hash-link\" aria-label=\"Direct link to Breaking changes\" title=\"Direct link to Breaking changes\">​</a></h2><ul><li>The minimum Java version required will be Java 17:<ul><li>If you run Komga using the <code>jar</code>, you will need to make sure your Java version is sufficient by running <code>java -version</code>.</li><li>If you run Komga using Docker, you don't need to do anything.</li></ul></li><li>The hashing algorithm for files and pages will change. Previous hashes for files and pages will be deleted. On startup, if hashing is enabled, Komga will re-hash files and pages using the new algorithm.</li><li>The default port will be changed from <code>8080</code> to <code>25600</code>:<ul><li>If you use Docker, you will need to update your container or compose configuration to expose the new port.</li><li>You may need to adjust your reverse proxy settings.</li><li>You can still change the port <a href=\"/docs/installation/configuration#server_port--serverport-port\">through configuration</a>.</li></ul></li></ul>",
            "url": "https://komga.org/blog/prepare-v1",
            "title": "Prepare for v1.0.0",
            "summary": "The future v1.0.0 will bring some breaking changes, this guide will help you to prepare for the next major version.",
            "date_modified": "2023-03-21T00:00:00.000Z",
            "author": {
                "name": "gotson",
                "url": "https://github.com/gotson"
            },
            "tags": [
                "breaking change",
                "upgrade",
                "komga"
            ]
        }
    ]
}

And a problematic href: <a href=\"/docs/installation/configuration#server_port--serverport-port\">

The generated feed should instead be generating an absolute link, ie https://komga.org/docs/installation/configuration#server_port--serverport-port

Reproducible demo

No response

Steps to reproduce

  1. go to https://komga.org/blog/feed.json
  2. observe incorrect href

Expected behavior

Absolute links in href

Actual behavior

Relative links in href

Your environment

Self-service

ranjanmangla1 commented 1 year ago

can some one assign me this issue, would love to work on it

Josh-Cena commented 1 year ago

@ranjanmangla1 We don't assign to external contributors. You can simply send a PR.

For some hint: we already have a parsed HTML tree representing the feed item (because we extracted it from the blog's build output). You just need to walk that HTML tree and resolve all URLs with the site's URL.

ranjanmangla1 commented 1 year ago

ok, thank you for the reply and the hint, will send a pr by this evening

slorber commented 1 year ago

If a blog post contains internal links, when the blog post is made available via feeds (rss/atom/json), the links should be made absolute, instead of relative.

Are we sure this is really needed? What is the problem with using relative URLs? Feed readers like Feedly are able to handle that properly and handle that resolution against the feed item URL.

Also if we implemt this, why would we do this only to the links, and not the images and other URL references?

Please explain exactly how using relative URLs have been a problem for you in practice, or share a link to a reference site that say it's bad to use relative URLs


Edit: found a ref recommending absolute URLs: https://validator.w3.org/feed/docs/warning/ContainsRelRef.html

Relative urls are probably supported by most RSS readers but maybe not all, so ok to implement this 👍 But we also need to handle the image urls.

Curious: your RSS reader doesn't support relative urls? which one is it?

We have a few RSS errors reported here: https://validator.w3.org/feed/check.cgi?url=https%3A%2F%2Fdocusaurus.io%2Fblog%2Frss.xml

gotson commented 1 year ago

Curious: your RSS reader doesn't support relative urls? which one is it?

i don't use a RSS reader. I consume the feed.json in a custom application.

But we also need to handle the image urls.

agreed, i wanted to update this issue but you've been faster than me :-)