Skip to content

Commit 73e307e

Browse files
committed
[CM2] Link posts in category not collection
It doesn't make sense to see a different category's post as the next or previous post link. Also collections handle linking default category's posts
1 parent 6411d65 commit 73e307e

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/compiler/contentModel2/models/collection/category.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,22 @@ function parseContent(node, content) {
1818
function category(node, context) {
1919
const settings = Settings.getSettings()
2020

21+
function linkPosts(post, postIndex, posts) {
22+
post.links = {}
23+
if (postIndex > 0) {
24+
post.links.nextPost = {
25+
title: posts[postIndex - 1].title,
26+
permalink: posts[postIndex - 1].permalink
27+
}
28+
}
29+
if (postIndex < posts.length - 1) {
30+
post.links.previousPost = {
31+
title: posts[postIndex + 1].title,
32+
permalink: posts[postIndex + 1].permalink
33+
}
34+
}
35+
}
36+
2137
if (node.isDefaultCategory) {
2238
return {
2339
context,
@@ -94,6 +110,7 @@ function category(node, context) {
94110
})
95111

96112
tree.posts.sort((a, b) => b.date - a.date)
113+
tree.posts.forEach(linkPosts)
97114

98115
const contentRaw = indexProps.content || ''
99116
const content = indexFile ?

src/compiler/contentModel2/models/collection/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ function collection(node) {
3535
})
3636
}
3737

38-
function attachLinks(post, postIndex, posts) {
38+
function linkPosts(post, postIndex, posts) {
3939
post.links = {}
4040
if (postIndex > 0) {
4141
post.links.nextPost = {
@@ -62,6 +62,7 @@ function collection(node) {
6262
category: _.omit(defaultCategory, ['posts', 'context', 'content', 'attachments'])
6363
})
6464
defaultCategory.posts.push(uncategorizedPost)
65+
defaultCategory.posts.forEach(linkPosts)
6566
tree.posts.push(uncategorizedPost)
6667
}
6768

@@ -113,7 +114,6 @@ function collection(node) {
113114
tree.posts.sort((a, b) => b.date - a.date)
114115
tree.posts.forEach((post, i, posts) => {
115116
collectPostTags(post)
116-
attachLinks(post, i, posts)
117117
})
118118

119119
const contentRaw = indexProps.content || ''

0 commit comments

Comments
 (0)