@@ -165,7 +165,19 @@ module.exports = class Page {
165
165
*/
166
166
167
167
get slug ( ) {
168
- return slugify ( this . strippedFilename )
168
+ const strippedFilename = this . strippedFilename
169
+
170
+ if ( / ^ ( i n d e x | r e a d m e ) $ / i. test ( strippedFilename ) ) {
171
+ const strippedFilename = this . stripFilename (
172
+ path . basename ( path . dirname ( this . _filePath || this . regularPath ) )
173
+ )
174
+
175
+ if ( strippedFilename ) {
176
+ return slugify ( strippedFilename )
177
+ }
178
+ }
179
+
180
+ return slugify ( strippedFilename )
169
181
}
170
182
171
183
/**
@@ -179,8 +191,7 @@ module.exports = class Page {
179
191
*/
180
192
181
193
get strippedFilename ( ) {
182
- const match = this . filename . match ( DATE_RE )
183
- return match ? match [ 3 ] : this . filename
194
+ return this . stripFilename ( this . filename )
184
195
}
185
196
186
197
/**
@@ -194,6 +205,22 @@ module.exports = class Page {
194
205
return inferDate ( this . frontmatter , this . filename )
195
206
}
196
207
208
+ /**
209
+ * stripped file name.
210
+ *
211
+ * If filename was yyyy-MM-dd-[title], the date prefix will be stripped.
212
+ * If filename was yyyy-MM-[title], the date prefix will be stripped.
213
+ *
214
+ * @param {string } fileName
215
+ * @returns {string }
216
+ * @private
217
+ */
218
+ stripFilename ( fileName ) {
219
+ const match = fileName . match ( DATE_RE )
220
+
221
+ return match ? match [ 3 ] : fileName
222
+ }
223
+
197
224
/**
198
225
* Convert page's metadata to JSON, note that all fields beginning
199
226
* with an underscore will not be serialized.
0 commit comments