slug property is not correct when using directory and index.md approach
See original GitHub issueVersion
@nuxt/content: 1.6.0 nuxt: 2.14.1
Reproduction Link
https://codesandbox.io/s/dank-paper-djlm0?file=/content/a-new-entry/index.md
Steps to reproduce
Create two content files
- one with a unique name at the top level in the content directory
- one in a subdirectory, and name it index.md
Start the application and check the content. Supply the file name or the directory name as the slug in await $content(slug)
What is Expected?
the slug property on the returned post is the same as what had to be supplied in order to fetch it
What is actually happening?
the slug property is correct for file names, but is being returned as ‘index’ for directory based content ie. the .md file name not the actual slug name
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Docs Introduction - Docusaurus
The docs feature provides users with a way to organize Markdown files in a hierarchical format.
Read more >Frequently Asked Questions - Read the Docs
Frequently Asked Questions¶. My project isn't building correctly¶. First, you should check out the Builds tab of your project. That records all of...
Read more >How to access resources from pages within a branch bundle
This method works fine for leaf bundles, but fails to work for pages located in the root directory of a branch bundle.
Read more >Permalinks — Eleventy
You may not be using HTML for that page in 20 years time, but you might want today's links to it to ......
Read more >Routing • Docs • SvelteKit
Each route directory contains one or more route files, which can be identified ... src/routes/blog/[slug]/+page.svelte ... throw error (404, 'Not found');.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
OK so there’s maybe two things here.
I now see that you supply a path to $content, which makes sense.
But a slug is defined as “the unique identifying part of a web address, typically at the end of the URL”, which is not necessarily the file name. In the case of this issue, it’s the final part of the URL, which is either the file name (minus .md) in the case of discrete files, or the name of the enclosing directory in the case of an index.md.
Returning ‘index’ as the slug every single time is not useful, and not correct from an SEO and web point of view.
This behaviour will not be changed in the current version as there is no simple way, see https://github.com/nuxt/content/pull/435#issuecomment-683702018.