Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(content-docs): quotify path when retrieving git history #6202

Merged
merged 2 commits into from
Dec 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Hoo hoo, if this path tricks you...
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ These sidebar document ids do not exist:
- goku

Available document ids are:
- doc with space
- foo/bar
- foo/baz
- headingAsTitle
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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\\",
Expand Down Expand Up @@ -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\\",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
4 changes: 2 additions & 2 deletions packages/docusaurus-plugin-content-docs/src/lastUpdate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
1 change: 1 addition & 0 deletions website/_dogfooding/dogfooding.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}),
],

Expand Down