Issue: Unable to directly preview section (_index.md) pages #318

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

Describe the bug

With a Hugo site that has section pages, which are always named _index.md and map directly to the folder they're found in, I'm unable to preview the markdown via the Open preview command in the action bar. Instead, I have to go to the site root and navigate to the page from there.

When I try to open the preview, it always appends _index to the preview path. I can set the slug value in the markdown file's metadata, but setting it to null or an empty string puts the preview path to _index and slug is also used by Hugo.

To Reproduce
Steps to reproduce the behavior:

  1. With a Hugo site and the following file: content/foo/_index.md
  2. Set the frontmatter.json to:
    {
      "frontMatter.framework.id": "hugo",
      "frontMatter.content.publicFolder": "static",
      "frontMatter.preview.host": "http://localhost:1313",
      "frontMatter.content.pageFolders": [
        {
          "title": "Posts",
          "path": "[[workspace]]/content/foo",
          "previewPath": "foo"
        }
      ]
    }
    
  3. Open content/foo/_index.md
  4. Start the server
  5. Select the Open preview command
  6. See that the preview URL is http://localhost:1313/foo/_index

Expected behavior

There should be a way to override the preview path on a per-file basis (without munging the metadata for the SSG itself) to work around this issue.

Screenshots

Screenshot showing the settings, a section file, and the incorrect preview URL causing a 404 error

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: Front Matter BETA v8.0.2993426

Additional context

I filed this as a bug because I can't see a way to preview section pages at all, but I do see that I'm sorta asking for a feature request here as well - I think being able to add metadata to override the Front Matter configuration on a per-file basis is likely really helpful, especially without the sort of SSG-aware configuration behavior described in #254.

**Describe the bug** With a Hugo site that has section pages, which are always named `_index.md` and map directly to the folder they're found in, I'm unable to preview the markdown via the **Open preview** command in the action bar. Instead, I have to go to the site root and navigate to the page from there. When I try to open the preview, it always appends `_index` to the preview path. I can set the **slug** value in the markdown file's metadata, but setting it to `null` or an empty string puts the preview path to `_index` and **slug** is also used by Hugo. **To Reproduce** Steps to reproduce the behavior: 1. With a Hugo site and the following file: `content/foo/_index.md` 2. Set the `frontmatter.json` to: ```json { "frontMatter.framework.id": "hugo", "frontMatter.content.publicFolder": "static", "frontMatter.preview.host": "http://localhost:1313", "frontMatter.content.pageFolders": [ { "title": "Posts", "path": "[[workspace]]/content/foo", "previewPath": "foo" } ] } ``` 3. Open `content/foo/_index.md` 4. Start the server 5. Select the **Open preview** command 6. See that the preview URL is `http://localhost:1313/foo/_index` **Expected behavior** There should be a way to override the preview path on a per-file basis (without munging the metadata for the SSG itself) to work around this issue. **Screenshots** ![Screenshot showing the settings, a section file, and the incorrect preview URL causing a 404 error](https://user-images.githubusercontent.com/14190564/188511431-301b0cdb-2909-4034-8280-20b576515161.png "Screenshot showing the settings, a section file, and the incorrect preview URL causing a 404 error") **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: Front Matter BETA v8.0.2993426 **Additional context** I filed this as a bug because I can't see a way to preview section pages at all, but I do see that I'm sorta asking for a feature request here as well - I think being able to add metadata to override the Front Matter configuration on a per-file basis is likely really helpful, especially without the sort of SSG-aware configuration behavior described in #254. <!-- github-sync-id:1362462962 -->
adam closed this issue 2026-10-05 02:39:53 +02:00
Author
Owner

Good catch, will change the behavior to ignore the _index and index paths to be applied to the URL.

Good catch, will change the behavior to ignore the `_index` and `index` paths to be applied to the URL. <!-- github-comment-id:1237897707 -->
Author
Owner

@michaeltlombardi this has been fixed and is available for testing.

@michaeltlombardi this has been fixed and is available for testing. <!-- github-comment-id:1239049479 -->
Author
Owner

@estruyf it works! 💜 thanks so much for yet another awesome and quick fix!

Screenshot of an _index.md section page beside the working preview for that page

@estruyf it works! 💜 thanks so much for yet another awesome and quick fix! ![Screenshot of an _index.md section page beside the working preview for that page](https://user-images.githubusercontent.com/14190564/188874051-a937712d-1ba3-4b69-a55d-94c6a9009f72.png) <!-- github-comment-id:1239300669 -->
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#318