_Not sure if the title is very descriptive, but I failed to find better English phrasing :)_
I am fetching surrounding blog posts on a single post page. Currently when it's the first post, no previous post is returned (null is returned instead). Similar thing happens for the last post. This is expected and well documented in fetching content docs.
I would love to have an option to add a wrap or loop param that - when set to true - would force surround to return a post. For example, when fetching surrounding posts for the last post, it would return the first post.
Example:
['post-1', 'post-2', 'post-3']
Current behaviour:
$content(...).surround('post-3').fetch() // returns [ post2, null]
Expected behaviour:
$content(...).surround('post-3', { loop: true }).fetch() // returns [post2, post1]
For the moment being I just check whether surround returned something and if not I backfill it manually.
Not sure how useful this feature can be... _It is just my personal opinion_
Basically I would use this feature to display the previous and next article...
But the feature you requested will make things wiered...
If I am previewing the last article then the up next would be the first article ever..
Wouldn't that be misleading information ??
Also what if there is only 1 or 2 articles in total (_Most likely such things won't happen but think of it_)
If there is only 1 article your current, up next and the previous one would be the same...
Other than my personal opinions above, it is completely upto the developers to make the decision and pass the decision :smile:
Hey @LukaszRados,
Thank you for your suggestion, however I think this is a bit too specific to include in this module for now.
You could use a workaround by selecting how many prev and next you want in the surround options:
const [prev1, prev2, next1, next2] = await this.$content('articles')
.surround('slug', { before: 2, after: 2 })
.fetch()
Hi @benjamincanac,
it makes sense, thanks for having a look :)
Most helpful comment
Not sure how useful this feature can be... _It is just my personal opinion_
Basically I would use this feature to display the previous and next article...
But the feature you requested will make things wiered...
If I am previewing the last article then the
up nextwould be the first article ever..Wouldn't that be misleading information ??
Also what if there is only 1 or 2 articles in total (_Most likely such things won't happen but think of it_)
If there is only 1 article your current, up next and the previous one would be the same...
Other than my personal opinions above, it is completely upto the developers to make the decision and pass the decision :smile: