feat: category neighbours on the post page
The post page links previous_in_category and next_in_category (the Journal's opt-in scored related mode) as server-rendered links with the title in the anchor text when the Journal answers one, else the site-wide previous_post and next_post (postNeighbours). Types, a fixture post and expectation lines for both cases.
This commit is contained in:
@@ -15,6 +15,24 @@ export function demotesH1(post: { content_h1_to_h2?: boolean | null } | null | u
|
||||
return post?.content_h1_to_h2 !== false
|
||||
}
|
||||
|
||||
/**
|
||||
* The previous and next links of a post page: the neighbours within the
|
||||
* post's first category when the Journal answers them (its opt-in scored
|
||||
* mode) and at least one exists, else the site-wide previous_post and
|
||||
* next_post.
|
||||
*/
|
||||
export function postNeighbours(post: {
|
||||
previous_post?: { slug: string; title: string } | null
|
||||
next_post?: { slug: string; title: string } | null
|
||||
previous_in_category?: { slug: string; title: string } | null
|
||||
next_in_category?: { slug: string; title: string } | null
|
||||
}): { previous: { slug: string; title: string } | null; next: { slug: string; title: string } | null; inCategory: boolean } {
|
||||
if (post.previous_in_category || post.next_in_category) {
|
||||
return { previous: post.previous_in_category ?? null, next: post.next_in_category ?? null, inCategory: true }
|
||||
}
|
||||
return { previous: post.previous_post ?? null, next: post.next_post ?? null, inCategory: false }
|
||||
}
|
||||
|
||||
/** A post page's data: the post with its body sanitized and no source or translations. */
|
||||
export type JournalPostView = JournalPostDetail
|
||||
|
||||
|
||||
@@ -75,8 +75,19 @@ export interface JournalPostSibling {
|
||||
export interface JournalPostDetail extends JournalPost {
|
||||
previous_post: JournalPostSibling | null
|
||||
next_post: JournalPostSibling | null
|
||||
/** Latest 3 in the same categories; empty when the post has no category. */
|
||||
/**
|
||||
* Latest 3 in the same categories (empty when the post has no category);
|
||||
* with the Journal's related_mode scored, 3 to 6 ranked by shared tags
|
||||
* and categories.
|
||||
*/
|
||||
related_posts: JournalPost[]
|
||||
/**
|
||||
* The neighbours by publish time within the post's first category, in
|
||||
* the direction of previous_post and next_post. Only with the Journal's
|
||||
* opt-in related_mode scored; absent otherwise.
|
||||
*/
|
||||
previous_in_category?: JournalPostSibling | null
|
||||
next_in_category?: JournalPostSibling | null
|
||||
/**
|
||||
* The Journal H1 setting (newer Journal APIs): true while stored
|
||||
* content has its H1 headings converted to H2, so the post title is the
|
||||
|
||||
Reference in New Issue
Block a user