Add open new page when configuring the menu

This commit is contained in:
Raven Scott 2024-09-26 18:19:30 -04:00
parent 2d89dcddf6
commit 6e02e0219a
5 changed files with 11 additions and 5 deletions

8
app.js
View File

@ -36,14 +36,20 @@ function loadMenuItems() {
const menuItems = [];
const titleRegex = /<!--\s*title:\s*(.*?)\s*-->/g;
const urlRegex = /<!--\s*url:\s*(.*?)\s*-->/g;
const openNewPageRegex = /<!--\s*openNewPage\s*-->/g;
let titleMatch;
let urlMatch;
let openNewPageMatch;
// Use a loop to find and process each menu item
while ((titleMatch = titleRegex.exec(content)) && (urlMatch = urlRegex.exec(content))) {
openNewPageMatch = openNewPageRegex.exec(content);
menuItems.push({
title: titleMatch[1],
url: urlMatch[1]
url: urlMatch[1],
openNewPage: openNewPageMatch !== null // If openNewPage exists, set it to true
});
}

View File

@ -34,7 +34,7 @@
<ul class="navbar-nav ms-auto">
<% menuItems.forEach(item => { %>
<li class="nav-item">
<a class="nav-link" href="<%= item.url %>"><%= item.title %></a>
<a class="nav-link" href="<%= item.url %>" <%= item.openNewPage ? 'target="_blank"' : '' %>><%= item.title %></a>
</li>
<% }) %>
</ul>

View File

@ -32,7 +32,7 @@
<ul class="navbar-nav ms-auto">
<% menuItems.forEach(item => { %>
<li class="nav-item">
<a class="nav-link" href="<%= item.url %>"><%= item.title %></a>
<a class="nav-link" href="<%= item.url %>" <%= item.openNewPage ? 'target="_blank"' : '' %>><%= item.title %></a>
</li>
<% }) %>
</ul>

View File

@ -37,7 +37,7 @@
<ul class="navbar-nav ms-auto">
<% menuItems.forEach(item => { %>
<li class="nav-item">
<a class="nav-link" href="<%= item.url %>"><%= item.title %></a>
<a class="nav-link" href="<%= item.url %>" <%= item.openNewPage ? 'target="_blank"' : '' %>><%= item.title %></a>
</li>
<% }) %>
</ul>

View File

@ -20,7 +20,7 @@
<ul class="navbar-nav ms-auto">
<% menuItems.forEach(item => { %>
<li class="nav-item">
<a class="nav-link" href="<%= item.url %>"><%= item.title %></a>
<a class="nav-link" href="<%= item.url %>" <%= item.openNewPage ? 'target="_blank"' : '' %>><%= item.title %></a>
</li>
<% }) %>
</ul>