All pages does not have weight params in frontmatter.
I want to set weight params in code based on file name.
File name format is xx_String.md.
xx is 2 digits.
So, I can get xx from bellow code, and hope to know //**//
{{ range .Pages }}
{{ $weight := substr .File.BaseFileName 0 2}}
// * what method can I use for setting every page's weight with above value *//
{{ end }}
If anyone have experiences on this, please let me know kindly…
Warm Regards.
I’m trying to do exactly the same thing: setting some param (like date, weight and title) from the filename, so that I can for instance use them in a range in the context of a list of content.
Did you eventually come up with a workaround?
I thought it would have been easy to extract a $value from the .File.BaseFileName with functions like trim and replaceRE and use it to override a .Page.Param like .Weight, .Date or .Title (would it be set in the page front-matter or not)…
I would like to do so without an archetype nor a bash script because while they seem to be both working solutions they’re not so convenient/flexible as they require running ‘manual’ operations (creating the new page or executing the script).
@bep, is Hugo now offering such a possibility? Or is there another way to do so ?
If not, alternatively, maybe the function range .Pages.ByParam could be extended to something like this: range .Pages.By$value?
In which case we wouldn’t even need to be able to override any .Page.Param.
I believe filenames are great pieces of metadata.
Thank you for your help! and for developing this awesome tool that is Hugo
Edit: Thanks @jmooring however i beleive discouraging doesn’t mean closing the discussion - but I’m not native locutor… If thats your policy, you should configure discourse to close inactive discussions by itself.
We discourage reviving old topics because people who participated in those discussions of yesteryear are usually not here anymore and they rarely reply to questions. It is best to open a new topic rather than bumping an old one.