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,29 +20,39 @@ const translateThisDoc = translate(
|
||||||
// inner doc component for article itself
|
// inner doc component for article itself
|
||||||
class Doc extends React.Component {
|
class Doc extends React.Component {
|
||||||
render() {
|
render() {
|
||||||
let editLink = !this.props.version &&
|
let docSource = this.props.source;
|
||||||
this.props.config.editUrl && (
|
|
||||||
|
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 + docSource}
|
||||||
|
target="_blank">
|
||||||
|
{editThisDoc}
|
||||||
|
</a>
|
||||||
|
);
|
||||||
|
|
||||||
|
// If internationalization is enabled, show Recruiting link instead of Edit Link.
|
||||||
|
if (
|
||||||
|
this.props.language != 'en' &&
|
||||||
|
this.props.config.translationRecruitingLink
|
||||||
|
) {
|
||||||
|
editLink = (
|
||||||
<a
|
<a
|
||||||
className="edit-page-link button"
|
className="edit-page-link button"
|
||||||
href={this.props.config.editUrl + this.props.source}
|
href={
|
||||||
|
this.props.config.translationRecruitingLink +
|
||||||
|
'/' +
|
||||||
|
this.props.language
|
||||||
|
}
|
||||||
target="_blank">
|
target="_blank">
|
||||||
{editThisDoc}
|
{translateThisDoc}
|
||||||
</a>
|
</a>
|
||||||
);
|
);
|
||||||
if (this.props.language != 'en') {
|
|
||||||
editLink = !this.props.version &&
|
|
||||||
this.props.config.translationRecruitingLink && (
|
|
||||||
<a
|
|
||||||
className="edit-page-link button"
|
|
||||||
href={
|
|
||||||
this.props.config.translationRecruitingLink +
|
|
||||||
'/' +
|
|
||||||
this.props.language
|
|
||||||
}
|
|
||||||
target="_blank">
|
|
||||||
{translateThisDoc}
|
|
||||||
</a>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<div className="post">
|
<div className="post">
|
||||||
|
|
|
@ -52,6 +52,7 @@ class DocsLayout extends React.Component {
|
||||||
this.props.metadata.title
|
this.props.metadata.title
|
||||||
: this.props.metadata.title
|
: this.props.metadata.title
|
||||||
}
|
}
|
||||||
|
version={metadata.version}
|
||||||
language={metadata.language}
|
language={metadata.language}
|
||||||
/>
|
/>
|
||||||
<div className="docs-prevnext">
|
<div className="docs-prevnext">
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue