Closed fuwuqi59 closed 3 years ago
Hi,
You will have to use the route's path
inside the surround
query.
Instead of having a site-wide i18n, I wanted i18n for specific articles, so I recently restructured the content
folder of this repo https://github.com/jainism-portal/jain-aagam with each deeply nested article present in its namesake language folder, instead of the article directly being a file. You can check its content
folder's structure for reference.
Earlier, the structure was:
๐ en
๐ folder... more folders
๐งพ apple
๐ hi
๐ folder... more folders
๐งพ apple
๐งพ mango
Here, on the apple
route, it is easy to fetch prev and next articles by using either slug
or path
in the surround because that will directly give you the mango
md file.
But, now, the structure is
๐ folder
๐ folder... more folders
๐ apple
๐งพ meta
๐งพ en
๐งพ hi
๐ mango
๐งพ meta
๐งพ hi
Here, on the apple
route wherein I display meta
info along with the current language's body, I cannot simply use path
in the surround
query. It will give me meta
, en
, hi
md files of the apple folder itself, which I don't want.
So, I have to modify it like this .surround(`/folder${this.filePathWithoutLocale}/meta`)
So, for the apple
route, mango
folder's meta
file will be fetched as the next article.
You can check it here https://github.com/jainism-portal/jainaagam/blob/506db64b2c3a7c019bb38d218b859fc23bf48980/components/organisms/post/PostPrevNext.vue#L28-L42
Here, the prop filePathWithoutLocale
is being sent to the PostPrevNext
component from inside the _.vue
page's computed properties. Basically, it is path
itself, without the suffix locale. You can check it here https://github.com/jainism-portal/jainaagam/blob/506db64b2c3a7c019bb38d218b859fc23bf48980/pages/_.vue#L234-L240
@fuwuqi59
surround()
method accepts only slug or path of a document (link).
Every element of the result array is a document object so there is nothing corresponding to directories. It's just a part of paths of documents.
More accurately, What surround()
method does is (1) to find it from the result array that the first element whose slug or path matches with the first argument of surround()
method, (2) to make up a new array by slicing the result array, and (3) to return it.
In this way, Nuxt Content can't find document by directory name, but it needs a cue by which to specify a document.
Hi I've stumbled upon the following issue and would love to hear your thoughts. I have a structure for my blog like the following:
content/ articles/ article-1/ index.md article-2/ index.md
I had no issues up to the point where I was trying to fetch previous and next articles surrounding a specific slug. I faced no issues if my md articles are organized using a file structure i.e. article-1.md (using the following code), but when they are reorganized as directory, that's when I failed to fetch surrounding articles.
const [prev, next] = await this.$content('articles') .only(['title', 'path']) .sortBy('date') .surround('article-2') .fetch()
How should I proceed when trying to fetch the surrounding articles organized as directories?