Skip to content

Commit c097f9f

Browse files
committed
Fix entryAlias not working in uncategorized post
In ContentModelEntryNode, use getIndexFile template method to set this.indexFile (and not this.subtree.indexFile). Once the indexFile is set and its content and frontmatter is parsed, continue calling other template methods, importantly, getSubtreeMatchers. After switching to use matcha expressions in matchers, they got out of their function wrappers. So, if they wanted to refer to this properties coming from front-matter, getSubtreeMatchers must have been called in super after indexFile is parsed. This change does just that. Setting this.indexFile instead of this.subtree.indexFile is for the coherence. If indexFile remained under 'subtree', then it would be confusing why its matcher is not in the getSubtreeMatchers. It feels right to have it directly in 'this'. Also add a missing edge-case to e2e-magazine: Uncategorized foldered post with an aliased indexFile. Lack of this test so far was what allowed this bug to hide so far.
1 parent 5b8db29 commit c097f9f

File tree

8 files changed

+87
-39
lines changed

8 files changed

+87
-39
lines changed

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,13 @@ class Category extends ContentModelEntryNode {
9393
})
9494
}
9595

96+
getIndexFile() {
97+
return this.fsNode.children?.find(
98+
matcha.templateFile({
99+
nameOptions: [this.settings.categoryAlias, 'category']
100+
})
101+
) || this.fsNode
102+
}
96103

97104
getPermalink() {
98105
if (this.fsNode.isDefaultCategory) {
@@ -112,10 +119,6 @@ class Category extends ContentModelEntryNode {
112119
})
113120

114121
return {
115-
indexFile: matcha.templateFile({
116-
nameOptions: [this.settings.categoryAlias, 'category']
117-
}),
118-
119122
category: matcha.directory({
120123
childSearchDepth: 3,
121124
children: [ postMatcher ]
@@ -129,7 +132,6 @@ class Category extends ContentModelEntryNode {
129132

130133
parseSubtree() {
131134
const tree = {
132-
indexFile: this.indexFile,
133135
categories: [],
134136
posts: [],
135137
levelPosts: [],
@@ -153,7 +155,7 @@ class Category extends ContentModelEntryNode {
153155
})
154156

155157
this.fsNode.children.forEach(childNode => {
156-
if (this.matchers.indexFile(childNode)) {
158+
if (childNode === this.indexFile) {
157159
return
158160
}
159161

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,14 @@ class Collection extends ContentModelEntryNode {
8181
this.subtree = this.parseSubtree()
8282
}
8383

84+
getIndexFile() {
85+
return this.fsNode.children.find(
86+
matcha.templateFile({
87+
nameOptions: this.settings.collectionAliases.concat('collection')
88+
})
89+
)
90+
}
91+
8492
getSlug() {
8593
return this.__originalAttributes__.slug === null ?
8694
'' :
@@ -103,10 +111,6 @@ class Collection extends ContentModelEntryNode {
103111
})
104112

105113
return {
106-
indexFile: matcha.templateFile({
107-
nameOptions: (this.settings.collectionAliases || []).concat('collection').filter(Boolean)
108-
}),
109-
110114
dataFile: matcha.dataFile({
111115
nameOptions: [this.fsNode.name]
112116
}),
@@ -124,7 +128,6 @@ class Collection extends ContentModelEntryNode {
124128

125129
parseSubtree() {
126130
const tree = {
127-
indexFile: this.indexFile,
128131
categories: [],
129132
posts: [],
130133
levelPosts: [],
@@ -140,7 +143,7 @@ class Collection extends ContentModelEntryNode {
140143
})
141144

142145
this.fsNode.children.forEach(childNode => {
143-
if (this.matchers.indexFile(childNode)) {
146+
if (childNode === this.indexFile) {
144147
return
145148
}
146149

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,22 @@ class Post extends ContentModelEntryNode {
3131
this.subtree = this.parseSubtree()
3232
}
3333

34-
getSubtreeMatchers() {
35-
return {
36-
indexFile: matcha.templateFile({
34+
getIndexFile() {
35+
return this.fsNode.children?.find(
36+
matcha.templateFile({
3737
nameOptions: [this.settings.entryAlias, 'post', 'index']
38-
}),
38+
})
39+
) || this.fsNode
40+
}
3941

42+
getSubtreeMatchers() {
43+
return {
4044
attachment: matcha.true()
4145
}
4246
}
4347

4448
parseSubtree() {
4549
const tree = {
46-
indexFile: this.fsNode,
4750
attachments: []
4851
}
4952

@@ -60,7 +63,7 @@ class Post extends ContentModelEntryNode {
6063
})
6164

6265
this.fsNode.children.forEach(childNode => {
63-
if (this.matchers.indexFile(childNode)) {
66+
if (childNode === this.indexFile) {
6467
return
6568
}
6669
if (this.matchers.attachment(childNode)) {

src/compiler/contentModel/models/homepage.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ class Homepage extends ContentModelEntryNode {
2323
this.subtree = this.parseSubtree()
2424
}
2525

26+
getIndexFile() {
27+
return this.fsNode.children?.find(
28+
matcha.templateFile({
29+
nameOptions: ['homepage', 'home', 'index']
30+
})
31+
) || this.fsNode
32+
}
33+
2634
getPermalink() {
2735
return this.context.peek().permalink
2836
}
@@ -33,17 +41,12 @@ class Homepage extends ContentModelEntryNode {
3341

3442
getSubtreeMatchers() {
3543
return {
36-
indexFile: matcha.templateFile({
37-
nameOptions: ['homepage', 'home', 'index']
38-
}),
39-
4044
attachment: matcha.true()
4145
}
4246
}
4347

4448
parseSubtree() {
4549
const tree = {
46-
indexFile: this.fsNode,
4750
attachments: []
4851
}
4952

@@ -61,7 +64,7 @@ class Homepage extends ContentModelEntryNode {
6164
}
6265

6366
this.fsNode.children.forEach(childNode => {
64-
if (this.matchers.indexFile(childNode)) {
67+
if (childNode === this.indexFile) {
6568
return
6669
}
6770
if (this.matchers.attachment(childNode)) {

src/compiler/contentModel/models/subpage.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,22 @@ class Subpage extends ContentModelEntryNode {
2323
this.subtree = this.parseSubtree()
2424
}
2525

26-
getSubtreeMatchers() {
27-
return {
28-
indexFile: matcha.templateFile({
26+
getIndexFile() {
27+
return this.fsNode.children?.find(
28+
matcha.templateFile({
2929
nameOptions: ['page', 'index']
30-
}),
30+
})
31+
) || this.fsNode
32+
}
3133

34+
getSubtreeMatchers() {
35+
return {
3236
attachment: matcha.true()
3337
}
3438
}
3539

3640
parseSubtree() {
3741
const tree = {
38-
indexFile: this.fsNode,
3942
attachments: []
4043
}
4144

@@ -52,7 +55,7 @@ class Subpage extends ContentModelEntryNode {
5255
})
5356

5457
this.fsNode.children.forEach(childNode => {
55-
if (this.matchers.indexFile(childNode)) {
58+
if (childNode === this.indexFile) {
5659
return
5760
}
5861
if (this.matchers.attachment(childNode)) {
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
date: 2025-12-06
3+
maker: +authors/enes
4+
tags: [html, hey world]
5+
---
6+
<h1>Hey world</h1>
7+
8+
<p>Adipisicing nesciunt ab quos eos nesciunt Nemo ab aliquid quod magnam eaque voluptatem. Possimus tenetur veniam nostrum magnam in? Ipsa atque cupiditate illum hic mollitia Soluta excepturi vel consequatur exercitationem.</p>

src/e2e-tests/magazine/fixtures/model.js

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,8 @@ const FIXTURE_CONTENT_MODEL = {
296296
slug: 'intelligent-drum-n-bass',
297297
permalink: '/demos/threejs/intelligent-drum-n-bass'
298298
},
299-
{ title: 'Hello World', slug: 'hello-world', permalink: '/demos/hello-world' }
299+
{ title: 'Hello World', slug: 'hello-world', permalink: '/demos/hello-world' },
300+
{ title: 'Hey World', slug: 'hey-world', permalink: '/demos/hey-world' }
300301
],
301302
articles: [
302303
{
@@ -906,6 +907,29 @@ const FIXTURE_CONTENT_MODEL = {
906907
}
907908
}
908909
},
910+
{
911+
title: 'Hey World',
912+
maker: { title: 'Mustafa Enes', slug: 'enes' },
913+
date: '2025-12-06',
914+
permalink: '/demos/hey-world',
915+
contentType: 'Demo',
916+
tags: ['html', 'hey world'],
917+
content: '<h1>Hey world</h1>\n\n<p>Adipisicing nesciunt ab quos eos nesciunt Nemo ab aliquid quod magnam eaque voluptatem. Possimus tenetur veniam nostrum magnam in? Ipsa atque cupiditate illum hic mollitia Soluta excepturi vel consequatur exercitationem.</p>',
918+
context: {
919+
collection: {
920+
title: 'demos',
921+
permalink: '/demos'
922+
},
923+
categories: []
924+
},
925+
links: {
926+
nextPost: null,
927+
previousPost: {
928+
title: 'good-morning-world',
929+
permalink: '/demos/good-morning-world.html'
930+
}
931+
}
932+
},
909933
{
910934
title: 'good-morning-world',
911935
maker: { title: 'Sir Tim Berners Lee', slug: 'tim' },
@@ -926,7 +950,10 @@ const FIXTURE_CONTENT_MODEL = {
926950
title: 'Hello World',
927951
permalink: '/demos/hello-world'
928952
},
929-
nextPost: null
953+
nextPost: {
954+
title: 'Hey World',
955+
permalink: '/demos/hey-world'
956+
}
930957
}
931958
}
932959
]
@@ -1060,4 +1087,4 @@ const FIXTURE_CONTENT_MODEL = {
10601087
module.exports = {
10611088
FIXTURE_SETTINGS,
10621089
FIXTURE_CONTENT_MODEL
1063-
}
1090+
}

src/lib/ContentModelEntryNode.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,12 @@ class ContentModelEntryNode extends ContentModelNode {
88
constructor(fsNode, context, settings = {}) {
99
super(fsNode, context, settings)
1010

11-
this.matchers = this.getSubtreeMatchers()
12-
this.subtree = {
13-
indexFile: this.getIndexFile()
14-
}
11+
this.indexFile = this.getIndexFile()
1512

1613
const isFlatData = !fsNode.stats?.birthtime
1714
const entryProperties = parseTextEntry(
1815
this.fsNode,
19-
this.subtree.indexFile || this.fsNode,
16+
this.indexFile || this.fsNode,
2017
isFlatData
2118
)
2219

@@ -25,10 +22,12 @@ class ContentModelEntryNode extends ContentModelNode {
2522
this.slug = this.getSlug()
2623
this.permalink = this.getPermalink()
2724
this.outputPath = this.getOutputPath()
25+
this.matchers = this.getSubtreeMatchers()
26+
this.subtree = {}
2827
}
2928

3029
getIndexFile() {
31-
return this.fsNode.children?.find(this.matchers.indexFile) || this.fsNode
30+
return this.fsNode
3231
}
3332

3433
getSlug() {

0 commit comments

Comments
 (0)