Meta data for categories

Hi there. Coming from a hosted wordpress site that held my hand through out blogging, I’m about 2 weeks into self learning html, css and chose to throw in a ssg at same time. After hitting some ouch! moments I have built myself a hugo site from the ground up. Let’s just say I think the hugo docs could do with some more examples.

What I am trying to achieve is some automation in the creation of the categories list page where each category has an image and a description. A bonus would be for a post that doesn’t have an image defined in the frontmatter, use the image of the first listed category.

This is beyond my abilities and I am at a lost as to were to start so I am looking at a strong nudge in the right direction.

currently I’m using git pages while develop my site.
https://mikewebbtech.github.io/mikewebb-tech/

and the repo for my hugo site
https://github.com/mikewebbtech/mikewebbtech-hugo
Any other feedback would be great, trying to learn. My todo list of things is getting longer the more I work on my todo list

oh wow, thanks. OK, dont know what happened there. I’ve fixed the link to the repo on my post

https://github.com/mikewebbtech/mikewebbtech-hugo

Where’s the content?

ah yes. had content in .gitignore. still working out how best to handle the sepperation of content and hugo. I’ll remove it from the ignore and push. There is no real content in yet.

To add meta data to taxonomy and term pages…

content/
├── categories/
│   ├── automation/
│   │   ├── _index.md
│   │   └── image.jpg
│   ├── _index.md
│   └── image.jpg
└── _index.md

content/categories/_index.md

+++
title = 'Categories'
+++

This is a description of the "categories" taxonomy.

content/categories/automation/_index.md

+++
title = 'Automation'
+++

This is a description of the "automation" category.

I remeber coming across that somewhere else, maybe on these community pages, and it did not work for me.

Did as you sugggested and it still did not work for me. So I must be missing something here. Do I need to make additions somehow in my list and category layout pages to reference these new _index.md pages?

The templates for your taxonomy and term pages need to:

  1. Render the content

    {{ .Content }}
    
  2. Render the image

    {{ with .Resources.Get "image.jpg" }}
      {{ with .Process "resize 300x webp" }}
        <img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}" alt="">
      {{ end }}
    {{ end }}
    

Nice. Yes that did the job. thanks.

I am trying to apply the same to my second goal and I getting a fail



 render: failed to render pages: render of "/Users/mike/Projects/mikewebbtech-hugo/content/categories/_index.md" failed: "/Users/mike/Projects/mikewebbtech-hugo/layouts/categories/terms.html:15:16": execute of template failed at <.Coneent>: can’t evaluate field Conetent in type page.OrderedTaxonomyEntry 

/Users/mike/Projects/mikewebbtech-hugo/layouts/categories/terms.html:15:16:

    <li class="tags-list-item">
      <div>
        {{ with .Content }} {{ . }} {{ end }}
        <a class="tags-list-item-title" href="{{ .Page.RelPermalink }}">
          {{ .Page.Title }}

I’ll dive into this more tomorrow. is this a context issue?

edit: and nice one with

  {{ with .Process "resize 300x webp" }}

image processing is next on the list once I get my catagory feature working

The error message says that you misspelled content.

Cheers got it working the way I like. Your guidence got me the description and image showing on the pages for category and for the categories.

To get the individual category description and image to show for each category list item, I had to apply {{ .Page.Content }} etc, in my list item after my {{ range .Data.Terms.Alphabetical }} in /layouts/categories/terms.html.

Got a few new niggles to sort then I’ll merge with main and push

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.