decap-cms icon indicating copy to clipboard operation
decap-cms copied to clipboard

preview_path not does not correspond to the real path

Open tpavel-aspose opened this issue 4 years ago • 10 comments

Uploading image.png… 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"]

tpavel-aspose avatar Feb 16 '21 16:02 tpavel-aspose

I have this same error. I tried testing with different tags but {{filename}} doesn't even seem to work at all.

jwktje avatar Feb 22 '21 17:02 jwktje

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)

erezrokah avatar Apr 04 '21 14:04 erezrokah

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.

lsolesen avatar Apr 04 '21 14:04 lsolesen

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?

lrq3000 avatar Jul 12 '21 05:07 lrq3000

/EDIT: there was a typo in my previous message, it's the {{slug}} tag that contains the full nested path.

lrq3000 avatar Jul 12 '21 05:07 lrq3000

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.

lrq3000 avatar Jul 12 '21 05:07 lrq3000

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 avatar Jul 12 '21 11:07 erezrokah

@erezrokah Please see my proposed solution. If it works for you, I'll add and update the tests.

mikestopcontinues avatar Feb 17 '22 17:02 mikestopcontinues

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? :)

tenhobi avatar Mar 24 '25 18:03 tenhobi

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.

tenhobi avatar Mar 24 '25 20:03 tenhobi