Skip to content

Commit

Permalink
Use swizzle "eject" instead to include DocumentMetadata on each page
Browse files Browse the repository at this point in the history
  • Loading branch information
ch1bo committed Aug 25, 2022
1 parent 4deb453 commit bec4e97
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docs/src/components/DocumentMetadata/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ interface TranslatedMetadata {
commitHash: string
}

const style = { marginTop: '1em' }
const style = { marginBottom: '1em' }

const renderMetadata = ({ lastUpdatedAt, commitHash }: Metadata) => {
let link = `https://github.com/input-output-hk/hydra-poc/commit/${commitHash}`
Expand Down
81 changes: 76 additions & 5 deletions docs/src/theme/DocItemFooter/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,83 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import React from 'react';
import DocItemFooter from '@theme-original/DocItemFooter';
import clsx from 'clsx';
import LastUpdated from '@theme/LastUpdated';
import EditThisPage from '@theme/EditThisPage';
import TagsListInline from '@theme/TagsListInline';
import styles from './styles.module.css';
import {ThemeClassNames} from '@docusaurus/theme-common';
import DocumentMetadata from '@site/src/components/DocumentMetadata';

export default function DocItemFooterWrapper(props) {
function TagsRow(props) {
return (
<>
<div
className={clsx(
ThemeClassNames.docs.docFooterTagsRow,
'row margin-bottom--sm',
)}>
<div className="col">
<TagsListInline {...props} />
</div>
</div>
);
}

function EditMetaRow({
editUrl,
lastUpdatedAt,
lastUpdatedBy,
formattedLastUpdatedAt,
}) {
return (
<div className={clsx(ThemeClassNames.docs.docFooterEditMetaRow, 'row')}>
<div className="col">{editUrl && <EditThisPage editUrl={editUrl} />}</div>

<div className={clsx('col', styles.lastUpdated)}>
{(lastUpdatedAt || lastUpdatedBy) && (
<LastUpdated
lastUpdatedAt={lastUpdatedAt}
formattedLastUpdatedAt={formattedLastUpdatedAt}
lastUpdatedBy={lastUpdatedBy}
/>
)}
</div>
</div>
);
}

export default function DocItemFooter(props) {
const {content: DocContent} = props;
const {metadata} = DocContent;
const {editUrl, lastUpdatedAt, formattedLastUpdatedAt, lastUpdatedBy, tags} =
metadata;
const canDisplayTagsRow = tags.length > 0;
const canDisplayEditMetaRow = !!(editUrl || lastUpdatedAt || lastUpdatedBy);
const canDisplayFooter = canDisplayTagsRow || canDisplayEditMetaRow;

if (!canDisplayFooter) {
return null;
}

return (
<footer
className={clsx(ThemeClassNames.docs.docFooter, 'docusaurus-mt-lg')}>
{canDisplayTagsRow && <TagsRow tags={tags} />}
// NOTE: This is our only modification to this "ejected" component
<DocumentMetadata />
<DocItemFooter {...props} />
</>
// End of our modifications
{canDisplayEditMetaRow && (
<EditMetaRow
editUrl={editUrl}
lastUpdatedAt={lastUpdatedAt}
lastUpdatedBy={lastUpdatedBy}
formattedLastUpdatedAt={formattedLastUpdatedAt}
/>
)}
</footer>
);
}
18 changes: 18 additions & 0 deletions docs/src/theme/DocItemFooter/styles.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

.lastUpdated {
margin-top: 0.2rem;
font-style: italic;
font-size: smaller;
}

@media (min-width: 997px) {
.lastUpdated {
text-align: right;
}
}

0 comments on commit bec4e97

Please sign in to comment.