Skip to content

Commit 376ba0a

Browse files
committed
[CM2] Fix linking prev/next posts
By not calling it for the default category after pushing to it every time.
1 parent f72e56f commit 376ba0a

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,19 @@ function parseContent(node, content) {
2424

2525
function linkPosts(post, postIndex, posts) {
2626
post.links = post.links || {}
27-
if (postIndex > 0) {
27+
28+
const nextPost = posts[postIndex - 1]
29+
if (nextPost) {
2830
post.links.nextPost = {
29-
title: posts[postIndex - 1].title,
30-
permalink: posts[postIndex - 1].permalink
31+
title: nextPost.title,
32+
permalink: nextPost.permalink
3133
}
3234
}
33-
if (postIndex < posts.length - 1) {
35+
const previousPost = posts[postIndex + 1]
36+
if (previousPost) {
3437
post.links.previousPost = {
35-
title: posts[postIndex + 1].title,
36-
permalink: posts[postIndex + 1].permalink
38+
title: previousPost.title,
39+
permalink: previousPost.permalink
3740
}
3841
}
3942
}
@@ -59,8 +62,6 @@ module.exports = function Category(settings = defaultSettings, contentTypes, lev
5962
}
6063

6164
return {
62-
linkPosts,
63-
6465
match: (node) => node.children?.find(childNode => {
6566
const containsPosts = childModels.post.match(childNode)
6667
if (level > 3) {

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ module.exports = function Collection(settings = defaultSettings, contentTypes =
9999
childModels.post.createFromData(postData, postContext)
100100
defaultCategory.levelPosts.push(uncategorizedPost)
101101
defaultCategory.posts.push(uncategorizedPost)
102-
defaultCategory.posts.forEach(childModels.category.linkPosts)
103102
tree.posts.push(uncategorizedPost)
104103
}
105104

0 commit comments

Comments
 (0)