preview_path not does not correspond to the real path
hugo version: 0.80.0
In editor path equal as
conversion-api/conversion-sdk-api/xhtml-converter
title: XHTML converter
Preview link now as
netlify.app/html/conversion-api-conversion-sdk-api-xhtml-converter-_index
but must equal
netlify.app/html/conversion-api/conversion-sdk-api/xhtml-converter/
my config
collections:
- name: html
label: HTML
label_singular: "Page"
folder: content/html
slug: "{{slug}}"
preview_path: "html/{{slug}}"
create: true
media_folder: ''
public_folder: ''
nested:
depth: 100
summary: "{{title}}"
fields:
- {label: "Title", name: "title", widget: "string"}
- {label: "Keywords", name: "keywords", widget: "string", required: false}
- {label: "Description", name: "description", widget: "string", required: false}
- {label: "Weight", name: "weight", widget: "number", value_type: "int", default: 10, step: 10, min: 1, max: 1000, required: false }
- {label: "Type", name: "type", widget: "hidden", default: "docs"}
- {label: "Body", name: "body", widget: "markdown", required: false}
meta: { path: { widget: string, label: "Path", index_file: "_index" } }
summary: "{{weight}} - {{title}}"
sortable_fields: ["weight",'title', "commit_author", "commit_date"]
I have this same error. I tried testing with different tags but {{filename}} doesn't even seem to work at all.
The CMS escapes template variables since they can break URL structure.
You might be able to construct the full preview path based on multiple fields, e.g {{field1}}/{{field2}} or we can consider proving an option to opt out of the CMS behavior (or even use https://www.netlifycms.org/docs/beta-features/#summary-string-template-transformations)
It is not an option for me to rebuild the link, as I add the slashes manually, so an option to opt out og that behavior would be great.
This issue also happens with GatsbyJS. It's because of nested collections, {{slug}} contains the full nested subfolders path but it's escaped with dashes so it's not a path anymore.
Any way to fix this? Maybe an undocumented templating tag specifically for nested folders path?
/EDIT: there was a typo in my previous message, it's the {{slug}} tag that contains the full nested path.
To summarize the issue, for the moment there seems to be no way to set up adequately the preview_path to allow previews of collections that are nested, because there is no specific tag and the only one that is the closest to what we need is {{slug}} but it escapes path delimiters into dashes to be URL safe.
or we can consider proving an option to opt out of the CMS behavior (or even use https://www.netlifycms.org/docs/beta-features/#summary-string-template-transformations)
If anyone would like to follow up with a PR to one of the suggestions in this comment it would be great.
@erezrokah Please see my proposed solution. If it works for you, I'll add and update the tests.
I have the same issue, after 3 years.
with
preview_path: "{{slug}}"
I still get url that ends with -_index
Can this be fixed, pretty please? :)
As a workaround, what I do now, since I define url/slug for each post and it might be different from Decap's slug, which is "file path" basically, I set it as preview_path: "posts/{{fields.slug}}" which gives me correct url from my fields. I just need to make sure that I set up this and permalink patterns the same.
And using preview_path: "{{slug}}" is wrong anyway if your url is not based on filename.