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:
Héctor Ramos 2017-12-05 15:44:14 -08:00 committed by Joel Marcey
parent 80fc8169b7
commit 97612cf20b
2 changed files with 29 additions and 18 deletions

View file

@ -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={

View file

@ -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">