Skip to content

Commit 9173d31

Browse files
portdeveloperbrandyscarneythetaPC
authored
feat: add docusaurus-plugin-copy-page-button (#4499)
Co-authored-by: Brandy Smith <6577830+brandyscarney@users.noreply.github.com> Co-authored-by: Maria Hutt <thetaPC@users.noreply.github.com>
1 parent 3d0029c commit 9173d31

7 files changed

Lines changed: 118 additions & 3 deletions

File tree

docusaurus.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,12 @@ module.exports = {
371371
versions: VERSIONS_JSON,
372372
},
373373
],
374+
[
375+
'docusaurus-plugin-copy-page-button',
376+
{
377+
injectButton: false,
378+
},
379+
],
374380
],
375381
customFields: {},
376382
themes: [],

package-lock.json

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
"clsx": "^1.1.1",
5151
"concurrently": "^6.2.0",
5252
"crowdin": "^3.5.0",
53+
"docusaurus-plugin-copy-page-button": "^0.8.2",
5354
"docusaurus-plugin-module-alias": "^0.0.2",
5455
"docusaurus-plugin-sass": "^0.2.6",
5556
"fs-extra": "^9.1.0",
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
:root {
22
--edit-this-page-c: var(--ifm-link-color);
3+
--edit-this-page-opacity: 0.7;
34
}
45

56
.theme-edit-this-page {
@@ -9,8 +10,6 @@
910

1011
grid-template-columns: 0.875rem 1fr;
1112

12-
margin-block-start: 1.25rem;
13-
1413
color: var(--edit-this-page-c);
1514

1615
transition: opacity 0.2s ease-out;
@@ -19,6 +18,6 @@
1918
&:active,
2019
&:focus {
2120
color: var(--edit-this-page-c);
22-
opacity: 0.7;
21+
opacity: var(--edit-this-page-opacity);
2322
}
2423
}

src/styles/components/_toc.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ html[data-theme='dark'] {
6262
.theme-edit-this-page {
6363
--edit-this-page-c: var(--ifm-heading-color);
6464

65+
margin-block-start: 1.25rem;
6566
font-weight: 600;
6667
font-size: 0.875rem;
6768
}

src/theme/EditMetaRow/index.tsx

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/**
2+
* EditMetaRow is a component that renders the edit and last updated
3+
* metadata for a page. This component is displayed at the bottom of
4+
* each page.
5+
*
6+
* Original source:
7+
* @link https://github.com/facebook/docusaurus/blob/main/packages/docusaurus-theme-classic/src/theme/EditMetaRow/index.tsx
8+
*
9+
* Reason for overriding:
10+
* - Add a copy page button next to the edit this page link
11+
* - Wrap the whole last updated section in a conditional, not just
12+
* its contents. Otherwise the empty column still reserves half the
13+
* row.
14+
*/
15+
16+
import React, { type ReactNode } from 'react';
17+
import clsx from 'clsx';
18+
// CUSTOM CODE
19+
import CopyPageButton from 'docusaurus-plugin-copy-page-button/react';
20+
// CUSTOM CODE END
21+
import EditThisPage from '@theme/EditThisPage';
22+
import type { Props } from '@theme/EditMetaRow';
23+
24+
import LastUpdated from '@theme/LastUpdated';
25+
26+
import globalStyles from '@docusaurus/theme-classic/lib/theme/EditMetaRow/styles.module.css';
27+
import styles from './styles.module.css';
28+
29+
export default function EditMetaRow({ className, editUrl, lastUpdatedAt, lastUpdatedBy }: Props): ReactNode {
30+
return (
31+
<div className={clsx('row', className)}>
32+
{/* CUSTOM CODE — "Edit this page | Copy page" as peer links on one row */}
33+
<div className={clsx('col', styles.editMetaActions)}>
34+
{editUrl && <EditThisPage editUrl={editUrl} />}
35+
<CopyPageButton
36+
customStyles={{
37+
container: { className: styles.copyPageContainer },
38+
button: { className: styles.copyPageButton },
39+
}}
40+
/>
41+
</div>
42+
{/* CUSTOM CODE END */}
43+
{/* CUSTOM CODE — wrap the whole column in the conditional, not just its contents */}
44+
{(lastUpdatedAt || lastUpdatedBy) && (
45+
<div className={clsx('col', globalStyles.lastUpdated)}>
46+
<LastUpdated lastUpdatedAt={lastUpdatedAt} lastUpdatedBy={lastUpdatedBy} />
47+
</div>
48+
)}
49+
{/* CUSTOM CODE END */}
50+
</div>
51+
);
52+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
.editMetaActions {
2+
display: inline-flex;
3+
align-items: center;
4+
}
5+
6+
.editMetaActions > :not(:first-child) {
7+
margin-inline-start: 0.85rem;
8+
padding-inline-start: 0.85rem;
9+
border-inline-start: 1px solid var(--ifm-color-emphasis-300);
10+
}
11+
12+
.copyPageContainer {
13+
display: inline-flex;
14+
align-items: center;
15+
}
16+
17+
/* Make the "Copy page" button look like the "Edit this page" link */
18+
.copyPageButton {
19+
display: inline-flex;
20+
align-items: center;
21+
gap: 0.3rem;
22+
border: none;
23+
background: transparent !important;
24+
padding: 0;
25+
margin: 0;
26+
color: var(--edit-this-page-c) !important;
27+
font: inherit;
28+
}
29+
30+
.copyPageButton:hover,
31+
.copyPageButton:active,
32+
.copyPageButton:focus {
33+
opacity: var(--edit-this-page-opacity);
34+
}
35+
36+
/* The plugin hides the button's text label for small screens; keep it visible at all sizes. */
37+
@media (max-width: 767px) {
38+
.copyPageButton [class*='copyPageText'] {
39+
display: inline;
40+
}
41+
}
42+
/* CUSTOM CODE END */

0 commit comments

Comments
 (0)