docs(nxdev): make sure category/index returns null if nothing is found (#12085)

This commit is contained in:
Benjamin Cabanes 2022-09-19 13:34:50 -04:00 committed by GitHub
parent 9312dff014
commit 515b33eb2a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 2 deletions

View File

@ -50,7 +50,7 @@ export class DocumentsApi {
* Generate the content of a "Category" or "Index" page, listing all its direct items.
* @param path
*/
getDocumentIndex(path: string[]): DocumentData {
getDocumentIndex(path: string[]): DocumentData | null {
let items = this.documents?.itemList;
let found: DocumentMetadata | null = null;
let itemPathToValidate: string[] = [];
@ -62,11 +62,14 @@ export class DocumentsApi {
items = found.itemList;
}
}
// If the ids have found the item, check that the segment correspond to the id tree
if (found && path.join('/') !== itemPathToValidate.join('/')) {
found = null;
}
if (!found) return null;
const cardListItems = items?.map((i) => ({
name: i.name,
path: i.path ?? '/' + path.concat(i.id).join('/'),

View File

@ -215,7 +215,7 @@ export const getStaticProps: GetStaticProps = async ({
};
}
let document: DocumentData | undefined;
let document: DocumentData | null = null;
try {
document = documentsApi.getDocument(params.segments);
} catch (e) {
@ -226,6 +226,7 @@ export const getStaticProps: GetStaticProps = async ({
} catch (e) {
// Do nothing
}
if (document) {
return {
props: {