From 41750667cd74b66c2bdde00619d290fc293a01d3 Mon Sep 17 00:00:00 2001 From: Glavin Wiechert Date: Sun, 11 Feb 2018 20:43:37 -0400 Subject: [PATCH] Allow edit URL to be customized with doc metadata (#443) --- docs/api-doc-markdown.md | 12 ++++++++++++ lib/core/Doc.js | 10 +++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/docs/api-doc-markdown.md b/docs/api-doc-markdown.md index 05e795149f1e..4c2b7fe33b16 100644 --- a/docs/api-doc-markdown.md +++ b/docs/api-doc-markdown.md @@ -38,6 +38,18 @@ original_id: doc1 --- ``` +`custom_edit_url`: The url for editing this document. If this field is not present, the document's edit url will fallback to `editUrl` from optional fields of `siteConfig.js`. See [siteConfig.js](site-config.md) docs for more information. + +For example: + +```markdown +--- +id: doc-markdown +title: Markdown Features +custom_edit_url: https://github.com/facebook/Docusaurus/edit/master/docs/api-doc-markdown.md +--- +``` + ### Blog Posts Blog Posts use the following markdown header fields that are enclosed by a line `---` on either side: diff --git a/lib/core/Doc.js b/lib/core/Doc.js index b08d8e69977d..06b76e941854 100644 --- a/lib/core/Doc.js +++ b/lib/core/Doc.js @@ -27,11 +27,11 @@ class Doc extends React.Component { docSource = docSource.match(new RegExp(/version-.*\/(.*\.md)/, 'i'))[1]; } - let editLink = this.props.config.editUrl && ( - + const editUrl = + this.props.metadata.custom_edit_url || + (this.props.config.editUrl && this.props.config.editUrl + docSource); + let editLink = editUrl && ( + {editThisDoc} );