kaushalmodi / hugo-atom-feed

Hugo theme component for ATOM feed custom Output Format
GNU General Public License v3.0
39 stars 13 forks source link

Correct taxonomy declaration in category #20

Closed jpawlowski closed 4 months ago

jpawlowski commented 4 years ago

Based on this, this and my RSS derivate of this feed template, I believe that the category should reflect the taxonomy type in a different scheme.

A URI does not necessarily mean that it is a real URL / internet address (URI != URL, but URL = URI :-)).

stefanv commented 3 years ago

I can confirm that this patch brings us closer to a correct rendering.

I also needed to add:

                        {{ if not (reflect.IsSlice $taxo_list) }}                                                                                                        
                          {{ $taxo_list = slice $taxo_list }}                                                                                                            
                        {{ end }}

to ensure that taxo_list was, in fact, a list. Sometimes (for categories), it comes in as a string.

stefanv commented 4 months ago

Here's the full patch I had to apply:

diff --git a/layouts/_default/list.atom.xml b/layouts/_default/list.atom.xml
index 69e361e..6bf08ae 100644
--- a/layouts/_default/list.atom.xml
+++ b/layouts/_default/list.atom.xml
@@ -104,12 +104,15 @@
             {{ printf `<content type="html"><![CDATA[%s%s]]></content>` $description .Content | safeHTML }}
             {{ with site.Taxonomies }}
                 {{ range $taxo,$_ := . }} <!-- Defaults taxos: "tags", "categories" -->
-                    {{ with $page.Param $taxo }}
+                {{ with $page.Param $taxo }}
                         {{ $taxo_list := . }} <!-- $taxo_list will be the tags/categories list -->
+                        {{ if not (reflect.IsSlice $taxo_list) }}
+                          {{ $taxo_list = slice $taxo_list }}
+                        {{ end }}
                         {{ with site.GetPage (printf "/%s" $taxo) }}
                             {{ $taxonomy_page := . }}
                             {{ range $taxo_list }} <!-- Below, assuming pretty URLs -->
-                                <category scheme="{{ printf "%s%s" $taxonomy_page.Permalink (. | urlize) }}" term="{{ (. | urlize) }}" label="{{ . }}" />
+                                <category scheme="taxonomy:{{ printf "%s" $taxo | humanize }}" term="{{ (. | urlize) }}" label="{{ . }}" />
                             {{ end }}
                         {{ end }}
                     {{ end }}

It would be great not to have to maintain a fork of this theme; @kaushalmodi any chance you'd be willing to look at the PR?

kaushalmodi commented 4 months ago

@stefanv I am not active in Hugo development lately, but to your comment

Sometimes (for categories), it comes in as a string.

That looks strange. I have never seen that happen. Should that be an issue on Hugo?

stefanv commented 4 months ago

Happens if you set categories: foo in the preamble, but that's a mistake, so we can stick to what is in this PR.

stefanv commented 4 months ago

Thanks @kaushalmodi!