mirror of
https://github.com/facebook/docusaurus.git
synced 2025-07-01 00:48:02 +02:00
feat(content-docs): draft docs excluded from build & sidebars (#6457)
Co-authored-by: sebastienlorber <lorber.sebastien@gmail.com> Co-authored-by: Joshua Chen <sidachen2003@gmail.com>
This commit is contained in:
parent
ee4c984bc7
commit
5fb0a2e274
27 changed files with 396 additions and 58 deletions
|
@ -259,12 +259,22 @@ export function useLayoutDocsSidebar(
|
|||
*
|
||||
* @throws This hook throws if a doc with said ID is not found.
|
||||
*/
|
||||
export function useLayoutDoc(docId: string, docsPluginId?: string): GlobalDoc {
|
||||
export function useLayoutDoc(
|
||||
docId: string,
|
||||
docsPluginId?: string,
|
||||
): GlobalDoc | null {
|
||||
const versions = useDocsVersionCandidates(docsPluginId);
|
||||
return useMemo(() => {
|
||||
const allDocs = versions.flatMap((version) => version.docs);
|
||||
const doc = allDocs.find((versionDoc) => versionDoc.id === docId);
|
||||
if (!doc) {
|
||||
const isDraft = versions
|
||||
.flatMap((version) => version.draftIds)
|
||||
.includes(docId);
|
||||
// drafts should be silently filtered instead of throwing
|
||||
if (isDraft) {
|
||||
return null;
|
||||
}
|
||||
throw new Error(
|
||||
`DocNavbarItem: couldn't find any doc with id "${docId}" in version${
|
||||
versions.length > 1 ? 's' : ''
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue