mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-12 08:37:25 +02:00
Link to master version of doc when editing (#262)
* Ensure Edit this Doc links always point to the master source of truth, and not a particular version * Only show Edit this Doc link if editUrl has been set
This commit is contained in:
parent
80fc8169b7
commit
97612cf20b
2 changed files with 29 additions and 18 deletions
|
@ -20,18 +20,28 @@ const translateThisDoc = translate(
|
|||
// inner doc component for article itself
|
||||
class Doc extends React.Component {
|
||||
render() {
|
||||
let editLink = !this.props.version &&
|
||||
this.props.config.editUrl && (
|
||||
let docSource = this.props.source;
|
||||
|
||||
if (this.props.version && this.props.version !== 'next') {
|
||||
// If versioning is enabled and the current version is not next, we need to trim out "version-*" from the source if we want a valid edit link.
|
||||
docSource = docSource.match(new RegExp(/version-.*\/(.*\.md)/, 'i'))[1];
|
||||
}
|
||||
|
||||
let editLink = this.props.config.editUrl && (
|
||||
<a
|
||||
className="edit-page-link button"
|
||||
href={this.props.config.editUrl + this.props.source}
|
||||
href={this.props.config.editUrl + docSource}
|
||||
target="_blank">
|
||||
{editThisDoc}
|
||||
</a>
|
||||
);
|
||||
if (this.props.language != 'en') {
|
||||
editLink = !this.props.version &&
|
||||
this.props.config.translationRecruitingLink && (
|
||||
|
||||
// If internationalization is enabled, show Recruiting link instead of Edit Link.
|
||||
if (
|
||||
this.props.language != 'en' &&
|
||||
this.props.config.translationRecruitingLink
|
||||
) {
|
||||
editLink = (
|
||||
<a
|
||||
className="edit-page-link button"
|
||||
href={
|
||||
|
|
|
@ -52,6 +52,7 @@ class DocsLayout extends React.Component {
|
|||
this.props.metadata.title
|
||||
: this.props.metadata.title
|
||||
}
|
||||
version={metadata.version}
|
||||
language={metadata.language}
|
||||
/>
|
||||
<div className="docs-prevnext">
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue