Skip to content

Commit

Permalink
Merge pull request #911 from Cysharp/feature/DocsAdditionalInfo
Browse files Browse the repository at this point in the history
Add additional information to the top of pages
  • Loading branch information
mayuki authored Feb 4, 2025
2 parents 42434a4 + f00945e commit c3634b5
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 5 deletions.
12 changes: 7 additions & 5 deletions docs/docusaurus.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import {themes as prismThemes} from 'prism-react-renderer';
import type {Config} from '@docusaurus/types';
import type * as Preset from '@docusaurus/preset-classic';

import additionalHeaderMetaRow from './src/remark/additionalHeaderMetaRow';

// This runs in Node.js - Don't use client-side code here (browser APIs, JSX...)

const config: Config = {
Expand Down Expand Up @@ -51,10 +53,14 @@ const config: Config = {
sidebarPath: './sidebars.ts',
sidebarCollapsed: false,

showLastUpdateTime: true,

editUrl: (params) => params.locale == 'en'
? `https://github.com/Cysharp/MagicOnion/tree/main/docs/docs/${params.docPath}`
: `https://github.com/Cysharp/MagicOnion/tree/main/docs/i18n/${params.locale}/docusaurus-plugin-content-docs/current/${params.docPath}`,
},

remarkPlugins: [additionalHeaderMetaRow],
},
theme: {
customCss: './src/css/custom.css',
},
Expand Down Expand Up @@ -107,10 +113,6 @@ const config: Config = {
{
title: 'Docs',
items: [
{
label: 'Documentation',
to: '/',
},
{
label: 'About MagicOnion',
to: '/',
Expand Down
2 changes: 2 additions & 0 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
},
"dependencies": {
"@docusaurus/core": "3.7.0",
"@docusaurus/plugin-content-docs": "^3.7.0",
"@docusaurus/preset-classic": "3.7.0",
"@docusaurus/theme-common": "^3.7.0",
"@docusaurus/theme-mermaid": "^3.7.0",
"@mdx-js/react": "^3.0.0",
"clsx": "^2.0.0",
Expand Down
6 changes: 6 additions & 0 deletions docs/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions docs/src/components/AdditionalHeaderMetaRow.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from 'react';

import LastUpdated from '@theme/LastUpdated';
import {useDoc} from '@docusaurus/plugin-content-docs/client'

export default function AdditionalHeaderMetaRow(props: { children: React.ReactNode }) {
const {metadata} = useDoc();

return (
<>
<LastUpdated lastUpdatedAt={metadata.lastUpdatedAt} />
</>
);
}
11 changes: 11 additions & 0 deletions docs/src/css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,14 @@
[lang='ja-Jp'] .theme-doc-sidebar-container nav {
font-size: 0.85rem;
}

header .theme-last-updated {
font-size: 0.85rem;
color: var(--ifm-color-emphasis-600);
display: block;
margin-top: calc((var(--ifm-h1-vertical-rhythm-bottom) * var(--ifm-leading) * -1) + 0.8rem);
margin-bottom: calc(var(--ifm-h1-vertical-rhythm-bottom) * var(--ifm-leading));
}
header .theme-last-updated b {
font-weight: normal;
}
20 changes: 20 additions & 0 deletions docs/src/remark/additionalHeaderMetaRow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import {visit} from 'unist-util-visit';

const plugin = (options) => {
const transformer = async (ast) => {
visit(ast, 'heading', (node, index, parent) => {
if (node.depth === 1 && node.children.length > 0) {
parent.children.push({
type: 'containerDirective',
data: {
hName: 'AdditionalHeaderMetaRow',
hProperties: {}
}
});
}
});
};
return transformer;
};

export default plugin;
7 changes: 7 additions & 0 deletions docs/src/theme/MDXComponents.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import MDXComponents from '@theme-original/MDXComponents';
import AdditionalHeaderMetaRow from '@site/src/components/AdditionalHeaderMetaRow';

export default {
...MDXComponents,
AdditionalHeaderMetaRow,
};
24 changes: 24 additions & 0 deletions docs/src/theme/MDXContent/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React, {type ReactNode} from 'react';
import clsx from 'clsx';
import MDXContent from '@theme-original/MDXContent';
import type MDXContentType from '@theme/MDXContent';
import type {WrapperProps} from '@docusaurus/types';
import styles from './styles.module.css';
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';

type Props = WrapperProps<typeof MDXContentType>;

export default function MDXContentWrapper(props: Props): ReactNode {
const {i18n} = useDocusaurusContext();
return (
<>
{(i18n.currentLocale != 'ja' && i18n.currentLocale != 'en') &&
<div className={clsx(styles.communityNotice, "alert alert--secondary")}>
Translation of pages other than English and Japanese versions is maintained by community contributions.
The project does not guarantee the accuracy of the content and may not reflect the latest content.
</div>
}
<MDXContent {...props} />
</>
);
}
4 changes: 4 additions & 0 deletions docs/src/theme/MDXContent/styles.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.communityNotice {
font-size: 0.9rem;
margin-bottom: 0.8rem;
}

0 comments on commit c3634b5

Please sign in to comment.