Static Index w/ Separate /blog?

Hello! I’d like to create a theme/layout + site that has a “static” front page with content controlled by an index.md in my /content folder, and then has a /content/blog folder with my blog posts, with an index at http://mysite.com/blog/, URLs like http://mysite.com/blog/my-post/, and still has an RSS on the home page that points to blog pages. Is this possible? I can’t seem to find a good example of this layout.

This is very possible and very easy to do right out of the box. I can’t example everything you’ll need to do in this post since that’s what the docs are for, but this will give you an idea of the source organization you’ll need…

.
├── content
│   ├── _index.md
│   └── blog
│       ├── my-first-post.md
│       └── my-second-post.md
└── layouts
    ├── _default
    └── index.html

You’ll also need layouts, etc, obviously…

But index.html will pull content and front matter from _index.md plus whatever templating you put in.

I would recommend doing the Quick Start since it does more or less exactly what you’re looking to do. Also hugo new will scaffold all the directory structure you need…

HTH.

@rdwatters Thanks for the reply! This was actually quite helpful.

The only thing I’m stuck with is that I’d like to have my /index.xml RSS be my blog posts only, and perhaps avoid generating /blog/index.xml. Is this possible?

To a degree, yes…

https://gohugo.io/templates/rss/

@rdwatters I had looked at that, and I can imaging creating my own index.xml that will only index the /blog/ section, but am I stuck with /blog/index.xml always being generated?

Hmm…my guess would be a blank file at…/layouts/section/SECTION.rss.xml per the docs, but I’m also guessing this will just create blank .xml files, and to my knowledge, there is no way to avoid certain pages from being created altogether…

I’m typing this in the middle of a workday, however, so I can’t test. That said, this would be very easy to remove as part of a build script, depending on where you’re hosting the site and how you’re currently deploying…

1 Like

Ok, this makes sense, and I guess I’d rather have the files generated than be blank.

I’m building this locally, but it’ll be hosted using Netlify, so the deploy script can be any options that can be passed to the hugo command, possibly more.

When you’re ready to deploy, let me know if you need help…Netlify makes this even easier through their UI. It’s just a BASH one-liner.

I love that they offer environmental variables too :smile:

Just an update. I’ve got a /index.xml that’s as follows:

<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>{{ if eq  .Title  .Site.Title }}{{ .Site.Title }}{{ else }}{{ with .Title }}{{.}} on {{ end }}{{ .Site.Title }}{{ end }}</title>
    <link>{{ .Permalink }}</link>
    <description>Recent content {{ if ne  .Title  .Site.Title }}{{ with .Title }}in {{.}} {{ end }}{{ end }}on {{ .Site.Title }}</description>
    <generator>Hugo -- gohugo.io</generator>{{ with .Site.LanguageCode }}
    <language>{{.}}</language>{{end}}{{ with .Site.Author.email }}
    <managingEditor>{{.}}{{ with $.Site.Author.name }} ({{.}}){{end}}</managingEditor>{{end}}{{ with .Site.Author.email }}
    <webMaster>{{.}}{{ with $.Site.Author.name }} ({{.}}){{end}}</webMaster>{{end}}{{ with .Site.Copyright }}
    <copyright>{{.}}</copyright>{{end}}{{ if not .Date.IsZero }}
    <lastBuildDate>{{ .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}</lastBuildDate>{{ end }}
    <atom:link href="{{.Permalink}}" rel="self" type="application/rss+xml" />
    {{ range where .Data.Pages "Section" "blog" }}
    <item>
      <title>{{ .Title }}</title>
      <link>{{ .Permalink }}</link>
      <pubDate>{{ .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}</pubDate>
      {{ with .Site.Author.email }}<author>{{.}}{{ with $.Site.Author.name }} ({{.}}){{end}}</author>{{end}}
      <guid>{{ .Permalink }}</guid>
      <description>{{ .Content | html }}</description>
    </item>
    {{ end }}
  </channel>
</rss>

I have some pages, such as /content/colophon.md that I (perhaps obviously) don’t want showing up in my “blog” feed at /index.xml. That’s why I’ve specified {{ range where .Data.Pages "Section" "blog" }}.

However, all pages still show up in my index.xml, both something like /content/colophon.md as well as /content/blog/my-post.md. Any ideas?

Any ideas?

@codydh Just curious, why are you declaring an Atom namespace inside an RSS feed?

Also, this feels cleaner maybe?

<title>{{if not .IsHome}}{{.Title}} on {{end}}{{.Site.Title}}</title>

I copied this from an example somewhere, and didn’t catch that.

Still unclear why I can’t have a feed that’s just my posts, and not my pages, though.

@codydh Gotcha. Where are you putting this within your project source organization?

It is located in /layouts/index.xml—so presumably {{range where .Data.Pages "Section" "blog" }} should be capturing the content in /content/blog/ only, but it’s also capturing /content/cv.md, for example.

@codydh Haven’t tested since I’m on the road for work, but have you checked the lookup order for RSS?

https://hugodocs.info/templates/rss/#rss-template-lookup-order