mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-22 12:37:58 +02:00
feat(v2): add editUrl option to docs plugin (#1818)
* feat(v2): add editUrl option to docs plugin * nits * misc(v2): nit * misc(v2): nit
This commit is contained in:
parent
aba9edc12c
commit
ae678c9dad
10 changed files with 66 additions and 6 deletions
|
@ -60,4 +60,28 @@ describe('processMetadata', () => {
|
|||
description: 'This has a different permalink',
|
||||
});
|
||||
});
|
||||
|
||||
test('docs with editUrl', async () => {
|
||||
const editUrl =
|
||||
'https://github.com/facebook/docusaurus/edit/master/website/docs/';
|
||||
const source = path.join('foo', 'baz.md');
|
||||
const data = await processMetadata(
|
||||
source,
|
||||
docsDir,
|
||||
{},
|
||||
siteConfig,
|
||||
pluginPath,
|
||||
siteDir,
|
||||
editUrl,
|
||||
);
|
||||
expect(data).toEqual({
|
||||
id: 'foo/baz',
|
||||
permalink: '/docs/foo/baz',
|
||||
source: path.join('@site', pluginPath, source),
|
||||
title: 'baz',
|
||||
editUrl:
|
||||
'https://github.com/facebook/docusaurus/edit/master/website/docs/foo/baz.md',
|
||||
description: '## Images',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -62,7 +62,7 @@ export default function pluginContentDocs(
|
|||
|
||||
// Fetches blog contents and returns metadata for the contents.
|
||||
async loadContent() {
|
||||
const {include, routeBasePath, sidebarPath} = options;
|
||||
const {include, routeBasePath, sidebarPath, editUrl} = options;
|
||||
const {siteConfig, siteDir} = context;
|
||||
const docsDir = contentPath;
|
||||
|
||||
|
@ -93,6 +93,7 @@ export default function pluginContentDocs(
|
|||
siteConfig,
|
||||
routeBasePath,
|
||||
siteDir,
|
||||
editUrl,
|
||||
);
|
||||
docsMetadataRaw[metadata.id] = metadata;
|
||||
}),
|
||||
|
|
|
@ -18,6 +18,7 @@ export default async function processMetadata(
|
|||
siteConfig: Partial<DocusaurusConfig>,
|
||||
docsBasePath: string,
|
||||
siteDir: string,
|
||||
editUrl?: string,
|
||||
): Promise<MetadataRaw> {
|
||||
const filepath = path.join(docsDir, source);
|
||||
|
||||
|
@ -82,5 +83,9 @@ export default async function processMetadata(
|
|||
}
|
||||
}
|
||||
|
||||
if (editUrl) {
|
||||
metadata.editUrl = normalizeUrl([editUrl, source]);
|
||||
}
|
||||
|
||||
return metadata as MetadataRaw;
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ export interface PluginOptions {
|
|||
docItemComponent: string;
|
||||
remarkPlugins: string[];
|
||||
rehypePlugins: string[];
|
||||
editUrl?: string;
|
||||
}
|
||||
|
||||
export type SidebarItemDoc = {
|
||||
|
@ -88,6 +89,7 @@ export interface MetadataRaw extends OrderMetadata {
|
|||
source: string;
|
||||
permalink: string;
|
||||
sidebar_label?: string;
|
||||
editUrl?: string;
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue