docs(nxdev): make sure category/index returns null if nothing is found (#12085)
This commit is contained in:
parent
9312dff014
commit
515b33eb2a
@ -50,7 +50,7 @@ export class DocumentsApi {
|
|||||||
* Generate the content of a "Category" or "Index" page, listing all its direct items.
|
* Generate the content of a "Category" or "Index" page, listing all its direct items.
|
||||||
* @param path
|
* @param path
|
||||||
*/
|
*/
|
||||||
getDocumentIndex(path: string[]): DocumentData {
|
getDocumentIndex(path: string[]): DocumentData | null {
|
||||||
let items = this.documents?.itemList;
|
let items = this.documents?.itemList;
|
||||||
let found: DocumentMetadata | null = null;
|
let found: DocumentMetadata | null = null;
|
||||||
let itemPathToValidate: string[] = [];
|
let itemPathToValidate: string[] = [];
|
||||||
@ -62,11 +62,14 @@ export class DocumentsApi {
|
|||||||
items = found.itemList;
|
items = found.itemList;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the ids have found the item, check that the segment correspond to the id tree
|
// If the ids have found the item, check that the segment correspond to the id tree
|
||||||
if (found && path.join('/') !== itemPathToValidate.join('/')) {
|
if (found && path.join('/') !== itemPathToValidate.join('/')) {
|
||||||
found = null;
|
found = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!found) return null;
|
||||||
|
|
||||||
const cardListItems = items?.map((i) => ({
|
const cardListItems = items?.map((i) => ({
|
||||||
name: i.name,
|
name: i.name,
|
||||||
path: i.path ?? '/' + path.concat(i.id).join('/'),
|
path: i.path ?? '/' + path.concat(i.id).join('/'),
|
||||||
|
|||||||
@ -215,7 +215,7 @@ export const getStaticProps: GetStaticProps = async ({
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
let document: DocumentData | undefined;
|
let document: DocumentData | null = null;
|
||||||
try {
|
try {
|
||||||
document = documentsApi.getDocument(params.segments);
|
document = documentsApi.getDocument(params.segments);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -226,6 +226,7 @@ export const getStaticProps: GetStaticProps = async ({
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
// Do nothing
|
// Do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
if (document) {
|
if (document) {
|
||||||
return {
|
return {
|
||||||
props: {
|
props: {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user