@@ -6,11 +6,12 @@ interface Props {
66 basePath: string ;
77 title? : string ;
88 customTitles? : Record <string , string >;
9+ useDirectFiles? : boolean ;
910}
1011
11- const { basePath, title, customTitles = {} } = Astro .props ;
12+ const { basePath, title, customTitles = {}, useDirectFiles = false } = Astro .props ;
1213
13- // Get only index files from immediate subdirectories
14+ // Get sections - either index files from subdirectories or direct files
1415const allSections = await getCollection (' docs' , ({ id }) => {
1516 // Must start with the base path
1617 if (! id .startsWith (basePath )) {
@@ -23,25 +24,20 @@ const allSections = await getCollection('docs', ({ id }) => {
2324 // Split into parts and filter out empty strings
2425 const pathParts = relativePath .split (' /' ).filter (part => part !== ' ' );
2526
26- // For index files, we should have exactly 1 part: [subdirectory]
27- // because index files get the ID of their parent directory in Astro
28- if (pathParts .length === 1 ) {
29- const subdirectory = pathParts [0 ];
30-
31- // These are the known subdirectories with index files
32- const validSubdirectories = [
33- ' web-app' ,
34- ' config' ,
35- ' cloud-sandbox' ,
36- ' networking' ,
37- ' state-management' ,
38- ' chaos-engineering' ,
39- ' security-testing'
40- ];
41-
42-
43-
44- return validSubdirectories .includes (subdirectory );
27+ if (useDirectFiles ) {
28+ // For direct files, we should have exactly 1 part: [filename]
29+ // and it should not be an index file
30+ if (pathParts .length === 1 ) {
31+ const filename = pathParts [0 ];
32+ return ! filename .startsWith (' index' );
33+ }
34+ } else {
35+ // For index files, we should have exactly 1 part: [subdirectory]
36+ // because index files get the ID of their parent directory in Astro
37+ if (pathParts .length === 1 ) {
38+ // Accept any single-level subdirectory - let the content collection handle validation
39+ return true ;
40+ }
4541 }
4642
4743 return false ;
@@ -54,12 +50,15 @@ const sortedSections = allSections.sort((a, b) => {
5450});
5551
5652const sectionData = sortedSections .map (section => {
57- // Extract the subdirectory name from the section ID
53+ // Extract the key name from the section ID
5854 const relativePath = section .id .substring (basePath .length );
59- const subdirectory = relativePath .split (' /' ).filter (part => part !== ' ' )[0 ];
55+ const keyName = relativePath .split (' /' ).filter (part => part !== ' ' )[0 ];
56+
57+ // For direct files, we need to remove the file extension from the key
58+ const cleanKey = useDirectFiles ? keyName .replace (/ \. (md| mdx)$ / , ' ' ) : keyName ;
6059
6160 // Use custom title if provided, otherwise fall back to the section title
62- const sectionTitle = customTitles [subdirectory ] || section .data .title || section .data .linkTitle || ' Unknown Section' ;
61+ const sectionTitle = customTitles [cleanKey ] || section .data .title || section .data .linkTitle || ' Unknown Section' ;
6362 const description = section .data .description || ` Learn more about ${sectionTitle } ` ;
6463
6564 const href = ` /${section .id } ` ;
0 commit comments