Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add author in posts info #173

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Add author in posts info #173

wants to merge 4 commits into from

Conversation

ctmbl
Copy link

@ctmbl ctmbl commented Mar 24, 2024

closes #170

Description

As discussed in the issue, if author is in the article's metadata add it just before the date in the post's info
Moreover, if author is a taxonomy for the website make it an hyperlink to /author/<author name>

What could be improved

Currently no CSS is added, and while the result seems good enough in dark mode with the hyperlink (see #170)
without the hyperlink it can be a bit "poor"
Screenshot_20240324_195802
I'd like to give it its own style, like tags but I'm not very creative when it comes to GUI...

Also, when listing an author's post, I believe layouts/_default/list.html is used to list terms of a taxonomy if I trust the doc. But it "titlized" the taxonomy's term (here my nickname) thus not respecting the case:
Screenshot_20240324_201302
Ctmbl instead of ctmbl
this is basically the same issue that #152, also https://discourse.gohugo.io/t/taxonomy-terms-permalink-spaces-vs-dashes/48629/5 might help

Forget that I noticed that hugo 0.123.0 introduced capitalizelisttitles = false that address my issue

Finally it's a bit outside of the scope of this PR but it might be nice to add a guard for tags URLs, as I did for author, if tags is not a taxonomy for the website

@ctmbl ctmbl closed this Mar 24, 2024
@ctmbl ctmbl deleted the post-author branch March 24, 2024 19:17
@ctmbl ctmbl restored the post-author branch March 24, 2024 19:21
@ctmbl ctmbl reopened this Mar 24, 2024
@ctmbl
Copy link
Author

ctmbl commented Mar 24, 2024

sorry for the miss-closing...

@ctmbl
Copy link
Author

ctmbl commented Mar 25, 2024

HI @lukeorth

DISCLAIMER: This issue is a bit outside of the scope of this PR (even if related to), if you want I can create a separate issue for it ofc

These threads are related:
https://discourse.gohugo.io/t/what-can-cause-infinite-recursion-can-dumping-taxonomies-cause-it/49029/3
https://discourse.gohugo.io/t/getting-links-to-taxonomy-term-pages/10699/3
https://discourse.gohugo.io/t/how-to-get-permalink-of-taxonomies-in-templates/12927

I bumped into a slight issue while working on this PR and I'd really like your view on it.

Description of the problem

Currently in poison we have two "default" taxonomies tags and series.
But looking at the code in layouts/partials/post/info.html the URL to these taxonomies' page isn't built the same way:
tags:

...
<li class="tag-{{ . }}">
  <a href="{{ "tags/" | absLangURL }}{{ . | urlize }}">{{ . }}</a>
</li>
...

series:

...
    Series: <a href="{{ $Site.BaseURL }}series/{{ .Params.series | urlize }}">{{ .Params.series }}</a>

...

In the case of tags, absLangURL is used which ensures robust construction of the absolute URL.

But in the case of series the baseURL is simply prefixed to the relative path, which isn't robust, for example if baseURL doesn't finish with a / (it is my case and it breaks, try clicking on the series at https://iscsc.fr/posts/introducing-poison/): if baseURL=http://example.com it will built the URL http://example.comseries/my-series which of course will fail.

Also, in both case we hardcode the taxonomy (tags/ and series/) path, which could break given that in HUGO one can define custom permalinks: https://gohugo.io/content-management/urls/#permalinks-monolingual-examples or https://discourse.gohugo.io/t/how-to-get-permalink-of-taxonomies-in-templates/12927 (WARNING: old thread)

Possible solution

1. Do nothing about it

It's not a major issue ofc. Why bother and lose time looking for "the" best solution, and maybe I should just add a / at the end of my baseURL after all 🥲

2. Keep hardcoding taxonomies but use absLangURL

For the consistency of poison codebase and because it is robust against different baseURL.
It works like a charm for tags so why want to change everything, who use custom permalinks anyway?

3a. Use HUGO .GetPage and .Permalink methods like this...

The idea is pretty simple: let HUGO handle it, it's its job after all.
Using .GetPage (or .Site.GetPage to fetch the appropriate Page object, with to set it as context and finally get its .Permalink

With my current implementation it looks like:

{{ if .Params.author }}
  {{ $author := .Params.author }}
  {{ $authorURLized := ($author | urlize) }}
  {{ with .Site.GetPage (printf "author/%s" $authorURLized) }}
    <span><a href="{{ .Permalink }}">{{ $author }}</a> - </span>
  {{ else }}
    <span>{{ .Params.author }} - </span>
  {{ end }}
{{ end }}

3b. ...or like that

But I'm not very fond of the printf... So it can also be written (which might be my best solution):

{{ if .Params.author }}
  {{ $author := .Params.author }}
  {{ $authorURLized := ($author | urlize) }}
  {{ with .Site.GetPage "author" }}
    <span><a href="{{ (.GetPage $authorURLized).Permalink }}">{{ $author }}</a> - </span>
  {{ else }}
    <span>{{ .Params.author }} - </span>
  {{ end }}
{{ end }}

But now I'm talking about details, I just don't have any knowledge about HUGO's "best practices" if it exists such...

Conclusion

As stated at the beginning, even if related because this PR wants to handle author taxonomy, this issue is outside of its scope so I'll create a separate issue right away if you want to.

I have a preference for the solution 3b because it looks to me like the way HUGO wants it to be done, but I'm really new to HUGO anyway so maybe I missed something huge which makes my solution no good at all, who knows?
Also the 3rd solution is a bit more difficult to understand for new contributors (it involves more HUGO syntax and code) so I'd understand if you want to keep it simple with the 2nd solution.

Anyway I'd be happy to hear about your opinion, even if not for poison just for me to learn more about HUGO 😉

Thanks for reading and sorry for the looong post 😅

@ctmbl
Copy link
Author

ctmbl commented Mar 26, 2024

given recent update on this thread I opened on HUGO's forum I'd say that this solution suggested by one of HUGO's dev would be even better:

{{ with .Params.author }}
  {{ with site.Taxonomies.author.Get . }}
    <span><a href="{{ .Page.RelPermalink }}">{{ .Page.LinkTitle }}</a> - </span>
  {{ else }}
    <span>{{ . }} - </span>
  {{ end }}
{{ end }}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Display author in post info
1 participant