I have a question about using Content Adapters with off-the-shelf themes, but first, a short preamble:
In this post, I’m assuming there are two kinds of Hugo users: “Markdown Users,” who are folks who know they can produce great looking websites by writing Markdown files and selecting one of the many excellent themes that exist for Hugo; and “Power Users”, who are folks who maintain public themes or write their own custom theme. Although I have been using Hugo for nearly 10 years, I’ve almost exclusively been the first kind of Hugo user.
I was really excited to read about Content Adapters last year. But after reading the docs I concluded I’d need to know how to write Hugo templates, so I had to put off my plans to use Content Adapters until I had more time.
Then, I recently came across Content adapters: using local data on this support site and I started thinking, maybe it is possible to use Content Adapaters with an off-the-shelf theme.
At GitHub - odoublewen/hugo-theme-with-content-adapter-poc you can see my ultra-simple effort to create a Hugo site using the excellent PaperMod theme.
There are two pages: one generated from content/fowl/ducks.md
:
---
title: 'Ducks'
date: '2025-02-20T13:17:48-08:00'
draft: false
cover:
image: "/images/duck.jpg"
caption: "Quack Quack"
---
Ducks have **short** necks.
…and one generated from content/fowl/_content.gotmpl
:
{{ range .Site.Data.fowl }}
{{/* Add page. */}}
{{ $content := dict "mediaType" "text/markdown" "value" .content }}
{{ $img := fmt.Printf "/images/%s" .image }}
{{ $cover := dict "image" $img "caption" .title }}
{{ $path := urls.URLize .title }}
{{ $page := dict
"title" .title
"date" .date
"draft" .draft
"path" $path
"content" $content
"cover" $cover
}}
{{ $.AddPage $page }}
{{/* page resource stuff here? */}}
{{ end }}
…and data/fowl.yaml
as data source:
- title: 'Geese'
date: '2025-02-20T13:28:01-08:00'
draft: false
image: 'goose.jpg'
caption: 'Honk Honk'
content: 'Geese have **long** necks.'
It seemed like that should work, since the $page
map mirrors the markdown frontmatter. As you can see in the README, I got pretty close, but two thing are missing in the content-adpater-generated page (which both work in the markdown-generate page):
- The date
- The cover image
I think I get lost trying to understand what things need to go into the $page
dict and what is a page resource?
From the docs, it looks like I should use dates.date
instead of just date
, but when I tried that, I still don’t get a date in the post.
Any help much appreciated! I feel like a worked example using an off-the-shelf theme could really help a broader audience (aka the “Markdown Users”) make use of Content Adapters. When I get it working, I’m happy to leave my repo up as an example.