Is there a string function that will give me the default slug from the taxonomy term (I would rather not declare the slug in my front-matter). I am currently using (what appears to me) a rather expensive round-about way to get each taxonomy slug like this:
{{ range $term, $value := .Data.Terms }}
{{ with index $value 0 }}
{{ $slug := (index (where $.Pages "LinkTitle" .LinkTitle) 0).RelPermalink }}
// Use $slug after stripping a possible trailing filename here
{{- end }}
{{- end
I did try .LinkTitle | urlize and while that removes obvious inappropriate characters like “:”, it does not work with Unicode characters in the title.
I have a script that updates an Algolia index and is triggered by a Git Webhook. This script reads an “index.json” generated by a template. I need to add a field in items of that index that will tell me the path of each taxonomy term so I can visit and get the individual articles of that taxonomy term.
My apologies if that explanation was inadequate (not a native English speaker). I would happy to answer any further queries you might have.
I was hoping that the steps would be (1) replace spaces by hyphens (2) lowercase everything and (3) remove special characters. So in the eventt that such a pre-defined function does not exist, just the complete list of special characters to remove/replace would be a solution that I would be happy with
Don’t be Indeed, I did fetch .PermaLink but that is because .Permalink in the loop over .Data.Terms (see original post) returns the folder name relative to the public folder inside each iteration. So in thsi happy circumstance .Permalink and the path are identical.
To illustrate with an example: If my Taxonomy term is “Bruce: Willis” - Under which folder can I find all articles tagged by “Bruce: Willis” - It turns out to be actors/bruce-willis As you can see, the code in my original post does give me the correct answer. But my concern is that I am jumping through two hoops to get it. And my question was is there a simple function call (or a predictrable manual transformation that will convert “Bruce: Willis” into “bruce-willis”.
Typically “files corresponding to the taxonomy term” are published in the section corresponding to their content type (e.g., public/articles/article-1/index.html).