Skip to content
Sveltia CMS
Esc
↑↓navigate↵open⌘Jpreview
On this page

Preview Paths, Permalinks and Redirects

Set preview URLs for Sveltia CMS entries, store each entry’s path in its front matter, and record redirects when slugs change.

The preview_path option tells Sveltia CMS where an entry lives on your site, which enables site previews, deploy previews, permalinks stored in the entry itself, and automatic redirects when an entry’s slug changes.

Preview Paths

The preview_path option allows you to define a custom URL path for previewing entries on your live site. This option accepts a string with template tags that will be replaced with entry-specific values when generating the preview URL. The CMS provides links to preview the entries based on this URL structure.

Without preview_path, the CMS can’t tell where an entry lives, so a published entry has no preview link. An unpublished entry in Editorial Workflow still links to the root of its deploy preview. The deploy preview’s address changes with each pull request, so the link is the easiest way to find it.

A preview_path that can’t be filled in for an entry, such as one with date tags on an entry whose date is empty, gives no link at all.

The path is appended to your site’s own address, or to the address of a build made for the entry when your repository is connected to a CI/CD provider. See Deploy Previews for how those are found.

The slug template tags can be used in the preview_path option, with the following exceptions:

  • {{slug}}: the entire slug of the entry, not just the slugified entry identifier.
  • {{year}}, {{month}}, {{day}}, {{hour}}, {{minute}}, {{second}}: these tags are based on the entry’s DateTime field. The CMS looks for the first DateTime field in the collection to extract the date and time information. Use the preview_path_date_field option to specify a different top-level DateTime field.
    • If no DateTime field is found, the preview_path option will be ignored. A configuration warning is shown so the missing link doesn’t go unexplained.
    • A field that exists but is left empty on an entry has the same effect on that entry.
  • {{dirname}}: the directory name of the entry file relative to the collection folder, without the locale folder of an i18n structure with a folder per locale. This is useful when using the path option to create subfolders.
  • {{filename}}: the filename of the entry without the extension. This is useful when you want to use the exact filename in the preview URL.
  • {{extension}}: the file extension of the entry. This is useful when you want to include the file type in the preview URL.
  • {{locale}}: the locale code of the entry when using i18n support. This is useful when you want to include the locale in the preview URL.

Just like the slug and path options, any field name defined in the collection’s fields option can also be used as a template tag in preview_path. A field’s name may match one of the predefined tags listed above or in the slug template tags, such as slug, year or uuid. If so, prefix it with fields., like {{fields.slug}}, to avoid confusion with the tag itself.

You can use string transformations with these template tags.

The example below shows how to configure a blog posts collection with a custom preview URL structure.

collections:
  - name: posts
    label: Blog Posts
    folder: /content/posts
    preview_path: '/blog/{{year}}/{{month}}/{{slug}}'
    preview_path_date_field: created_at
    fields:
      - { name: title, label: Title }
      - { name: created_at, label: Created At, widget: datetime }
      - { name: body, label: Body, widget: richtext }
[[collections]]
name = "posts"
label = "Blog Posts"
folder = "/content/posts"
preview_path = "/blog/{{year}}/{{month}}/{{slug}}"
preview_path_date_field = "created_at"
[[collections.fields]]
name = "title"
label = "Title"
[[collections.fields]]
name = "created_at"
label = "Created At"
widget = "datetime"
[[collections.fields]]
name = "body"
label = "Body"
widget = "richtext"
{
  "collections": [
    {
      "name": "posts",
      "label": "Blog Posts",
      "folder": "/content/posts",
      "preview_path": "/blog/{{year}}/{{month}}/{{slug}}",
      "preview_path_date_field": "created_at",
      "fields": [
        { "name": "title", "label": "Title" },
        { "name": "created_at", "label": "Created At", "widget": "datetime" },
        { "name": "body", "label": "Body", "widget": "richtext" }
      ]
    }
  ]
}
{
  collections: [
    {
      name: "posts",
      label: "Blog Posts",
      folder: "/content/posts",
      preview_path: "/blog/{{year}}/{{month}}/{{slug}}",
      preview_path_date_field: "created_at",
      fields: [
        { name: "title", label: "Title" },
        { name: "created_at", label: "Created At", widget: "datetime" },
        { name: "body", label: "Body", widget: "richtext" },
      ],
    },
  ],
}

With the above configuration, a blog post created on June 15, 2025, with the title “My First Post” will have a preview URL of /blog/2025/06/my-first-post.

Setting the preview_path option does two more things:

  • It lets the CMS tell your framework where to build an entry. See Permalinks below.
  • It lets the CMS keep links working when an entry is renamed. See Redirects below.
  • It’s what Deploy Previews need in order to point at an entry. Without it, there’s nothing to append to the site or preview address, so no preview link is shown.

The preview_path and preview_path_date_field options can also be set on each file of a file collection, where the collection-level options have no effect.

Some frameworks read an entry’s output path from a front matter property. Sveltia CMS can fill that property from the preview_path option, so your site is built at the same path the CMS links to. You don’t have to reproduce the framework’s slug rules in preview_path or add the slug to each entry by hand.

This is turned off by default. Set the permalink_field option on an entry collection to enable it:

  • true: use the permalink property.
  • a string: use a property of that name, such as url.
  • false: leave the property alone.

The example below stores the path in the permalink property, which Eleventy reads:

collections:
  - name: portfolio
    label: Portfolio
    folder: /content/portfolio
    preview_path: 'portfolio/{{slug}}/'
    permalink_field: true
[[collections]]
name = "portfolio"
label = "Portfolio"
folder = "/content/portfolio"
preview_path = "portfolio/{{slug}}/"
permalink_field = true
{
  "collections": [
    {
      "name": "portfolio",
      "label": "Portfolio",
      "folder": "/content/portfolio",
      "preview_path": "portfolio/{{slug}}/",
      "permalink_field": true
    }
  ]
}
{
  collections: [
    {
      name: "portfolio",
      label: "Portfolio",
      folder: "/content/portfolio",
      preview_path: "portfolio/{{slug}}/",
      permalink_field: true,
    },
  ],
}

Saving an entry titled “Hello World” then results in the following front matter:

---
permalink: /portfolio/hello-world/
title: Hello World
---
+++
permalink = "/portfolio/hello-world/"
title = "Hello World"
+++
{
  "permalink": "/portfolio/hello-world/",
  "title": "Hello World"
}

Supported Frameworks

These frameworks set a page’s whole output path from a front matter property. Use the permalink_field value that matches yours:

Framework permalink_field value Notes
Eleventy true The path must end with a slash or a file extension. Otherwise, the build fails.
Hexo true The path must end with a slash or .html.
Hugo url On a multilingual site, include the {{locale}} tag in preview_path where the language prefix belongs.
Jekyll true
Lume url A path without a trailing slash or file extension creates a file without an extension.
VuePress true
Zola path

Docusaurus is different: its slug property is relative to the plugin’s route base path, such as /docs. Set permalink_field to slug only if preview_path leaves that base path out, which means the preview links won’t include it either.

Frameworks that define routes in code, such as Astro, Next.js and SvelteKit, have no such property, but you can read one in your own route code.

How the Property Is Updated

  • The path is filled in each time an entry is saved, for both new and existing entries, because it can depend on the slug and on any field.
  • An existing entry gets the property the next time it’s saved. The CMS doesn’t update entries in bulk when you enable the option.
  • Bulk editing, relation updates and moving a folder of nested entries also update the entries they rewrite. Renaming an asset and reordering entries don’t, so an entry whose path depends on an asset or its order is updated the next time it’s saved.
  • The path always starts with a slash, whether or not preview_path does. The rest is kept as written, so a trailing slash has to come from preview_path.
  • If the path can’t be filled in, such as when an entry’s date is empty, the property is removed so an outdated path can’t remain.

The CMS leaves the property alone in these cases:

  • Its value isn’t a string, such as Eleventy’s permalink: false, which keeps a page from being built.
  • The preview_path option isn’t defined.
  • A field with the same name is defined in the fields option. The property is then left to the editor to manage.
  • The entry is the collection’s index file.

The option replaces any other string in the property, including a template you wrote by hand for your framework.

Redirects

Changing an entry’s slug usually changes its URL, which breaks existing links to it, including internal links, external links and search engine results. To prevent this, Sveltia CMS can record the entry’s previous path in its data, so your framework can redirect visitors from the old URL to the new one.

This requires the preview_path option, because that option is what tells the CMS where an entry lives on your live site. Once it’s set, saving an entry with a modified slug adds the previous path to the entry’s aliases property:

  • If the property doesn’t exist yet, it’s created as a list with a single item.
  • If the property already exists as a list, the previous path is appended to it, so redirects accumulate as an entry is renamed over time.

Entry slugs can be changed in the Slug panel of the Content Editor’s sidebar.

With the preview_path configuration shown under Preview Paths, renaming a June 2025 blog post from my-first-post to hello-world results in the following front matter:

---
aliases:
  - /blog/2025/06/my-first-post
title: Hello World
created_at: 2025-06-15T09:00:00.000Z
---

The aliases property is supported out of the box by Hugo and Zola, which generate the redirects for you. Other frameworks may expect a different property name or require a plugin.

Customizing the Redirect Property

You can store the previous paths in a property other than aliases using the aliases_field option. For example, Jekyll sites using the jekyll-redirect-from plugin expect a redirect_from property:

collections:
  - name: posts
    label: Blog Posts
    folder: /content/posts
    preview_path: '/blog/{{year}}/{{month}}/{{slug}}'
    aliases_field: redirect_from
[[collections]]
name = "posts"
label = "Blog Posts"
folder = "/content/posts"
preview_path = "/blog/{{year}}/{{month}}/{{slug}}"
aliases_field = "redirect_from"
{
  "collections": [
    {
      "name": "posts",
      "label": "Blog Posts",
      "folder": "/content/posts",
      "preview_path": "/blog/{{year}}/{{month}}/{{slug}}",
      "aliases_field": "redirect_from"
    }
  ]
}
{
  collections: [
    {
      name: "posts",
      label: "Blog Posts",
      folder: "/content/posts",
      preview_path: "/blog/{{year}}/{{month}}/{{slug}}",
      aliases_field: "redirect_from",
    },
  ],
}

Disabling Redirects

If your framework doesn’t support redirects defined in entry data, set the aliases_field option to false. The CMS will then leave the property untouched when an entry is renamed, and no redirects will be generated.

collections:
  - name: posts
    label: Blog Posts
    folder: /content/posts
    preview_path: '/blog/{{year}}/{{month}}/{{slug}}'
    aliases_field: false
[[collections]]
name = "posts"
label = "Blog Posts"
folder = "/content/posts"
preview_path = "/blog/{{year}}/{{month}}/{{slug}}"
aliases_field = false
{
  "collections": [
    {
      "name": "posts",
      "label": "Blog Posts",
      "folder": "/content/posts",
      "preview_path": "/blog/{{year}}/{{month}}/{{slug}}",
      "aliases_field": false
    }
  ]
}
{
  collections: [
    {
      name: "posts",
      label: "Blog Posts",
      folder: "/content/posts",
      preview_path: "/blog/{{year}}/{{month}}/{{slug}}",
      aliases_field: false,
    },
  ],
}

The same applies if you define a field with the same name as the redirect property in the fields option. The CMS assumes that the redirects are to be managed in the Content Editor, so it won’t write to the property on its own. This is the way to go to curate the list by hand while still being able to see and edit it in the CMS.

Was this page helpful?