The background to my messing with the titleCaseStyle
option is that I’m building a new web site and want to use sentence case for titles, sections, headings, everything really. (Sentence case is increasingly what’s used everywhere — The Guardian, CNN, etc.)
So that means the menu should say “Posts”, but the heading on the list page needs to say “Recent posts”, and so on. Using ananke as starting theme, the “Recent Posts” string comes from i18n/en.toml
:
[recentTitle]
other = "Recent {{ .Title }}"
I noticed that setting the option didn’t leave the .Title
(i.e. section type) in lower case, per issue 11547. I thought the easiest thing to do would be to fix that string to "Recent {{ .Title | lower }}"
or "Recent {{ lower .Title }}"
, but that doesn’t work — it seems the helper functions aren’t available in that context:
WARN Failed to get translated string for language "en" and ID "recentTitle": template: :1: function "lower" not defined
The right answer, for anyone who stumbles into this thread, is that ananke has a variable you can use in a top level content/_index.md
file:
recent_copy = "Recent posts"
Having solved the immediate problem, I’m not sure what the right functionality is for Hugo in general. Ideally there would be a simple way to say “sentence case” or “title case” and have that apply everywhere, but case changes are algorithmically difficult because you have to deal with situations like the user defining sections called “iPhone”, “iPad”, “Apple Watch”, “macOS”, etc. As long as the “none” option exists, that’s probably the way to go, and make any changes in the template. Or for themes, have multiple variables rather than trying to do case transformations.