Writing filenames other than sys.id
initrode opened this issue · comments
Great module.
I couldn't find a way to write filenames (for say Article
types) to represent the slug set in Contentful.
This means I get URLs like //articles/3kqwk8n0xnjpb7vcsck005
which isn't good for SEO.
Is there a way to workaround this?
Currently we don't support naming the file from a field in Contentful. However, if you have a slug
field Hugo will use that as the slug in your URL instead of the filename.
If you don't have a field specifically named slug you can use the overrides
parameter to specify a field to use as the slug. See
https://github.com/ModiiMedia/contentful-hugo#overriding-fields-and-field-values and https://github.com/ModiiMedia/contentful-hugo#the-overrides-parameter
@mjp80
I now have a working build of this feature here: https://github.com/ModiiMedia/contentful-hugo/tree/dynamic-filename.
It not only allows you to use any entry property as the filename for repeatableTypes
but it also keeps track of where dynamically named files have been written. This allows it to delete the old files if the property value has changed.
For example if a post's slug field has been changed. It'll delete the file at it's old location and then create a file with the new slug.
I'm going to run a few more tests, but I expect to merge this branch to master sometime next week.
added in #44