diff --git a/packages/docusaurus-plugin-content-docs/src/__tests__/__fixtures__/simple-site/docs/doc with space.md b/packages/docusaurus-plugin-content-docs/src/__tests__/__fixtures__/simple-site/docs/doc with space.md new file mode 100644 index 0000000000..2b2a616da3 --- /dev/null +++ b/packages/docusaurus-plugin-content-docs/src/__tests__/__fixtures__/simple-site/docs/doc with space.md @@ -0,0 +1 @@ +# Hoo hoo, if this path tricks you... diff --git a/packages/docusaurus-plugin-content-docs/src/__tests__/__snapshots__/docs.test.ts.snap b/packages/docusaurus-plugin-content-docs/src/__tests__/__snapshots__/docs.test.ts.snap index a6a50483c1..d8ad2b8a3e 100644 --- a/packages/docusaurus-plugin-content-docs/src/__tests__/__snapshots__/docs.test.ts.snap +++ b/packages/docusaurus-plugin-content-docs/src/__tests__/__snapshots__/docs.test.ts.snap @@ -2,6 +2,13 @@ exports[`simple site custom pagination 1`] = ` Array [ + Array [ + undefined, + Object { + "permalink": "/docs/headingAsTitle", + "title": "My heading as title", + }, + ], Array [ undefined, undefined, @@ -17,7 +24,10 @@ Array [ }, ], Array [ - undefined, + Object { + "permalink": "/docs/doc with space", + "title": "Hoo hoo, if this path tricks you...", + }, Object { "permalink": "/docs/", "title": "Hello sidebar_label", diff --git a/packages/docusaurus-plugin-content-docs/src/__tests__/__snapshots__/index.test.ts.snap b/packages/docusaurus-plugin-content-docs/src/__tests__/__snapshots__/index.test.ts.snap index 5a1e7ed3b8..09fbc4a29e 100644 --- a/packages/docusaurus-plugin-content-docs/src/__tests__/__snapshots__/index.test.ts.snap +++ b/packages/docusaurus-plugin-content-docs/src/__tests__/__snapshots__/index.test.ts.snap @@ -6,6 +6,7 @@ These sidebar document ids do not exist: - goku Available document ids are: +- doc with space - foo/bar - foo/baz - headingAsTitle @@ -241,6 +242,11 @@ Object { "versions": Array [ Object { "docs": Array [ + Object { + "id": "doc with space", + "path": "/docs/doc with space", + "sidebar": undefined, + }, Object { "id": "foo/bar", "path": "/docs/foo/bar", @@ -326,6 +332,19 @@ Object { exports[`simple website content: data 1`] = ` Object { + "site-docs-doc-with-space-md-e90.json": "{ + \\"unversionedId\\": \\"doc with space\\", + \\"id\\": \\"doc with space\\", + \\"title\\": \\"Hoo hoo, if this path tricks you...\\", + \\"description\\": \\"\\", + \\"source\\": \\"@site/docs/doc with space.md\\", + \\"sourceDirName\\": \\".\\", + \\"slug\\": \\"/doc with space\\", + \\"permalink\\": \\"/docs/doc with space\\", + \\"tags\\": [], + \\"version\\": \\"current\\", + \\"frontMatter\\": {} +}", "site-docs-foo-bar-md-8c2.json": "{ \\"unversionedId\\": \\"foo/bar\\", \\"id\\": \\"foo/bar\\", @@ -811,6 +830,11 @@ Object { ] }, \\"docs\\": { + \\"doc with space\\": { + \\"id\\": \\"doc with space\\", + \\"title\\": \\"Hoo hoo, if this path tricks you...\\", + \\"description\\": \\"\\" + }, \\"foo/bar\\": { \\"id\\": \\"foo/bar\\", \\"title\\": \\"Bar\\", @@ -902,6 +926,11 @@ Object { "versions": Array [ Object { "docs": Array [ + Object { + "id": "doc with space", + "path": "/docs/doc with space", + "sidebar": undefined, + }, Object { "id": "foo/bar", "path": "/docs/foo/bar", @@ -1045,6 +1074,14 @@ Array [ }, "path": "/docs/absoluteSlug", }, + Object { + "component": "@theme/DocItem", + "exact": true, + "modules": Object { + "content": "@site/docs/doc with space.md", + }, + "path": "/docs/doc with space", + }, Object { "component": "@theme/DocItem", "exact": true, diff --git a/packages/docusaurus-plugin-content-docs/src/__tests__/docs.test.ts b/packages/docusaurus-plugin-content-docs/src/__tests__/docs.test.ts index 5237c4fffa..7bccd442d0 100644 --- a/packages/docusaurus-plugin-content-docs/src/__tests__/docs.test.ts +++ b/packages/docusaurus-plugin-content-docs/src/__tests__/docs.test.ts @@ -202,6 +202,7 @@ describe('simple site', () => { 'rootResolvedSlug.md', 'rootTryToEscapeSlug.md', 'headingAsTitle.md', + 'doc with space.md', 'foo/bar.md', 'foo/baz.md', 'slugs/absoluteSlug.md', diff --git a/packages/docusaurus-plugin-content-docs/src/__tests__/lastUpdate.test.ts b/packages/docusaurus-plugin-content-docs/src/__tests__/lastUpdate.test.ts index 53ffc3a27f..e1528f8c5c 100644 --- a/packages/docusaurus-plugin-content-docs/src/__tests__/lastUpdate.test.ts +++ b/packages/docusaurus-plugin-content-docs/src/__tests__/lastUpdate.test.ts @@ -28,6 +28,22 @@ describe('lastUpdate', () => { expect(typeof timestamp).toBe('number'); }); + test('existing test file with spaces in path', async () => { + const filePathWithSpace = path.join( + __dirname, + '__fixtures__/simple-site/docs/doc with space.md', + ); + const lastUpdateData = await getFileLastUpdate(filePathWithSpace); + expect(lastUpdateData).not.toBeNull(); + + const {author, timestamp} = lastUpdateData; + expect(author).not.toBeNull(); + expect(typeof author).toBe('string'); + + expect(timestamp).not.toBeNull(); + expect(typeof timestamp).toBe('number'); + }); + test('non-existing file', async () => { const consoleMock = jest.spyOn(console, 'error').mockImplementation(); const nonExistingFileName = '.nonExisting'; diff --git a/packages/docusaurus-plugin-content-docs/src/lastUpdate.ts b/packages/docusaurus-plugin-content-docs/src/lastUpdate.ts index c37e55bdb6..b78c4146c3 100644 --- a/packages/docusaurus-plugin-content-docs/src/lastUpdate.ts +++ b/packages/docusaurus-plugin-content-docs/src/lastUpdate.ts @@ -43,12 +43,12 @@ export async function getFileLastUpdate( return null; } - const result = shell.exec(`git log -1 --format=%ct,%an ${filePath}`, { + const result = shell.exec(`git log -1 --format=%ct,%an "${filePath}"`, { silent: true, }); if (result.code !== 0) { throw new Error( - `Retrieval of git history failed at ${filePath} with exit code ${result.code}: ${result.stderr}`, + `Retrieval of git history failed at "${filePath}" with exit code ${result.code}: ${result.stderr}`, ); } return getTimestampAndAuthor(result.stdout.trim()); diff --git a/website/_dogfooding/dogfooding.config.js b/website/_dogfooding/dogfooding.config.js index 56ae83b230..89eb42620b 100644 --- a/website/_dogfooding/dogfooding.config.js +++ b/website/_dogfooding/dogfooding.config.js @@ -20,6 +20,7 @@ const dogfoodingPluginInstances = [ // Using a symlinked folder as source, test for use-case https://github.com/facebook/docusaurus/issues/3272 // The target folder uses a _ prefix to test against an edge case regarding MDX partials: https://github.com/facebook/docusaurus/discussions/5181#discussioncomment-1018079 path: fs.realpathSync('_dogfooding/docs-tests-symlink'), + showLastUpdateTime: true, }), ],