fix menu system
This commit is contained in:
parent
62cd503704
commit
7e8297bb8b
22
app.js
22
app.js
@ -34,22 +34,20 @@ function loadMenuItems() {
|
||||
const content = fs.readFileSync(menuFile, 'utf-8');
|
||||
|
||||
const menuItems = [];
|
||||
const titleRegex = /<!--\s*title:\s*(.*?)\s*-->/g;
|
||||
const urlRegex = /<!--\s*url:\s*(.*?)\s*-->/g;
|
||||
const openNewPageRegex = /<!--\s*openNewPage\s*-->/g;
|
||||
const itemRegex = /<!--\s*title:\s*(.*?)\s*-->\s*(<!--\s*openNewPage\s*-->\s*)?<!--\s*url:\s*(.*?)\s*-->/g;
|
||||
|
||||
let titleMatch;
|
||||
let urlMatch;
|
||||
let openNewPageMatch;
|
||||
let match;
|
||||
|
||||
// Use a loop to find and process each menu item
|
||||
while ((titleMatch = titleRegex.exec(content)) && (urlMatch = urlRegex.exec(content))) {
|
||||
openNewPageMatch = openNewPageRegex.exec(content);
|
||||
// Loop to find all menu items
|
||||
while ((match = itemRegex.exec(content)) !== null) {
|
||||
const title = match[1];
|
||||
const url = match[3];
|
||||
const openNewPage = !!match[2]; // Check if openNewPage is present in the match
|
||||
|
||||
menuItems.push({
|
||||
title: titleMatch[1],
|
||||
url: urlMatch[1],
|
||||
openNewPage: openNewPageMatch !== null // If openNewPage exists, set it to true
|
||||
title,
|
||||
url,
|
||||
openNewPage
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -28,6 +28,7 @@
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
|
||||
<!-- Main Content -->
|
||||
<header class="py-5">
|
||||
<div class="container text-center">
|
||||
|
Loading…
Reference in New Issue
Block a user