From b543339009a395b7ffc6117635095b2ad373231f Mon Sep 17 00:00:00 2001 From: Tim-Siu Date: Sun, 7 Apr 2024 11:07:10 +0800 Subject: [PATCH 01/10] Add warning for empty segment includes --- packages/core/src/html/includePanelProcessor.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/core/src/html/includePanelProcessor.ts b/packages/core/src/html/includePanelProcessor.ts index ce83e64eab..83c695c102 100644 --- a/packages/core/src/html/includePanelProcessor.ts +++ b/packages/core/src/html/includePanelProcessor.ts @@ -66,7 +66,7 @@ function _getBoilerplateFilePath(element: MbNode, filePath: string, config: Reco function _getSrcFlagsAndFilePaths(element: MbNode, config: Record) { const isUrl = urlUtil.isUrl(element.attribs.src); - // We do this even if the src is not a url to get the hash, if any + // We do this even if the src is not an url to get the hash, if any const includeSrc = parse(element.attribs.src); let filePath; @@ -269,6 +269,10 @@ export function processInclude(node: MbNode, context: Context, pageSources: Page logger.error(error); actualContent = cheerio.html(createErrorNode(node, error)); + } else if (actualContentOrNull === null && isOptional) { + const warning = `Optional segment '${hash}' not found in file: ${actualFilePath}\n` + + `Empty reference in ${context.cwf}`; + logger.info(warning); } } From d0e7b69eea24de2dee78d3432c1855e6ce4e08db Mon Sep 17 00:00:00 2001 From: Tim-Siu Date: Sun, 7 Apr 2024 11:26:22 +0800 Subject: [PATCH 02/10] Add warning for empty includes --- packages/core/src/html/includePanelProcessor.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/core/src/html/includePanelProcessor.ts b/packages/core/src/html/includePanelProcessor.ts index 83c695c102..067871c34f 100644 --- a/packages/core/src/html/includePanelProcessor.ts +++ b/packages/core/src/html/includePanelProcessor.ts @@ -31,6 +31,9 @@ function _checkAndWarnFileExists(element: MbNode, context: Context, actualFilePa pageSources: PageSources, isOptional = false) { if (!fsUtil.fileExists(actualFilePath)) { if (isOptional) { + const warning = `Optional file not found: ${actualFilePath}\n` + + `Empty reference in ${context.cwf}`; + logger.warn(warning); return false; } @@ -272,7 +275,7 @@ export function processInclude(node: MbNode, context: Context, pageSources: Page } else if (actualContentOrNull === null && isOptional) { const warning = `Optional segment '${hash}' not found in file: ${actualFilePath}\n` + `Empty reference in ${context.cwf}`; - logger.info(warning); + logger.warn(warning); } } From 0a704b2274540e56483ff90ab7781e04a1efc4b8 Mon Sep 17 00:00:00 2001 From: Tim-Siu Date: Mon, 8 Apr 2024 11:50:47 +0800 Subject: [PATCH 03/10] Update the behaviours --- packages/core/src/html/includePanelProcessor.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/core/src/html/includePanelProcessor.ts b/packages/core/src/html/includePanelProcessor.ts index 067871c34f..bf8c87eedf 100644 --- a/packages/core/src/html/includePanelProcessor.ts +++ b/packages/core/src/html/includePanelProcessor.ts @@ -272,9 +272,9 @@ export function processInclude(node: MbNode, context: Context, pageSources: Page logger.error(error); actualContent = cheerio.html(createErrorNode(node, error)); - } else if (actualContentOrNull === null && isOptional) { - const warning = `Optional segment '${hash}' not found in file: ${actualFilePath}\n` - + `Empty reference in ${context.cwf}`; + } else if (actualContentOrNull === '') { + const warning = `Segment '${hash}' in file: ${actualFilePath} is empty\n` + + `Empty reference in ${context.cwf}`; logger.warn(warning); } } From 12e6c10c17b27859372259e18648eac8d872b96a Mon Sep 17 00:00:00 2001 From: Tim-Siu Date: Mon, 8 Apr 2024 12:00:32 +0800 Subject: [PATCH 04/10] Remove legacy code --- packages/core/src/html/includePanelProcessor.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/packages/core/src/html/includePanelProcessor.ts b/packages/core/src/html/includePanelProcessor.ts index bf8c87eedf..f5cfe5a126 100644 --- a/packages/core/src/html/includePanelProcessor.ts +++ b/packages/core/src/html/includePanelProcessor.ts @@ -31,9 +31,6 @@ function _checkAndWarnFileExists(element: MbNode, context: Context, actualFilePa pageSources: PageSources, isOptional = false) { if (!fsUtil.fileExists(actualFilePath)) { if (isOptional) { - const warning = `Optional file not found: ${actualFilePath}\n` - + `Empty reference in ${context.cwf}`; - logger.warn(warning); return false; } From cc6b8cb243acd3731a873d9ad878314d427a4904 Mon Sep 17 00:00:00 2001 From: "Shuyao \"Tim\" Xu" <61866948+Tim-Siu@users.noreply.github.com> Date: Sun, 14 Apr 2024 00:00:40 +0800 Subject: [PATCH 05/10] Apply suggestions from code review Co-authored-by: Chan Yu Cheng <77204346+yucheng11122017@users.noreply.github.com> --- packages/core/src/html/includePanelProcessor.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/core/src/html/includePanelProcessor.ts b/packages/core/src/html/includePanelProcessor.ts index f5cfe5a126..543585813d 100644 --- a/packages/core/src/html/includePanelProcessor.ts +++ b/packages/core/src/html/includePanelProcessor.ts @@ -270,8 +270,8 @@ export function processInclude(node: MbNode, context: Context, pageSources: Page actualContent = cheerio.html(createErrorNode(node, error)); } else if (actualContentOrNull === '') { - const warning = `Segment '${hash}' in file: ${actualFilePath} is empty\n` - + `Empty reference in ${context.cwf}`; + const warning = `Empty reference in ${context.cwf}:\n` + + `Segment '${hash}' in file: ${actualFilePath} is empty`; logger.warn(warning); } } From ed5e8b14024fa5813f29f1c345a8e8496735d4cc Mon Sep 17 00:00:00 2001 From: Tim-Siu Date: Sun, 14 Apr 2024 00:06:37 +0800 Subject: [PATCH 06/10] Add examples in siteNavigationMenus.md --- docs/userGuide/syntax/siteNavigationMenus.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/userGuide/syntax/siteNavigationMenus.md b/docs/userGuide/syntax/siteNavigationMenus.md index 399b3b31da..3e1c456ab6 100644 --- a/docs/userGuide/syntax/siteNavigationMenus.md +++ b/docs/userGuide/syntax/siteNavigationMenus.md @@ -51,3 +51,8 @@ You can **append the `:expanded:` to a + +You can see an example of a Site Navigation Menu ==on the top== of this page. + From e818a570d7c8d38e735d6088f76c506b5fac293e Mon Sep 17 00:00:00 2001 From: Tim-Siu Date: Sun, 14 Apr 2024 00:24:45 +0800 Subject: [PATCH 07/10] Warn empty include file --- packages/core/src/html/includePanelProcessor.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/core/src/html/includePanelProcessor.ts b/packages/core/src/html/includePanelProcessor.ts index 543585813d..705d0e05ee 100644 --- a/packages/core/src/html/includePanelProcessor.ts +++ b/packages/core/src/html/includePanelProcessor.ts @@ -228,6 +228,12 @@ export function processInclude(node: MbNode, context: Context, pageSources: Page childContext, } = variableProcessor.renderIncludeFile(actualFilePath, pageSources, node, context, filePath); + if (nunjucksProcessed.trim() === '') { + const warning = `Empty file included in ${context.cwf}:\n` + + `File: ${actualFilePath} is empty or contains only whitespace`; + logger.warn(warning); + } + let actualContent = nunjucksProcessed; if (fsUtil.isMarkdownFileExt(path.extname(actualFilePath))) { actualContent = isInline From e2424b19d871d54ef1e8fddbf0c63a8fb3410d4c Mon Sep 17 00:00:00 2001 From: Tim-Siu Date: Sun, 14 Apr 2024 00:28:19 +0800 Subject: [PATCH 08/10] Fix typo --- packages/core/src/html/includePanelProcessor.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/src/html/includePanelProcessor.ts b/packages/core/src/html/includePanelProcessor.ts index 705d0e05ee..3458c59483 100644 --- a/packages/core/src/html/includePanelProcessor.ts +++ b/packages/core/src/html/includePanelProcessor.ts @@ -66,7 +66,7 @@ function _getBoilerplateFilePath(element: MbNode, filePath: string, config: Reco function _getSrcFlagsAndFilePaths(element: MbNode, config: Record) { const isUrl = urlUtil.isUrl(element.attribs.src); - // We do this even if the src is not an url to get the hash, if any + // We do this even if the src is not a url to get the hash, if any const includeSrc = parse(element.attribs.src); let filePath; From fef8cedd123a74d28e0b9a868c898814ceab90f0 Mon Sep 17 00:00:00 2001 From: Tim-Siu Date: Sun, 14 Apr 2024 00:37:59 +0800 Subject: [PATCH 09/10] Fix redundant example --- docs/userGuide/syntax/siteNavigationMenus.md | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/docs/userGuide/syntax/siteNavigationMenus.md b/docs/userGuide/syntax/siteNavigationMenus.md index 3e1c456ab6..f1943a8136 100644 --- a/docs/userGuide/syntax/siteNavigationMenus.md +++ b/docs/userGuide/syntax/siteNavigationMenus.md @@ -34,7 +34,10 @@ You can **append the `:expanded:` to a +
+ +You can see an example of a Site Navigation Menu ==on the top== of this page. +
@@ -51,8 +54,3 @@ You can **append the `:expanded:` to a - -You can see an example of a Site Navigation Menu ==on the top== of this page. -
From 9cd7de939d904e5d92295a144c9f2c3dd01177f0 Mon Sep 17 00:00:00 2001 From: Tim-Siu Date: Mon, 15 Apr 2024 12:41:57 +0800 Subject: [PATCH 10/10] Fix wrong information --- docs/userGuide/syntax/siteNavigationMenus.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/userGuide/syntax/siteNavigationMenus.md b/docs/userGuide/syntax/siteNavigationMenus.md index f1943a8136..2a333a665e 100644 --- a/docs/userGuide/syntax/siteNavigationMenus.md +++ b/docs/userGuide/syntax/siteNavigationMenus.md @@ -36,7 +36,7 @@ You can **append the `:expanded:` to a -You can see an example of a Site Navigation Menu ==on the top== of this page. +You can see an example of a Site Navigation Menu ==on the left side== of this page.