-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
382 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
packages/logos-docusaurus-theme/src/client/theme/AuthorPage/AuthorPage.module.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
@use '../../css/utils'; | ||
|
||
.root { | ||
max-width: 80%; | ||
} | ||
|
||
.links { | ||
padding-top: 0.5rem; | ||
|
||
display: flex; | ||
flex-direction: row; | ||
|
||
& > a:not(:last-child) { | ||
&::after { | ||
content: '•'; | ||
display: inline-block; | ||
margin-inline: 0.75rem; | ||
} | ||
} | ||
} | ||
|
||
.docs { | ||
margin-top: 1rem; | ||
|
||
display: flex; | ||
flex-direction: column; | ||
gap: 1rem; | ||
} | ||
|
||
.date { | ||
margin-bottom: 0.5rem; | ||
font-style: italic; | ||
opacity: 0.8; | ||
} | ||
|
||
.title { | ||
display: block; | ||
text-decoration: underline; | ||
} | ||
|
||
.description { | ||
display: block; | ||
margin-top: 0.25rem; | ||
} | ||
|
||
@include utils.responsive('lg', 'down') { | ||
.root { | ||
max-width: unset; | ||
} | ||
} |
88 changes: 88 additions & 0 deletions
88
packages/logos-docusaurus-theme/src/client/theme/AuthorPage/AuthorPage.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import { Typography } from '@acid-info/lsd-react' | ||
import Link from '@docusaurus/Link' | ||
import formatDate from 'date-fns/format' | ||
import React from 'react' | ||
import { Author } from '../../types/theme.types' | ||
import styles from './AuthorPage.module.scss' | ||
|
||
export type AuthorPageProps = { | ||
data: { | ||
author: Author | ||
docs: { | ||
id: string | ||
title: string | ||
description: string | ||
permalink: string | ||
frontMatter: { | ||
date?: string | ||
} | ||
}[] | ||
} | ||
} | ||
|
||
export const AuthorPage: React.FC<AuthorPageProps> = ({ | ||
data: { author, docs }, | ||
}) => { | ||
return ( | ||
<div className={styles.root}> | ||
<Typography className={styles.name} variant="h3"> | ||
{author.name} | ||
</Typography> | ||
<div className={styles.links}> | ||
{author.github && ( | ||
<Typography | ||
variant="body2" | ||
component="a" | ||
target="_blank" | ||
href={`https://github.com/${author.github}`} | ||
> | ||
Github | ||
</Typography> | ||
)} | ||
{author.twitter && ( | ||
<Typography | ||
variant="body2" | ||
component="a" | ||
target="_blank" | ||
href={`https://twitter.com/${author.twitter}`} | ||
> | ||
</Typography> | ||
)} | ||
{author.website && ( | ||
<Typography | ||
variant="body2" | ||
component="a" | ||
target="_blank" | ||
href={author.website} | ||
> | ||
Website | ||
</Typography> | ||
)} | ||
</div> | ||
<div className={styles.docs}> | ||
{docs.map((doc, index) => ( | ||
<div className={styles.doc} key={index}> | ||
{doc.frontMatter.date && ( | ||
<Typography | ||
className={styles.date} | ||
variant="body2" | ||
component="div" | ||
> | ||
{formatDate(new Date(doc.frontMatter.date), 'MMM d yyyy')} | ||
</Typography> | ||
)} | ||
<Link className={styles.title} href={doc.permalink}> | ||
{doc.title} | ||
</Link> | ||
<Typography className={styles.description} variant="body1"> | ||
{doc.description} | ||
</Typography> | ||
</div> | ||
))} | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
export default AuthorPage |
1 change: 1 addition & 0 deletions
1
packages/logos-docusaurus-theme/src/client/theme/AuthorPage/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './AuthorPage' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
packages/logos-docusaurus-theme/src/server/utils/author.utils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import { LoadedContent } from '@docusaurus/plugin-content-docs' | ||
import { | ||
AllContent, | ||
LoadContext, | ||
PluginContentLoadedActions, | ||
} from '@docusaurus/types' | ||
import { docuHash } from '@docusaurus/utils' | ||
import path from 'path' | ||
import { ensureTrailingSlash } from '../../client/lib/string.utils' | ||
import { getVersionMetadataPath } from './doc.utils' | ||
import { getDocConfig } from './option.utils' | ||
|
||
export const createAuthorRoutes = async ( | ||
context: LoadContext, | ||
args: { | ||
allContent: AllContent | ||
actions: PluginContentLoadedActions | ||
}, | ||
) => { | ||
const docs = args.allContent['docusaurus-plugin-content-docs'] ?? {} | ||
|
||
const docContents = Object.entries(docs) | ||
|
||
for (const [id, loadedContent] of docContents) { | ||
const { loadedVersions } = loadedContent as LoadedContent | ||
|
||
for (const loadedVersion of loadedVersions) { | ||
const { path: versionPath } = loadedVersion | ||
|
||
const versionMetadataPath = getVersionMetadataPath( | ||
context, | ||
id, | ||
loadedVersion, | ||
) | ||
|
||
const conf = getDocConfig(context, id) | ||
const authorPageConf = conf?.content?.authorPage | ||
if (!authorPageConf) return | ||
|
||
const authors = conf?.content?.authors ?? [] | ||
|
||
const authorDocs: Record<string, any[]> = {} | ||
|
||
loadedVersion.docs.forEach((doc) => { | ||
const { author } = doc.frontMatter as any | ||
const docAuthors = !author | ||
? [] | ||
: Array.isArray(author) | ||
? author | ||
: [author] | ||
const validAuthors = docAuthors.map((authorKey) => | ||
authors.find((a) => a.key === authorKey), | ||
) | ||
validAuthors.forEach((author) => { | ||
if (!author) return | ||
|
||
authorDocs[author.key] = [ | ||
...(authorDocs[author.key] ?? []), | ||
{ | ||
id: doc.id, | ||
title: doc.title, | ||
description: doc.description, | ||
frontMatter: doc.frontMatter, | ||
permalink: doc.permalink, | ||
}, | ||
] | ||
}) | ||
}) | ||
|
||
const routes = await Promise.all( | ||
authors.map(async (author) => { | ||
const dataPath = await args.actions.createData( | ||
`${docuHash( | ||
`author-${author.key}-${loadedVersion.versionName}`, | ||
)}.json`, | ||
JSON.stringify({ author, docs: authorDocs[author.key] ?? [] }), | ||
) | ||
|
||
return { | ||
path: `${ensureTrailingSlash(versionPath)}author/${author.key}`, | ||
component: path.resolve( | ||
__dirname, | ||
'../../client/theme/AuthorPage/AuthorPage', | ||
), | ||
exact: true, | ||
sidebar: | ||
typeof authorPageConf === 'boolean' | ||
? null | ||
: authorPageConf!.sidebar, | ||
modules: { | ||
data: dataPath, | ||
}, | ||
} | ||
}), | ||
) | ||
|
||
args.actions.addRoute({ | ||
path: `${ensureTrailingSlash(versionPath)}author`, | ||
exact: false, | ||
component: '@theme/DocPage', | ||
routes: routes ?? [], | ||
modules: { | ||
versionMetadata: versionMetadataPath, | ||
}, | ||
priority: 1000, | ||
}) | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
packages/logos-docusaurus-theme/src/server/utils/doc.utils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { LoadedVersion } from '@docusaurus/plugin-content-docs' | ||
import { LoadContext } from '@docusaurus/types' | ||
import { docuHash } from '@docusaurus/utils' | ||
import path from 'path' | ||
|
||
export const getVersionMetadataPath = ( | ||
context: LoadContext, | ||
pluginId: string, | ||
loadedVersion: LoadedVersion, | ||
) => { | ||
const pluginDataDirRoot = path.join( | ||
context.generatedFilesDir, | ||
'docusaurus-plugin-content-docs', | ||
) | ||
const dataDir = path.join(pluginDataDirRoot, pluginId) | ||
|
||
return path.join( | ||
dataDir, | ||
`${docuHash(`version-${loadedVersion.versionName}-metadata-prop`)}.json`, | ||
) | ||
} |
16 changes: 16 additions & 0 deletions
16
packages/logos-docusaurus-theme/src/server/utils/option.utils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { LoadContext } from '@docusaurus/types' | ||
import _ from 'lodash' | ||
import type { DocConfig, ThemeOptions } from '../../client/types/theme.types' | ||
|
||
export const getDocConfig = ( | ||
context: LoadContext, | ||
pluginId: string, | ||
): DocConfig => { | ||
const themeOptions = _.get( | ||
context, | ||
'siteConfig.customFields.logos-docusaurus-theme', | ||
{}, | ||
) as ThemeOptions | ||
|
||
return themeOptions?.docs?.[pluginId] ?? {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.