Content: Non-unique slugs' impact on `surround`

Created on 5 Jun 2020  Â·  2Comments  Â·  Source: nuxt/content

Hi — first of all, thanks a ton for all the effort.
It's a pretty amazing module!

I've stumbled upon the following issue and would love to hear your thoughts.
Assumed there's a structure like:

content/
    series-a/
        intro.md
        subpost-a-1.md
        subpost-a-2.md
    series-b/
        intro.md
        subpost-b-1.md
        subpost-b-2.md

In this case, both intro.md files would have the same slug.
That's usually not an issue at all since it's up to the developers when to use path or slug.

But how to proceed when trying to fetch the surrounding posts?
That feature uses the slugs property which isn't unique and thus the results are not really predictable. Is there a "proper" workaround, would you consider it a bug or should the developers take care of unique file names? 😊

Cheers,
Felix

question

Most helpful comment

Hey @felixheck,

When using surround, you can specify a parent directory, so you could do something like:

const [prev, next] = await this.$content('series-a')
  .surround('intro')
  .fetch()

However, if you want to browse across all your files using deep-fetching for example, in my opinion you should take care of unique file names yes.

All 2 comments

Hey @felixheck,

When using surround, you can specify a parent directory, so you could do something like:

const [prev, next] = await this.$content('series-a')
  .surround('intro')
  .fetch()

However, if you want to browse across all your files using deep-fetching for example, in my opinion you should take care of unique file names yes.

Merci beaucoup!

I just wrote my own surround function which uses paths instead of slugs.
Not ideal but it's just needed in one place, so it's fine 😊

Have a nice weekend.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

thely picture thely  Â·  4Comments

dolbex picture dolbex  Â·  3Comments

uporot1k picture uporot1k  Â·  4Comments

LukaszRados picture LukaszRados  Â·  3Comments

pxwee5 picture pxwee5  Â·  4Comments