Skip to content

yelosan/hugo-feeds

 
 

Repository files navigation

Atom and RSS2 feed for Hugo

This Hugo module adds Atom feed support, and provides an update to the default RSS feed.

Repository, suggestions, issues, pull requests

We use Codeberg for development, suggestions, issues, and pull requests.

Mirrors

Note: These mirrors should not be used as a Hugo module as it will produce a GoLang module error. The go.mod ID is set to codeberg.org/yelosan/hugo-feeds which should match the URL Hugo/GoLang is fetching it from.

Installation

Step 1: Add/download the module

Method A: As a Hugo module

  1. In your config file, add the following:

TOML

[module]
  [[module.imports]]
    path = "codeberg.org/yelosan/hugo-feeds"

YAML

module:
  imports:
    - path: codeberg.org/yelosan/hugo-feeds

JSON

{
  "module": {
    "imports": [
      {
        "path": "codeberg.org/yelosan/hugo-feeds"
      }
    ]
  }
}
  1. Initialize the Hugo Feeds module
hugo mod init codeberg.org/yelosan/hugo-feeds
To update

To update the Hugo Feeds module, run this command while in your project's root directory: hugo mod get -u codeberg.org/yelosan/hugo-feeds

Method B: git submodule

  1. In your project's root directory, run the following command
 git submodule add https://codeberg.org/yelosan/hugo-feeds themes/hugo-feeds
  1. Initialize the Hugo Feeds submodule
git submodule update --init --recursive themes/hugo-feeds
To update

While in your project's root directory, run this command: git submodule update --init --recursive themes/hugo-feeds

Method C: git clone

  1. In your project's root directory, run
git clone https://codeberg.org/yelosan/hugo-feeds themes/hugo-feeds
To update

In the Hugo Feeds subdirectory (cd themes/hugo-feeds), run this command: git pull

Method D: download

  1. Download the main branch, or tag of your choice, here.
  2. Extract the file in your project's /themes/ subdirectory. It should be in /themes/hugo-feeds/ after extracting.
To update
  1. Check the project's repository regularly for updates.
  2. Download the main branch, or tag of your choice, here.
  3. If you did not modify any of the Hugo Feeds files, delete the /hugo-feeds/ subdirectory located in your project's /themes/ subdirectory.
  4. Extract the latest release in your project's /themes/ subdirectory. It should look like this after extracting: /themes/hugo-feeds/.

Step 2: config file settings

  1. Add "ATOM" to all the Page Kinds you want to generate an Atom feed.xml

TOML

[outputs]
  # <domain>/feed.xml
  home = ["HTML", "ATOM", "RSS"]
  # <domain>/posts/feed.xml
  section = ["HTML", "ATOM", "RSS"]
  # <domain>/tags/mytag/feed.xml; <domain>/categories/mycat/feed.xml
  taxonomy = ["HTML", "ATOM", "RSS"]

YAML

outputs:
  home:
    - HTML
    - ATOM
    - RSS
  section:
    - HTML
    - ATOM
    - RSS
  taxonomy:
    - HTML
    - ATOM
    - RSS

JSON

{
  "outputs": {
    "home": ["HTML", "ATOM", "RSS"],
    "section": ["HTML", "ATOM", "RSS"],
    "taxonomy": ["HTML", "ATOM", "RSS"]
  }
}
  1. Extra step for Methods B, C, and D.

Add this in your config file

TOML

theme = ["hugo-feeds", "your-theme"]

YAML

theme:
  - hugo-feeds
  - your-theme

JSON

{
  "theme": ["hugo-feeds", "your-theme"]
}

Pay attention to web server MIME type

To fully comply with web standards, make sure your web server sends the correct /Content-Type/ HTTP response header for the feed file name feed.xml. The correct response header looks like this: Content-Type: application/atom+xml; charset=UTF-8

Note that even though the feed file extension is .xml, the MIME type is slightly adjusted from application/xml to application/atom+xml.

While this might not be important for many feed readers, it could still be a source of error. It is a good practice to be compliant with the web standards, and avoid potential errors. Please consult the documentation of your web hosting provider, or web server software, on how to set the correct MIME type.

Specifying the correct "Content-Type" for Netlify

You can specify the /Content-Type/ of feed.xml and *.atom files to be application/atom+xml; charset=UTF-8 by adding this in your site's netlify.toml:

[[headers]]
  for = "feed.xml"
  [headers.values]
    Content-Type = "application/atom+xml; charset=UTF-8"
[[headers]]
  for = "*.atom"
  [headers.values]
    Content-Type = "application/atom+xml; charset=UTF-8"

RSS2

The Hugo Feeds module also contain an override template for the RSS feed. This version matches what is available in the Atom feed, where possible. RSS is enabled by default in Hugo, and the default file name is index.xml. Simply ensure you have not disabled RSS in your project (check your config file).

References

Attributions

Based on / forked from: