Skip to content

Commit c50468c

Browse files
authored
chore: allow directories name to contain a dot (#673)
1 parent 1936a0e commit c50468c

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

packages/content/lib/database.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,16 @@ class Database extends Hookable {
252252
* @returns {string} Normalized path
253253
*/
254254
normalizePath (path) {
255-
return path.replace(this.dir, '').replace(/\.[^/.]+$/, '').replace(/\\/g, '/')
255+
let extractPath = path.replace(this.dir, '')
256+
const extensionPath = extractPath.substr(extractPath.lastIndexOf('.'))
257+
const additionalsExt = EXTENSIONS.concat(this.extendParserExtensions)
258+
259+
// Remove the extension from the path if contained at the end or starts with a dot
260+
if (additionalsExt.includes(extensionPath) || extractPath.startsWith('.')) {
261+
extractPath = extractPath.replace(/(?:\.([^.]+))?$/, '')
262+
}
263+
264+
return extractPath.replace(/\\/g, '/')
256265
}
257266

258267
/**
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
title: Title with dot
3+
---
4+
5+
This is a page which contains dot !

packages/content/test/server.test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,19 @@ describe('module', () => {
5353
]))
5454
})
5555

56+
test('$content() on directory with dot', async () => {
57+
const items = await $content('1.0').fetch()
58+
59+
expect(items).toEqual([
60+
expect.objectContaining({
61+
title: 'Title with dot',
62+
dir: '/1.0',
63+
path: '/1.0/index',
64+
slug: 'index'
65+
})
66+
])
67+
})
68+
5669
test('$content() on file', async () => {
5770
const item = await $content('home').fetch()
5871

0 commit comments

Comments
 (0)