Skip to content

Commit

Permalink
feat: dev draft & unlisted banner
Browse files Browse the repository at this point in the history
  • Loading branch information
OzakIOne committed Aug 6, 2024
1 parent 7be1fea commit da16a1c
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 4 deletions.
8 changes: 8 additions & 0 deletions packages/docusaurus-theme-classic/src/theme-classic.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1610,6 +1610,14 @@ declare module '@theme/Unlisted' {
export default function Unlisted(props: Props): JSX.Element;
}

declare module '@theme/Drafted' {
export interface Props {
className?: string;
}

export default function Unlisted(props: Props): JSX.Element;
}

declare module '@theme/prism-include-languages' {
import type * as PrismNamespace from 'prismjs';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import BlogPostPageStructuredData from '@theme/BlogPostPage/StructuredData';
import TOC from '@theme/TOC';
import type {Props} from '@theme/BlogPostPage';
import Unlisted from '@theme/Unlisted';
import Drafted from '@theme/Drafted';
import type {BlogSidebar} from '@docusaurus/plugin-content-blog';

function BlogPostPageContent({
Expand Down Expand Up @@ -48,7 +49,8 @@ function BlogPostPageContent({
/>
) : undefined
}>
{unlisted && <Unlisted />}
{(unlisted || frontMatter.unlisted) && <Unlisted />}
{frontMatter.draft && <Drafted />}

<BlogPostItem>{children}</BlogPostItem>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import DocBreadcrumbs from '@theme/DocBreadcrumbs';
import Unlisted from '@theme/Unlisted';
import type {Props} from '@theme/DocItem/Layout';

import Drafted from '@theme/Drafted';
import styles from './styles.module.css';

/**
Expand Down Expand Up @@ -49,12 +50,13 @@ function useDocTOC() {
export default function DocItemLayout({children}: Props): JSX.Element {
const docTOC = useDocTOC();
const {
metadata: {unlisted},
metadata: {unlisted, frontMatter},
} = useDoc();
return (
<div className="row">
<div className={clsx('col', !docTOC.hidden && styles.docItemCol)}>
{unlisted && <Unlisted />}
{(unlisted || frontMatter.unlisted) && <Unlisted />}
{frontMatter.draft && <Drafted />}
<DocVersionBanner />
<div className={styles.docItemContainer}>
<article>
Expand Down
27 changes: 27 additions & 0 deletions packages/docusaurus-theme-classic/src/theme/Drafted/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* 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 clsx from 'clsx';
import {
ThemeClassNames,
DraftedBannerTitle,
DraftedBannerMessage,
} from '@docusaurus/theme-common';
import Admonition from '@theme/Admonition';
import type {Props} from '@theme/Drafted';

export default function Drafted({className}: Props): JSX.Element | null {
return (
<Admonition
type="caution"
title={<DraftedBannerTitle />}
className={clsx(className, ThemeClassNames.common.draftedBanner)}>
<DraftedBannerMessage />
</Admonition>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import Unlisted from '@theme/Unlisted';
import type {Props} from '@theme/MDXPage';

import EditMetaRow from '@theme/EditMetaRow';
import Drafted from '@theme/Drafted';
import styles from './styles.module.css';

export default function MDXPage(props: Props): JSX.Element {
Expand Down Expand Up @@ -60,7 +61,8 @@ export default function MDXPage(props: Props): JSX.Element {
<main className="container container--fluid margin-vert--lg">
<div className={clsx('row', styles.mdxPageWrapper)}>
<div className={clsx('col', !hideTableOfContents && 'col--8')}>
{unlisted && <Unlisted />}
{(unlisted || frontMatter.unlisted) && <Unlisted />}
{frontMatter.draft && <Drafted />}
<article>
<MDXContent>
<MDXPageContent />
Expand Down
2 changes: 2 additions & 0 deletions packages/docusaurus-theme-common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ export {
UnlistedMetadata,
} from './utils/unlistedUtils';

export {DraftedBannerTitle, DraftedBannerMessage} from './utils/draftedUtils';

export {
ErrorBoundaryTryAgainButton,
ErrorBoundaryError,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export const ThemeClassNames = {
codeBlock: 'theme-code-block',
admonition: 'theme-admonition',
unlistedBanner: 'theme-unlisted-banner',
draftedBanner: 'theme-drafted-banner',

admonitionType: (type: string) => `theme-admonition-${type}`,
},
Expand Down
29 changes: 29 additions & 0 deletions packages/docusaurus-theme-common/src/utils/draftedUtils.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* 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 Translate from '@docusaurus/Translate';

export function DraftedBannerTitle(): JSX.Element {
return (
<Translate
id="theme.draftedContent.title"
description="The drafted content banner title">
Drafted page
</Translate>
);
}

export function DraftedBannerMessage(): JSX.Element {
return (
<Translate
id="theme.draftedContent.message"
description="The drafted content banner message">
This page is drafted and will be excluded from production build.
</Translate>
);
}

0 comments on commit da16a1c

Please sign in to comment.