@@ -2,7 +2,13 @@ import { readFileSync } from "fs";
22import { resolve } from "path" ;
33import type { LoadContext , Plugin } from "@docusaurus/types" ;
44import { getMarkdownSlugs } from "../src/lib/content-markdown" ;
5- import { recipes , examples , templates } from "../src/lib/recipes/recipes" ;
5+ import {
6+ recipes ,
7+ examples ,
8+ templates ,
9+ filterPublished ,
10+ } from "../src/lib/recipes/recipes" ;
11+ import { showDrafts , examplesEnabled } from "../src/lib/feature-flags-server" ;
612import { solutions } from "../src/lib/solutions/solutions" ;
713
814function assertNoDuplicateSlugs ( ) : void {
@@ -84,6 +90,22 @@ export default function ExampleEntryPage(): ReactNode {
8490}
8591
8692function getRegistrySlugs ( entryType : EntryType ) : string [ ] {
93+ const includeDrafts = showDrafts ( ) ;
94+ if ( entryType === "recipe" ) {
95+ return filterPublished ( recipes , includeDrafts )
96+ . map ( ( recipe ) => recipe . id )
97+ . sort ( ) ;
98+ }
99+ if ( entryType === "example" ) {
100+ if ( ! examplesEnabled ( ) ) return [ ] ;
101+ return filterPublished ( examples , includeDrafts )
102+ . map ( ( example ) => example . id )
103+ . sort ( ) ;
104+ }
105+ return solutions . map ( ( solution ) => solution . id ) . sort ( ) ;
106+ }
107+
108+ function getAllRegistrySlugs ( entryType : EntryType ) : string [ ] {
87109 if ( entryType === "recipe" ) {
88110 return recipes . map ( ( recipe ) => recipe . id ) . sort ( ) ;
89111 }
@@ -93,15 +115,11 @@ function getRegistrySlugs(entryType: EntryType): string[] {
93115 return solutions . map ( ( solution ) => solution . id ) . sort ( ) ;
94116}
95117
96- function assertSlugParity (
97- entryType : EntryType ,
98- contentSlugs : string [ ] ,
99- registrySlugs : string [ ] ,
100- ) : void {
101- const onlyInContent = contentSlugs . filter (
102- ( slug ) => ! registrySlugs . includes ( slug ) ,
103- ) ;
104- const onlyInRegistry = registrySlugs . filter (
118+ function assertSlugParity ( entryType : EntryType , contentSlugs : string [ ] ) : void {
119+ const allSlugs = getAllRegistrySlugs ( entryType ) ;
120+
121+ const onlyInContent = contentSlugs . filter ( ( slug ) => ! allSlugs . includes ( slug ) ) ;
122+ const onlyInRegistry = allSlugs . filter (
105123 ( slug ) => ! contentSlugs . includes ( slug ) ,
106124 ) ;
107125
@@ -135,11 +153,12 @@ export default function contentEntriesPlugin(
135153 context . siteDir ,
136154 options . contentSection ,
137155 ) ;
138- const registrySlugs = getRegistrySlugs ( options . entryType ) ;
139- assertSlugParity ( options . entryType , contentSlugs , registrySlugs ) ;
156+ assertSlugParity ( options . entryType , contentSlugs ) ;
157+
158+ const publishedSlugs = getRegistrySlugs ( options . entryType ) ;
140159
141160 const rawMarkdownBySlug : Record < string , string > = { } ;
142- for ( const slug of contentSlugs ) {
161+ for ( const slug of publishedSlugs ) {
143162 const filePath = resolve (
144163 context . siteDir ,
145164 "content" ,
@@ -152,11 +171,11 @@ export default function contentEntriesPlugin(
152171 setGlobalData ( {
153172 entryType : options . entryType ,
154173 routeBasePath : options . routeBasePath ,
155- slugs : contentSlugs ,
174+ slugs : publishedSlugs ,
156175 rawMarkdownBySlug,
157176 } ) ;
158177
159- for ( const slug of contentSlugs ) {
178+ for ( const slug of publishedSlugs ) {
160179 const modulePath = await createData (
161180 `${ options . id } -${ slug } -route.tsx` ,
162181 createRouteModuleSource ( options . entryType , slug ) ,
0 commit comments