Skip to content

Commit aad2eb4

Browse files
committed
Patternification
1 parent f7f6867 commit aad2eb4

File tree

5 files changed

+21
-41
lines changed

5 files changed

+21
-41
lines changed

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

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ class Category extends ContentModelEntryNode {
139139
attachments: []
140140
}
141141

142-
if (!this.fsNode.children || !this.fsNode.children.length) {
142+
if (this.isDefaultCategory) {
143143
return tree
144144
}
145145

@@ -155,11 +155,9 @@ class Category extends ContentModelEntryNode {
155155
key: contextKey
156156
})
157157

158-
this.fsNode.children.forEach(childNode => {
159-
if (childNode === this.indexFile) {
160-
return
161-
}
158+
const childNodes = this.fsNode.children.filter(node => node !== this.indexFile)
162159

160+
childNodes.forEach(childNode => {
163161
if (this.matchers.post(childNode)) {
164162
const postSettings = {
165163
entryAlias: this.entryAlias || this.settings.entryAlias,
@@ -319,10 +317,9 @@ class Category extends ContentModelEntryNode {
319317
)
320318
}
321319

322-
/*
323-
* Collection doesn't render uncategorized posts, so it must be done here.
324-
* An unnamed default category shouldn't render anything else. This way, we
325-
* avoid race conditions with collection's rendering in the same paths. */
320+
/* Uncategorized posts are rendered by the default category.
321+
* If default category is untitled, it should render only the posts.
322+
* Otherwise it'll race with collection to render at same outputPaths. */
326323
const isUntitledDefaultCategory = this.isDefaultCategory && !this.slug
327324
if (isUntitledDefaultCategory) {
328325
return renderPosts()

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,9 @@ class Collection extends ContentModelEntryNode {
143143
key: 'collection'
144144
})
145145

146-
this.fsNode.children.forEach(childNode => {
147-
if (childNode === this.indexFile) {
148-
return
149-
}
146+
const childNodes = this.fsNode.children.filter(node => node !== this.indexFile)
150147

148+
childNodes.forEach(childNode => {
151149
if (this.matchers.dataFile(childNode, this.fsNode)) {
152150
const data = JSON.parse(childNode.content || '[]')
153151
if (!Array.isArray(data)) {

src/compiler/contentModel/models/collection/post.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,6 @@ class Post extends ContentModelEntryNode {
5151
attachments: []
5252
}
5353

54-
if (!this.fsNode.children || !this.fsNode.children.length) {
55-
return tree
56-
}
57-
5854
const childContext = this.context.push({
5955
title: this.title,
6056
slug: this.slug,
@@ -63,10 +59,9 @@ class Post extends ContentModelEntryNode {
6359
key: 'post'
6460
})
6561

66-
this.fsNode.children.forEach(childNode => {
67-
if (childNode === this.indexFile) {
68-
return
69-
}
62+
const childNodes = (this.fsNode.children || []).filter(node => node !== this.indexFile)
63+
64+
childNodes.forEach(childNode => {
7065
if (this.matchers.attachment(childNode)) {
7166
tree.attachments.push(
7267
new models.Attachment(childNode, childContext)

src/compiler/contentModel/models/homepage.js

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,7 @@ class Homepage extends ContentModelEntryNode {
5151
attachments: []
5252
}
5353

54-
if (!this.fsNode.children || !this.fsNode.children.length) {
55-
return tree
56-
}
57-
58-
const context = {
54+
const childContext = {
5955
homepage: {
6056
title: this.title,
6157
slug: this.slug,
@@ -64,13 +60,12 @@ class Homepage extends ContentModelEntryNode {
6460
}
6561
}
6662

67-
this.fsNode.children.forEach(childNode => {
68-
if (childNode === this.indexFile) {
69-
return
70-
}
63+
const childNodes = (this.fsNode.children || []).filter(node => node !== this.indexFile)
64+
65+
childNodes.forEach(childNode => {
7166
if (this.matchers.attachment(childNode)) {
7267
tree.attachments.push(
73-
new models.Attachment(childNode, context)
68+
new models.Attachment(childNode, childContext)
7469
)
7570
}
7671
})

src/compiler/contentModel/models/subpage.js

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,25 +43,20 @@ class Subpage extends ContentModelEntryNode {
4343
attachments: []
4444
}
4545

46-
if (!this.fsNode.children || !this.fsNode.children.length) {
47-
return tree
48-
}
49-
50-
const context = this.context.push({
46+
const childContext = this.context.push({
5147
title: this.title,
5248
slug: this.slug,
5349
permalink: this.permalink,
5450
outputPath: this.outputPath,
5551
key: 'page'
5652
})
5753

58-
this.fsNode.children.forEach(childNode => {
59-
if (childNode === this.indexFile) {
60-
return
61-
}
54+
const childNodes = (this.fsNode.children || []).filter(node => node !== this.indexFile)
55+
56+
childNodes.forEach(childNode => {
6257
if (this.matchers.attachment(childNode)) {
6358
tree.attachments.push(
64-
new models.Attachment(childNode, context)
59+
new models.Attachment(childNode, childContext)
6560
)
6661
}
6762
})

0 commit comments

Comments
 (0)