Skip to content

Commit

Permalink
move edit this page to top
Browse files Browse the repository at this point in the history
  • Loading branch information
gingerwizard committed Dec 12, 2024
1 parent 5418a8f commit cac4a5d
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 1 deletion.
64 changes: 64 additions & 0 deletions src/theme/DocItem/Footer/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import React from 'react';
import clsx from 'clsx';
import {ThemeClassNames} from '@docusaurus/theme-common';
import {useDoc} from '@docusaurus/theme-common/internal';
import LastUpdated from '@theme/LastUpdated';
import EditThisPage from '@theme/EditThisPage';
import TagsListInline from '@theme/TagsListInline';
import styles from './styles.module.css';
function TagsRow(props) {
return (
<div
className={clsx(
ThemeClassNames.docs.docFooterTagsRow,
'row margin-bottom--sm',
)}>
<div className="col">
<TagsListInline {...props} />
</div>
</div>
);
}
function EditMetaRow({
lastUpdatedAt,
lastUpdatedBy,
formattedLastUpdatedAt,
}) {
return (
<div className={clsx(ThemeClassNames.docs.docFooterEditMetaRow, 'row')}>
<div className={clsx('col', styles.lastUpdated)}>
{(lastUpdatedAt || lastUpdatedBy) && (
<LastUpdated
lastUpdatedAt={lastUpdatedAt}
formattedLastUpdatedAt={formattedLastUpdatedAt}
lastUpdatedBy={lastUpdatedBy}
/>
)}
</div>
</div>
);
}
export default function DocItemFooter() {
const {metadata} = useDoc();
const {lastUpdatedAt, formattedLastUpdatedAt, lastUpdatedBy, tags} =
metadata;
const canDisplayTagsRow = tags.length > 0;
const canDisplayEditMetaRow = !!(lastUpdatedAt || lastUpdatedBy);
const canDisplayFooter = canDisplayTagsRow || canDisplayEditMetaRow;
if (!canDisplayFooter) {
return null;
}
return (
<footer
className={clsx(ThemeClassNames.docs.docFooter, 'docusaurus-mt-lg')}>
{canDisplayTagsRow && <TagsRow tags={tags} />}
{canDisplayEditMetaRow && (
<EditMetaRow
lastUpdatedAt={lastUpdatedAt}
lastUpdatedBy={lastUpdatedBy}
formattedLastUpdatedAt={formattedLastUpdatedAt}
/>
)}
</footer>
);
}
11 changes: 11 additions & 0 deletions src/theme/DocItem/Footer/styles.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.lastUpdated {
margin-top: 0.2rem;
font-style: italic;
font-size: smaller;
}

@media (min-width: 997px) {
.lastUpdated {
text-align: right;
}
}
11 changes: 10 additions & 1 deletion src/theme/DocItem/Layout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import DocItemTOCMobile from '@theme/DocItem/TOC/Mobile';
import DocItemTOCDesktop from '@theme/DocItem/TOC/Desktop';
import DocItemContent from '@theme/DocItem/Content';
import DocBreadcrumbs from '@theme/DocBreadcrumbs';
import EditThisPage from '@theme/EditThisPage';
import styles from './styles.module.css';
/**
* Decide if the toc should be rendered, on mobile or desktop viewports
Expand All @@ -32,14 +33,22 @@ function useDocTOC() {
}
export default function DocItemLayout({children}) {
const docTOC = useDocTOC();
const {metadata} = useDoc();
const {editUrl} = metadata;
return (
<div className="row" style={{flexWrap: 'nowrap'}}>
<div className={clsx('col', !docTOC.hidden && styles.docItemCol)}>
<DocVersionBanner />
<div className={styles.docItemContainer}>
<article>
<DocBreadcrumbs />
{/* Add EditThisPage link at the top */}
<div className={styles.docHeaderContainer}>
<DocBreadcrumbs />
{editUrl && <EditThisPage editUrl={editUrl} />}
</div>

<DocVersionBadge />

<DocItemContent>{children}</DocItemContent>
<DocItemFooter />
</article>
Expand Down
5 changes: 5 additions & 0 deletions src/theme/DocItem/Layout/styles.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
padding-bottom: 3.5rem;
}

.docHeaderContainer {
display: flex;
justify-content: space-between;
}

@media (min-width: 997px) {
.docItemCol {
max-width: 75% !important;
Expand Down

0 comments on commit cac4a5d

Please sign in to comment.