Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add warning for including empty segments or files in optional mode #2506

Merged
merged 14 commits into from
Apr 18, 2024
5 changes: 4 additions & 1 deletion docs/userGuide/syntax/siteNavigationMenus.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ You can **append the `:expanded:` to a <tooltip content="a menu item with sub me

</div>

<div id="examples"></div>
<div id="examples" class="d-none">

You can see an example of a Site Navigation Menu ==on the left side== of <a target="_blank" href="{{ baseUrl }}/userGuide/formattingContents.html">this page</a>.
</div>

<div id="short" class="d-none">

Expand Down
10 changes: 10 additions & 0 deletions packages/core/src/html/includePanelProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -269,6 +275,10 @@ export function processInclude(node: MbNode, context: Context, pageSources: Page
logger.error(error);

actualContent = cheerio.html(createErrorNode(node, error));
} else if (actualContentOrNull === '') {
const warning = `Empty reference in ${context.cwf}:\n`
+ `Segment '${hash}' in file: ${actualFilePath} is empty`;
logger.warn(warning);
}
}

Expand Down