Displaying the Full Content in Hugo's RSS feed
Tags: hugo, rss
Published: 2020-07-04 02:14:25

---
title: Displaying the Full Content in Hugo's RSS feed
published: true
date: 2020-07-03 01:53:38 UTC
tags: hugo, rss
canonical_url: https://bemnlam.github.io/posts/displaying-the-full-content-in-hugo-rss-feed/
cover_image: https://bemnlam.github.io/img/displaying-the-full-content-in-hugo-rss-feed/cover-images/cover-images.001.png
---

## Background

Recently I created a hugo blog and started writing articles. Later, I found that dev.to can [publish articles (as draft) from a RSS feed](https://dev.to/settings/publishing-from-rss). In that way I don’t have to copy-and-paste my articles manually in order to publish the same item on dev.to!

<aside>
  <details open>
    <summary title="click to toggle table of contents.">Table of Contents</summary>
    <nav id="TableOfContents">
  <ul>
    <li><a href="#problem">😨 Problem</a></li>
    <li>
<a href="#solution">😀 Solution</a>
      <ul>
        <li><a href="#locating-rssxml">Locating <code>rss.xml</code></a></li>
        <li><a href="#rendering-the-full-content">Rendering the full content</a></li>
        <li><a href="#regenerating-the-site">Regenerating the site</a></li>
      </ul>
    </li>
    <li><a href="#bonus">Bonus: The difference between `{{` and `{{-` in Hugo</a></li>
    <li><a href="#conclusion">Conclusion</a></li>
  </ul>
</nav>
  </details>
</aside>

## 😨 Problem

Although dev.to’s puslishing from RSS feed service is great, my Hugo site is not that great (with the basic settings). **When I was trying to sync my RSS feed items to dev.to, all items can be imported but only the beginning part of the content was fetched.**

I know that should be something wrong with the RSS feeds generated by Hugo. The [default Hugo RSS template](https://github.com/gohugoio/hugo/blob/master/tpl/tplimpl/embedded/templates/_default/rss.xml) only renders `Summary` of an article and my Hugo theme is using that:

{% gist https://gist.github.com/bemnlam/83b253aef5526c30ca5535c72bd861cc %}

As you can see in **line 73** , the [`<description>`](https://validator.w3.org/feed/docs/rss2.html) in my RSS feeds contain article summary only but not the full content. Is there any ways to change the `Summary` here into something else? Something else that represents the **full content**?

## 😀 Solution

### Locating `rss.xml` <a name="locating-rssxml"></a>

Usually, Hugo templates are placed under `{your hugo theme}/layouts/_defualt/`. If such file does not exist, it’s time to create one. You can copy-and-paste the code from [Hugo’s github](https://github.com/gohugoio/hugo/blob/master/tpl/tplimpl/embedded/templates/_default/rss.xml) or run the following `curl` command under `/layouts/_default` to download it:

```bash
curl "https://raw.githubusercontent.com/gohugoio/hugo/master/tpl/tplimpl/embedded/templates/_default/rss.xml" > rss.xml
```

### Rendering the full content

Rendering the full content of is really simple and straight-forward. What you need to do is just replacing this:

```html
<description>{{ .Summary | html }}</description>
```

With this:

```html
<description>{{- .Content | html -}}</description>
```

Caution: use `{{-` instead of `{{`. Read [the bonus part](#bonus-the-difference-between--and---in-hugo) if you want to know what is the difference.

### Regenerating the site

Updating the RSS template **will not** update your **generated content** automatically. Therefore, you need to re-generate your Hugo site:

```bash
hugo
```

You should see the changes in all RSS xml files (from git). After that, push all the code changes, remove all the fetched posts in dev.to and re-fetch them. That’s it.

<a name="bonus"></a>

## Bonus: The difference between `{{` and `{{-` in Hugo

You may notice that the template code is changed into `{{-` from `{{`. As a newbie in Hugo I checked [the Hugo’s official documentation about _whitespace_](https://gohugo.io/templates/introduction/#whitespace).

> … the ability to trim the whitespace from either side of a Go tag …

This `-` notation is introduced in Go 1.6.

The following example (from the documentation):

```html
<div>
  {{ .Title }}
</div>
<div>
  {{- .Title -}}
</div>
```

Which will output:

```html
<div>
  Hello, World!
</div>
<div>Hello, World!</div>
```


## Conclusion

The default RSS feed in Hugo site shows _article abstract_ only. By defining a custom `rss.xml` template and replacing `{{ .Summary | html }}` with `{{- .Content | html -}}` in the `<description>` tag you will get the article’s full content in the re-generated RSS xml files.