Skip to content

✨ Prev & next post filtering, with primary tag support#9141

Merged
kevinansfield merged 13 commits intoTryGhost:masterfrom
ErisDS:prev-next
Oct 13, 2017
Merged

✨ Prev & next post filtering, with primary tag support#9141
kevinansfield merged 13 commits intoTryGhost:masterfrom
ErisDS:prev-next

Conversation

@ErisDS
Copy link
Copy Markdown
Member

@ErisDS ErisDS commented Oct 12, 2017

Replace prev & next logic with the filter param, add new "in" option to support next and preivous post within primary tags.

closes #9140


This PR introduces a breaking change to the JSON API, removing the undocumented ability to fetch next/prev post directly using includes. Instead, anyone who did use this feature would need to use the filter param instead:

Previous post query: /posts/?filter=slug:-[current-post-slug]+published_at:<='current-post-published-at'&order=published_at desc&limit=1
Next post query: /posts/?filter="slug:-[current-post-slug]+published_at:>='current-post-published-at'&order=published_at asc&limit=1

Meanwhile, the widely used {{#next_post}}{{/next_post}} & {{#prev_post}}{{/prev_post}} helpers will work exactly as they did before, with no changes. The underlying implementation will be more efficient (hopefully improving page load times and reducing load on the database).

Finally, we're adding an extra parameter to the{{#next_post}}{{/next_post}} & {{#prev_post}}{{/prev_post}} to support fetching the next/prev post inside of a primary tag.

{{#next_post in="primary_tag"}}
      {{> "post-card"}}
{{/next_post}}

{{#prev_post in="primary_tag"}}
       {{> "post-card"}}
{{/prev_post}}

Things that need more testing:

  • does it work properly on sqlite3 vs mysql
  • is the order correct?
  • does it still properly filter out pages, and drafts, etc

return apiOptions;
};

fetch = function fetch(options, data) {

This comment was marked as abuse.

@ErisDS ErisDS changed the title [WIP] Prev / Next 2.0 Prev / Next 2.0 Oct 13, 2017
@ErisDS ErisDS changed the title Prev / Next 2.0 ✨ Prev & next post filtering, with in primary tag support Oct 13, 2017
@ErisDS ErisDS changed the title ✨ Prev & next post filtering, with in primary tag support ✨ Prev & next post filtering, with primary tag support Oct 13, 2017
return fetch(apiOptions, options, data);
} else {
// Guard against trying to execute prev/next on previews, pages, or other resources
if (!isPost(this) || this.status !== 'published') {

This comment was marked as abuse.

This comment was marked as abuse.

This comment was marked as abuse.

return encodeURIComponent("published_at:" + op + "'" + publishedAt + "'"); // jscs:ignore
}

request.get(testUtils.API.getApiQuery(

This comment was marked as abuse.

This comment was marked as abuse.

This comment was marked as abuse.

@kevinansfield kevinansfield merged commit 1c38279 into TryGhost:master Oct 13, 2017
@kevinansfield kevinansfield deleted the prev-next branch October 13, 2017 14:44
ErisDS pushed a commit that referenced this pull request Oct 18, 2017
refs #9141

- adds support for `{{#prev_post in="author"}}{{/prev_post}}` & `{{#next_post in="author"}}{{/next_post}}` 
- "author.slug" is the author equivalent of "primary_tag.slug" - there is only one
- added tests to cover both cases in the prev/next helpers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Prev & Next 2.0: refactor & primary tag support

3 participants