TIL (from Claude) how to create separate RSS feeds for my hugo blog
⋅ 9 minute read
I really like the idea of providing different content types of my blog in separate RSS feeds. For example a blog could have:
- essays
- today-I-learned posts
- link-list or bloglink posts
- short social media style posts
- etc.
Providing different RSS feeds for them allows my readers to subscribe to all or a subset of these, depending on their interest. I am using hugo, as the static site generator for this website. Setting up these dfferent feeds for a framework that I am only partially familar with is a great use-case to work with an LLM.
I knew that I would need to:
- Distinguish different content types with a flag
- Specify different RSS templates that filter on these flags
- Tell hugo to generate separate xml files for each content type and use the right templates.
I just didn’t know how to piece these parts together. I first tried googling the answer and read the typical mix of
- stackoverflow posts that were not solving the exact same problem
- hugo forum discussions that did not have a clear solution or where the solution wasn’t transferable to my unique setup.
I think with those first pointers, spending some time on the hugo documentation, and trial-and-erroring, I could have worked out how to do it. I think that these shallow but unknown problems are the ideal use case for an LLM.
I think of using LLMs as an interface for search + context, where I don’t have to take the laborious work of pre-filtering and connecting the sources. Instead, it helps me get a quick overview and a potential draft of a solution. I can then go deeper and understand the problem better by asking about parts of the solution that I don’t understand. I can then mix this with more googling and get to a solution.
My Goal:
I have a hugo blog with the following folder structure:
/content/posts/post1.md
/content/posts/post2.md
/content/posts/_index.md
/content/til/_index.md
/content/til/til1.md
/content/til/til2.md
Markdown pages written in the posts subfolder have type: post in the frontmatter and pages written in the til subfolder have type: til in the submatter.
Explain to me step by step how I can create three separate rss feeds on my website.
-
Only showing content coming from the til subfolder on til.xml
-
Only showing content coming from the post subfolder posts.xml
-
One showing everything on index.xml
Solution
Claude Sonnet 3.5 - Response
I’d be happy to explain how you can create three separate RSS feeds for your Hugo blog with the structure you’ve described. Let’s go through this step-by-step:
- Create RSS template files: First, you’ll need to create three separate RSS template files in your Hugo project’s layouts folder.
Now, let me explain each step in more detail:
-
We create three separate RSS template files in the
layouts/_default/
directory. Each file corresponds to one of the RSS feeds you want to create. -
In each RSS template, we use Hugo’s templating language to generate the RSS feed. The main difference between the templates is in the range statement:
- For
til.xml
, we use{{ range where .Site.RegularPages "Type" "til" }}
- For
posts.xml
, we use{{ range where .Site.RegularPages "Type" "post" }}
- For
index.xml
, we use{{ range .Site.RegularPages }}
to include all content
- For
-
We update the Hugo configuration file to define new output formats for TIL and Posts, and to include these new formats in the home page outputs.
-
We add links to the new RSS feeds in the site’s HTML, typically in the
<head>
section or footer. -
Finally, we build the site to generate the new RSS feed files.
After following these steps, your Hugo site will generate three separate RSS feeds:
til.xml
will only include content from thetil
subfolderposts.xml
will only include content from theposts
subfolderindex.xml
will include all content
Would you like me to explain any part of this process in more detail?
I followed these steps, except for using my already existing xml template for til.xml
, posts.xml
, index.xml
. I already read in some hugo discussions that I need to add [outputs]
and [outputFormats]
to my hugo config.toml
file. However, I didn’t really understand the difference between home, page, section and what exactly home = ["HTML", "RSS", "JSON", "TIL", "POSTS"]
does.
So I asked for clarification:
Can you explain to me the config [outputs] and its purpose as well as [outputFormats]?
Claude Sonnet 3.5 - Response
Certainly! I’d be happy to explain the [outputs]
and [outputFormats]
configurations in Hugo and their purposes.
Now, let me provide a more detailed explanation of these configurations:
[outputs]
: This configuration section determines what types of files Hugo will generate for different types of pages on your site. In our case, we’re telling Hugo to generate additional output formats for the home page. The linehome = ["HTML", "RSS", "TIL", "POSTS"]
means:
- For the home page, generate the standard HTML and RSS outputs
- Also generate our custom TIL and POSTS outputs This is crucial for creating our multiple RSS feeds, as it instructs Hugo to actually generate these files when building the site.
[outputFormats]
: This section allows you to define new output formats or modify existing ones. In our case, we’re defining two new output formats: TIL and POSTS. For each new format, we specify:
mediaType
: This tells Hugo what kind of content this is. We’re using “application/rss+xml” because we’re creating RSS feeds.baseName
: This determines the filename of the output file. For example,baseName = "til"
will result in a file namedtil.xml
.
By defining these custom output formats, we’re giving Hugo the information it needs to generate our specialized RSS feeds.
The interaction between these two configuration sections is key:
[outputFormats]
defines what the TIL and POSTS formats are[outputs]
tells Hugo to actually generate these formats for the home page
This setup allows you to have fine-grained control over what files Hugo generates and how they’re named, which is exactly what we need to create multiple, specialized RSS feeds. Is there any part of this you’d like me to elaborate on further?
This helped but I still didn’t really get why I would have to add this to home
and not page
because I thought that I want to generate rss for page-types.
What’s the difference between adding TIL and POSTS to home instead of page?
Claude Sonnet 3.5 - Response
That’s an excellent question! The difference between adding output formats to home
versus page
in Hugo’s configuration is quite significant and affects how and where these outputs are generated. Let me explain:
Now, let me elaborate on the key points:
-
Scope and Purpose:
- Adding TIL and POSTS to
home
creates site-wide RSS feeds that include all relevant content from across your site. This is ideal for your use case of creating separate feeds for TIL entries and blog posts. - If you added these to
page
, it would create individual RSS feeds for each content page, which is not what you’re aiming for.
- Adding TIL and POSTS to
-
Number of Files Generated:
- With
home
, you get onetil.xml
and oneposts.xml
file for your entire site. - If you used
page
, you’d get atil.xml
andposts.xml
for every single page on your site, which would be unnecessary and potentially confusing.
- With
-
Content Aggregation:
- The
home
outputs can access and aggregate content from across your entire site, which is perfect for creating comprehensive RSS feeds. page
outputs typically only contain information from that specific page.
- The
-
Location of Generated Files:
home
outputs are usually placed at the root of your site, making them easy to find and link to (e.g.,https://yoursite.com/til.xml
).page
outputs would be scattered throughout your site structure, mirroring your content organization.
-
Practical Implementation:
- For your RSS feeds, using
home
allows you to create the three distinct feeds you want (TIL, posts, and everything) in a clean, organized manner. - Using
page
for this purpose would be impractical and wouldn’t achieve your goal of separate, comprehensive feeds.
- For your RSS feeds, using
In summary, for your specific need of creating site-wide RSS feeds for different content types, adding TIL and POSTS to the home
outputs is the correct approach. It generates the feeds at the site level, includes all relevant content, and produces a single file for each feed type, which is exactly what you’re looking to achieve.
I followed the suggested approach and added to my config.toml
:
1# I want to top-level output html, rss, and my two custom outputs
2[outputs]
3 home = ["html", "rss", "til", "post"]
4
5# Here I define how to process these custom feeds
6[outputFormats.til]
7 mediaType = "application/rss+xml"
8 baseName = "til"
9
10[outputFormats.post]
11 mediaType = "application/rss+xml"
12 baseName = "posts"
Then I built the page and hugo would build three different xml files:
public/index.xml
public/posts.xml
public/til.xml
However, the files all had the same content as if they were built from the same template instead of the individual templates that filter by page type.
This generates the three xml files but they all seem to use the same template file
Claude Sonnet 3.5 - Response
I apologize for the confusion in my previous explanation. You’re right to point out that issue. Let’s correct this and explain how to properly set up distinct templates for each RSS feed.
Now, let me explain the key changes and why they solve the problem:
-
Template File Naming: The crucial change is in how we name and place the template files. Instead of putting them in
layouts/_default/
, we’re now creating:layouts/index.til.xml
layouts/index.posts.xml
layouts/index.xml
This naming convention is important because Hugo uses it to match the output formats we defined in the configuration.
-
Template Content: The content of each template remains largely the same, but we’ve made sure that each one is filtering for the correct content type:
index.til.xml
uses{{ range where .Site.RegularPages "Type" "til" }}
index.posts.xml
uses{{ range where .Site.RegularPages "Type" "post" }}
index.xml
continues to use{{ range .Site.RegularPages }}
for all content
-
Configuration: The configuration in
config.toml
remains the same as before. The[outputFormats]
and[outputs]
sections are correctly set up to generate these files. -
How It Works:
- When Hugo sees
TIL
in the[outputs]
section, it looks for a template namedindex.til.xml
- Similarly, for
POSTS
, it looks forindex.posts.xml
- The default RSS output uses
index.xml
- When Hugo sees
This setup ensures that each RSS feed uses its own template, allowing you to customize the content for each feed independently.
The reason your previous attempt generated three XML files with the same content was likely because Hugo was falling back to a default RSS template when it couldn’t find specific templates for TIL and POSTS.
With these changes, you should now have three distinct RSS feeds, each with its appropriate content. Does this explanation help clarify the issue? Would you like me to elaborate on any part of this solution?
So I moved the template layout files as suggested to:
layouts/index.til.xml
layouts/index.posts.xml
layouts/index.xml
and they were correctly selected. You can find the correct feeds here:
https://staticnotes.org/index.xml
https://staticnotes.org/posts.xml
https://staticnotes.org/til.xml
Conclusion
A common criticism is that LLMs will confidently hallucinate incorrect information. I think this will likely be true for the next couple of years. However, when I use the old-school google + stackoverflow + documentation + online discussion workflow I also might generate an incorrect approach. This can happen because I misunderstand the content or because I can’t piece the information from different sources correctly together for my use case.
I think viewing an LLM as an interactive interface to search and combine information and context is the right mental model to use them productively.
If you have any thoughts, questions, or feedback about this post, I would love to hear it. Please reach out to me via email.