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:
@@ -2,7 +2,7 @@
|
||||
// source, translations and related post bodies stay out of it.
|
||||
import { test } from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import { toPostView } from '../app/utils/postView.ts'
|
||||
import { postNeighbours, toPostView } from '../app/utils/postView.ts'
|
||||
import type { JournalPost, JournalPostDetail } from '../app/utils/types.ts'
|
||||
|
||||
function post(overrides: Partial<JournalPost> = {}): JournalPost {
|
||||
@@ -53,3 +53,12 @@ test('source, translations and related post bodies stay out of the payload', ()
|
||||
test('a missing body becomes an empty string', () => {
|
||||
assert.equal(toPostView(detail({ content_html: null })).content_html, '')
|
||||
})
|
||||
|
||||
test('postNeighbours prefers the in-category neighbours when the Journal answers one', () => {
|
||||
const site = { previous_post: { slug: 'p', title: 'P' }, next_post: { slug: 'n', title: 'N' } }
|
||||
assert.deepEqual(postNeighbours(site), { previous: site.previous_post, next: site.next_post, inCategory: false })
|
||||
assert.deepEqual(postNeighbours({ ...site, previous_in_category: null, next_in_category: null }), { previous: site.previous_post, next: site.next_post, inCategory: false })
|
||||
const cat = { slug: 'c', title: 'C' }
|
||||
assert.deepEqual(postNeighbours({ ...site, previous_in_category: null, next_in_category: cat }), { previous: null, next: cat, inCategory: true })
|
||||
assert.deepEqual(postNeighbours({}), { previous: null, next: null, inCategory: false })
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user