-
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.
feat: add DocMetadata mdx component for displaying date and authors
- Loading branch information
Showing
12 changed files
with
153 additions
and
18 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
25 changes: 25 additions & 0 deletions
25
packages/logos-docusaurus-theme/src/client/components/mdx/DocMetadata/DocMetadata.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,25 @@ | ||
@use '../../../css/utils'; | ||
@use '../../../css/lsd'; | ||
|
||
.mdx-doc-metadata { | ||
display: flex; | ||
flex-direction: row; | ||
line-height: 0; | ||
|
||
& > span:not(:last-child) { | ||
&::after { | ||
content: '•'; | ||
display: inline-block; | ||
margin-inline: 0.75rem; | ||
} | ||
} | ||
} | ||
|
||
.markdown { | ||
h1 + .mdx-doc-metadata, | ||
header + .mdx-doc-metadata { | ||
margin-top: calc( | ||
-1 * var(--ifm-h1-vertical-rhythm-bottom) * var(--ifm-leading) + 1rem | ||
); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
packages/logos-docusaurus-theme/src/client/components/mdx/DocMetadata/DocMetadata.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,28 @@ | ||
import { Typography } from '@acid-info/lsd-react' | ||
import clsx from 'clsx' | ||
import React from 'react' | ||
import './DocMetadata.scss' | ||
import { useDocMetadata } from './useDocMetadata' | ||
|
||
export type DocMetadataProps = React.HTMLAttributes<HTMLDivElement> & {} | ||
|
||
export const DocMetadata: React.FC<DocMetadataProps> = ({ | ||
className, | ||
children, | ||
...props | ||
}) => { | ||
const { date, authors } = useDocMetadata() | ||
|
||
return ( | ||
<div className={clsx(className, 'mdx-doc-metadata')} {...(props as any)}> | ||
{date && <Typography variant="body2">{date}</Typography>} | ||
{authors && authors.length > 0 && ( | ||
<> | ||
<Typography variant="body2"> | ||
by {authors.map((author) => author!.name).join(', ')} | ||
</Typography> | ||
</> | ||
)} | ||
</div> | ||
) | ||
} |
1 change: 1 addition & 0 deletions
1
packages/logos-docusaurus-theme/src/client/components/mdx/DocMetadata/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 './DocMetadata' |
20 changes: 20 additions & 0 deletions
20
packages/logos-docusaurus-theme/src/client/components/mdx/DocMetadata/useDocMetadata.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,20 @@ | ||
import { useDoc } from '@docusaurus/theme-common/internal' | ||
import { useDocThemeOptions } from '../../../lib/useThemeOptions' | ||
import format from 'date-fns/format' | ||
|
||
export const useDocMetadata = () => { | ||
const options = useDocThemeOptions() | ||
const { content: { authors = [] } = {} } = options | ||
|
||
const { frontMatter = {} } = useDoc() as any | ||
const { author = [], date } = frontMatter | ||
|
||
const docAuthors = (Array.isArray(author) ? author : [author]) | ||
.map((key) => authors.find((a) => key === a.key)) | ||
.filter((a) => !!a) | ||
|
||
return { | ||
date: date ? format(new Date(date), 'MMM d yyyy') : '', | ||
authors: docAuthors, | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
packages/logos-docusaurus-theme/src/client/components/mdx/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
25 changes: 21 additions & 4 deletions
25
packages/logos-docusaurus-theme/src/client/types/theme.types.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 |
---|---|---|
@@ -1,9 +1,26 @@ | ||
import type { PluginOptions as DefaultPluginOptions } from '@docusaurus/theme-classic' | ||
|
||
export type Author = { | ||
key: string | ||
name: string | ||
github?: string | ||
twitter?: string | ||
website?: string | ||
} | ||
|
||
export type DocContent = { | ||
authors?: Author[] | ||
} | ||
|
||
export type DocSidebarConfig = { | ||
hide?: boolean | ||
} | ||
|
||
export type DocConfig = { | ||
sidebar?: { | ||
hide?: boolean | ||
} | ||
sidebar?: DocSidebarConfig | ||
content?: DocContent | ||
} | ||
|
||
export type ThemeOptions = { | ||
export type ThemeOptions = DefaultPluginOptions & { | ||
docs?: Record<string, DocConfig> | ||
} |
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
42 changes: 42 additions & 0 deletions
42
packages/logos-docusaurus-theme/src/server/utils/validateOptions.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,42 @@ | ||
import { Joi } from '@docusaurus/utils-validation' | ||
import { | ||
Author, | ||
DocConfig, | ||
DocContent, | ||
DocSidebarConfig, | ||
ThemeOptions, | ||
} from '../../client/types/theme.types' | ||
|
||
const schema = Joi.object<ThemeOptions>({ | ||
docs: Joi.object() | ||
.pattern( | ||
Joi.string(), | ||
Joi.object<DocConfig>({ | ||
sidebar: Joi.object<DocSidebarConfig>({ | ||
hide: Joi.bool().default(true), | ||
}).default({}), | ||
content: Joi.object<DocContent>({ | ||
authors: Joi.array() | ||
.items( | ||
Joi.object<Author>({ | ||
key: Joi.string().required(), | ||
name: Joi.string().required(), | ||
github: Joi.string().optional(), | ||
twitter: Joi.string().optional(), | ||
website: Joi.string().optional(), | ||
}), | ||
) | ||
.default([]), | ||
}).default({}), | ||
}), | ||
) | ||
.default({}), | ||
}).unknown(true) | ||
|
||
export const validateOptions = ({ | ||
options, | ||
validate, | ||
}: { | ||
options: ThemeOptions | ||
validate: any | ||
}) => validate(schema, { ...(options ?? {}) }) |
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