feat(v2): allow per-doc hiding of edit url (#2166)

This commit is contained in:
Yangshun Tay 2020-01-01 18:45:55 +08:00 committed by GitHub
parent 428e087eb7
commit 75f5bb4d23
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 42 additions and 1 deletions

View file

@ -0,0 +1,5 @@
---
custom_edit_url: null
---
Lorem ipsum.

View file

@ -84,6 +84,14 @@ Array [
},
"path": "/docs/hello",
},
Object {
"component": "@theme/DocItem",
"exact": true,
"modules": Object {
"content": "@site/docs/ipsum.md",
},
"path": "/docs/ipsum",
},
Object {
"component": "@theme/DocItem",
"exact": true,

View file

@ -143,6 +143,34 @@ describe('simple site', () => {
});
});
test('docs with null custom_edit_url', async () => {
const source = 'ipsum.md';
const options = {
routeBasePath,
showLastUpdateAuthor: true,
showLastUpdateTime: true,
};
const data = await processMetadata({
source,
refDir: docsDir,
context,
options,
env,
});
expect(data).toEqual({
id: 'ipsum',
permalink: '/docs/ipsum',
source: path.join('@site', routeBasePath, source),
title: 'ipsum',
editUrl: null,
description: 'Lorem ipsum.',
lastUpdatedAt: 1539502055,
lastUpdatedBy: 'Author',
});
});
test('docs with invalid id', async () => {
const badSiteDir = path.join(fixtureDir, 'bad-site');
const options = {

View file

@ -134,7 +134,7 @@ export default async function processMetadata({
description,
source: aliasedSitePath(filePath, siteDir),
permalink,
editUrl: custom_edit_url || docsEditUrl,
editUrl: custom_edit_url !== undefined ? custom_edit_url : docsEditUrl,
version,
lastUpdatedBy,
lastUpdatedAt,