Skip to content

Commit e652646

Browse files
authored
Adjust the "Edit this page" button to always point to versioned docs (#4371)
* Adjust the "Edit this page" button to always point to versioned docs * Update editUrl to be a buttons array * Replace blob URL with edit URL * Fix eslint script * Fix merge conflict * Show normal verbiage on latest release
1 parent 1e51014 commit e652646

File tree

5 files changed

+78
-10
lines changed

5 files changed

+78
-10
lines changed

website/docusaurus.config.ts

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,54 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
import type {Config} from '@docusaurus/types';
9-
import type * as Preset from '@docusaurus/preset-classic';
108
import type * as PluginContentDocs from '@docusaurus/plugin-content-docs';
9+
import type * as Preset from '@docusaurus/preset-classic';
10+
import type {Config} from '@docusaurus/types';
11+
import path from 'path';
1112

1213
import users from './showcase.json';
1314
import versions from './versions.json';
1415

1516
const lastVersion = versions[0];
1617
const copyright = `Copyright © ${new Date().getFullYear()} Meta Platforms, Inc.`;
1718

19+
export interface EditUrlButton {
20+
label: string;
21+
href: string;
22+
}
23+
1824
const commonDocsOptions = {
1925
breadcrumbs: false,
2026
showLastUpdateAuthor: false,
2127
showLastUpdateTime: true,
22-
editUrl:
23-
'https://github.com/facebook/react-native-website/blob/main/website/',
28+
editUrl: (options => {
29+
const baseUrl =
30+
'https://github.com/facebook/react-native-website/edit/main';
31+
const nextReleasePath = `docs/${options.docPath}`;
32+
const isNextRelease = options.version === 'current';
33+
const buttons: EditUrlButton[] = [
34+
{
35+
label: isNextRelease ? 'Edit this page' : 'Edit page for next release',
36+
href: `${baseUrl}/${nextReleasePath}`,
37+
},
38+
];
39+
if (!isNextRelease) {
40+
const label =
41+
options.version === lastVersion
42+
? 'Edit page for current release'
43+
: `Edit page for ${options.version} release`;
44+
const thisVersionPath = path.posix.join(
45+
'website',
46+
options.versionDocsDirPath,
47+
options.docPath
48+
);
49+
buttons.push({
50+
label,
51+
href: `${baseUrl}/${thisVersionPath}`,
52+
});
53+
}
54+
return JSON.stringify(buttons);
55+
}) as PluginContentDocs.EditUrlFunction,
2456
remarkPlugins: [
2557
require('@react-native-website/remark-snackplayer'),
2658
require('@react-native-website/remark-codeblock-language-as-title'),

website/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"format:style": "prettier --write src/**/*.{scss,css}",
2727
"format:examples": "eslint-examples-js --fix && eslint-examples-tsx --fix",
2828
"prettier": "yarn format:source && yarn format:markdown && yarn format:style",
29-
"lint": "eslint ../docs/** blog/** '{core,src}/**/*.{js,jsx,ts,tsx}'",
29+
"lint": "eslint ../docs/** blog/** \"{core,src}/**/*.{js,jsx,ts,tsx}\"",
3030
"lint:examples": "eslint-examples-js && eslint-examples-tsx && tsc-examples",
3131
"lint:versioned": "eslint versioned_docs/**",
3232
"lint:markdown": "remark ../docs --quiet -r .remarkrc.mjs",

website/src/theme/DocItem/Footer/index.tsx

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,19 @@ import React from 'react';
22
import clsx from 'clsx';
33
import {ThemeClassNames} from '@docusaurus/theme-common';
44
import {useDoc} from '@docusaurus/plugin-content-docs/client';
5+
import Translate from '@docusaurus/Translate';
6+
import IconEdit from '@theme/Icon/Edit';
57
import LastUpdated from '@theme/LastUpdated';
6-
import EditThisPage from '@theme/EditThisPage';
7-
import TagsListInline from '@theme/TagsListInline';
8+
import Link from '@docusaurus/Link';
9+
import TagsListInline, {
10+
Props as TagsListInlineProps,
11+
} from '@theme/TagsListInline';
812

13+
import type {EditUrlButton} from '../../../../docusaurus.config';
914
import styles from './styles.module.css';
1015
import DocsRating from '../../../../core/DocsRating';
1116

12-
function TagsRow(props) {
17+
function TagsRow(props: TagsListInlineProps) {
1318
return (
1419
<div
1520
className={clsx(
@@ -22,11 +27,35 @@ function TagsRow(props) {
2227
</div>
2328
);
2429
}
30+
function EditPage({label, href}: {label: string; href: string}) {
31+
return (
32+
<Link to={href} className={ThemeClassNames.common.editThisPage}>
33+
<IconEdit />
34+
<Translate
35+
id="theme.common.editThisPage"
36+
description="The link label to edit the page">
37+
{label}
38+
</Translate>
39+
</Link>
40+
);
41+
}
2542
function EditMetaRow({editUrl, lastUpdatedAt, lastUpdatedBy}) {
43+
const buttons = React.useMemo((): EditUrlButton[] => {
44+
try {
45+
return JSON.parse(editUrl);
46+
} catch (e) {
47+
console.error(e);
48+
return [{href: editUrl, label: 'Edit this page'}];
49+
}
50+
}, [editUrl]);
2651
return (
2752
<div className={clsx(ThemeClassNames.docs.docFooterEditMetaRow, 'row')}>
28-
<div className="col">{editUrl && <EditThisPage editUrl={editUrl} />}</div>
29-
<div className={clsx('col', styles.lastUpdated)}>
53+
<div className={clsx(styles.editButtons)}>
54+
{buttons.map(({label, href}, index) => (
55+
<EditPage key={index} label={label} href={href} />
56+
))}
57+
</div>
58+
<div className={clsx(styles.lastUpdated)}>
3059
{(lastUpdatedAt || lastUpdatedBy) && (
3160
<LastUpdated
3261
lastUpdatedAt={lastUpdatedAt}

website/src/theme/DocItem/Footer/styles.module.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
font-size: smaller;
55
}
66

7+
.editButtons {
8+
column-gap: 0.4rem;
9+
display: flex;
10+
flex: 1;
11+
}
12+
713
@media (min-width: 997px) {
814
.lastUpdated {
915
text-align: end;

website/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"extends": "@docusaurus/tsconfig",
33
"compilerOptions": {
44
"baseUrl": "."
5+
// "esModuleInterop": true
56
},
67
"exclude": ["node_modules", "build"]
78
}

0 commit comments

Comments
 (0)