Issue: pageFolders "previewPath" setting doesn't seem to work #315

Closed
opened 2026-10-05 02:39:41 +02:00 by adam · 5 comments
Owner

Describe the bug

Despite setting the previewPath key in frontmatter.content.pageFolders, the preview for a page still opens to <frontMatter.preview.host>/<slug>.

To Reproduce

Steps to reproduce the behavior:

  1. Add Front Matter to a hugo site

  2. Define frontMatter.preview.host as http://localhost:1313

  3. Define frontmatter.content.pageFolders as:

    "frontMatter.content.pageFolders": [
       {
         "title": "Blog Posts",
         "path": "[[workspace]]/content/posts",
         "previewPath": "posts"
       }
    ]
    
  4. Add foo.md in the content/posts folder

  5. Open foo.md and select Open preview

  6. Get a 404 error and see the URL for the preview is http://localhost:1313/foo instead of http://localhost:1313/posts/foo.

Expected behavior

When I set the previewPath option for a page folder, the pages in that folder should have the value of previewPath appended to the preview host before the page slug when I preview that page.

Screenshots

Screenshot of the settings in frontmatter.json

Screenshot of 404 preview beside markdown file

Desktop (please complete the following information):

  • VS Code Info:
    • Version: 1.70.2 (system setup)
    • Commit: e4503b30fc78200f846c62cf8091b76ff5547662
    • Date: 2022-08-16T05:35:13.448Z
    • Electron: 18.3.5
    • Chromium: 100.0.4896.160
    • Node.js: 16.13.2
    • V8: 10.0.139.17-electron.0
    • OS: Windows_NT x64 10.0.19044
  • Front Matter: v8.0.1

Additional context

I did notice that if I set the previewPath for the Post content type in frontMatter.taxonomy.contentTypes that works - but my problem is, for the rest of my content, it lives in subfolders of a single folder (in this case, games, like games/factions, games/factions/supplements/coasts, and so on), which would require me to redefine the content type over and over.

Screenshot of settings in frontmatter.js showing the configuration for the Factions folder and a markdown page in that folder, as well as the Post content type with previewPath set

With previewPath set on the content type, it does show the correct preview page. However, the URL seems malformed, showing http://localhost:1313/posts\automated-factions instead of http://localhost:1313/posts/automated-factions - presumably because I'm on Windows?

Screenshot of a working preview page with malformed URL

I tried using the diagnostics and output terminal to see what was going on, but the output terminal only showed me an info message saying "Receiving message from webview to panel: open-preview" and the diagnostic info didn't include anything related to the content or folder specific preview settings.

I'm not clear if I've misconfigured something or misunderstood this feature. I saw #254 which implies a future feature for being able to leverage the SSG's own preview settings, which would likely resolve my entire problem, but I thought it worthwhile to file this issue as I would expect, even with that feature, that this override would function.

**Describe the bug** Despite setting the **previewPath** key in `frontmatter.content.pageFolders`, the preview for a page still opens to `<frontMatter.preview.host>/<slug>`. **To Reproduce** Steps to reproduce the behavior: 1. Add Front Matter to a hugo site 2. Define `frontMatter.preview.host` as `http://localhost:1313` 3. Define `frontmatter.content.pageFolders` as: ```json "frontMatter.content.pageFolders": [ { "title": "Blog Posts", "path": "[[workspace]]/content/posts", "previewPath": "posts" } ] ``` 4. Add `foo.md` in the `content/posts` folder 5. Open `foo.md` and select `Open preview` 6. Get a 404 error and see the URL for the preview is `http://localhost:1313/foo` instead of `http://localhost:1313/posts/foo`. **Expected behavior** When I set the **previewPath** option for a page folder, the pages in that folder should have the value of **previewPath** appended to the preview host before the page slug when I preview that page. **Screenshots** ![Screenshot of the settings in frontmatter.json](https://user-images.githubusercontent.com/14190564/188270474-3f8d0ae1-a389-48a3-82ba-3a7353884085.png "Screenshot of settings in frontmatter.json") ![Screenshot of 404 preview beside markdown file](https://user-images.githubusercontent.com/14190564/188270545-75f34946-9025-42f1-93ab-3d2dd6f4ba10.png "Screenshot of 404 preview beside markdown file") **Desktop (please complete the following information):** - VS Code Info: - Version: 1.70.2 (system setup) - Commit: e4503b30fc78200f846c62cf8091b76ff5547662 - Date: 2022-08-16T05:35:13.448Z - Electron: 18.3.5 - Chromium: 100.0.4896.160 - Node.js: 16.13.2 - V8: 10.0.139.17-electron.0 - OS: Windows_NT x64 10.0.19044 - Front Matter: v8.0.1 **Additional context** I did notice that if I set the **previewPath** for the `Post` content type in `frontMatter.taxonomy.contentTypes` that works - but my problem is, for the rest of my content, it lives in subfolders of a single folder (in this case, `games`, like `games/factions`, `games/factions/supplements/coasts`, and so on), which would require me to redefine the content type over and over. ![Screenshot of settings in frontmatter.js showing the configuration for the Factions folder and a markdown page in that folder, as well as the Post content type with previewPath set](https://user-images.githubusercontent.com/14190564/188271142-77f7f843-6854-428f-9c65-f3a1bded2cc2.png "Screenshot of settings in frontmatter.js showing the configuration for the Factions folder and a markdown page in that folder, as well as the Post content type with previewPath set") With **previewPath** set on the content type, it _does_ show the correct preview page. However, the URL seems malformed, showing `http://localhost:1313/posts\automated-factions` instead of `http://localhost:1313/posts/automated-factions` - presumably because I'm on Windows? ![Screenshot of a working preview page with malformed URL](https://user-images.githubusercontent.com/14190564/188271300-02dd5a2c-802e-4b6e-8296-336942b321f3.png "Screenshot of a working preview page with malformed URL") I tried using the diagnostics and output terminal to see what was going on, but the output terminal only showed me an info message saying "Receiving message from webview to panel: open-preview" and the diagnostic info didn't include anything related to the content or folder specific preview settings. I'm not clear if I've misconfigured something or misunderstood this feature. I saw #254 which implies a future feature for being able to leverage the SSG's own preview settings, which would likely resolve my entire problem, but I thought it worthwhile to file this issue as I would expect, even with that feature, that this override would function. <!-- github-sync-id:1360851242 -->
adam closed this issue 2026-10-05 02:39:41 +02:00
Author
Owner

Thanks @michaeltlombardi, I'll investigate what is going on here.

Thanks @michaeltlombardi, I'll investigate what is going on here. <!-- github-comment-id:1236634504 -->
Author
Owner

Thank you! Hugely appreciated!

Thank you! Hugely appreciated! <!-- github-comment-id:1236881050 -->
Author
Owner

@michaeltlombardi found the issue. It had indeed to do with some Windows path parsing, and it got fixed. Feel free to test it out in the latest beta version.

@michaeltlombardi found the issue. It had indeed to do with some Windows path parsing, and it got fixed. Feel free to test it out in the latest beta version. <!-- github-comment-id:1236994372 -->
Author
Owner

@estruyf confirmed, it's working! Thank you enormously for this fix, this is wayyyy easier to manage. 😊

Screenshot of VS Code showing the highlighted preview path setting in the frontmatter.json file, the markdown file, and the preview for that file displaying correctly.

@estruyf confirmed, it's working! Thank you enormously for this fix, this is wayyyy easier to manage. 😊 ![Screenshot of VS Code showing the highlighted preview path setting in the frontmatter.json file, the markdown file, and the preview for that file displaying correctly.](https://user-images.githubusercontent.com/14190564/188502413-f6329360-0e02-4714-967d-6a09a405dafc.png) <!-- github-comment-id:1237390935 -->
Author
Owner

Thanks @michaeltlombardi for confirming

Thanks @michaeltlombardi for confirming <!-- github-comment-id:1237895786 -->
Sign in to join this conversation.
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: adam/vscode-front-matter#315