Refactor site templates to include footer partial and update page paths
- Added a footer partial to improve code reusability across templates. - Updated paths for the 'about' and 'badges' pages to 'om-oss.html' and 'om-markning.html', respectively. - Removed redundant footer code from individual templates, replacing it with a dynamic footer inclusion.
This commit is contained in:
29
build.js
29
build.js
@@ -199,7 +199,8 @@ function generateEntryPage(entry, template) {
|
|||||||
title: `${entry.title} | Ursprung Sverige`,
|
title: `${entry.title} | Ursprung Sverige`,
|
||||||
subtitle: entry.title,
|
subtitle: entry.title,
|
||||||
content: entryHtml,
|
content: entryHtml,
|
||||||
year: new Date().getFullYear()
|
year: new Date().getFullYear(),
|
||||||
|
footer: getFooter('../')
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -275,6 +276,19 @@ function generateFilterHTML(filters) {
|
|||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Load footer partial
|
||||||
|
function getFooter(rootPath = '') {
|
||||||
|
const footerPath = path.join(TEMPLATE_DIR, 'partials', 'footer.html');
|
||||||
|
if (!fs.existsSync(footerPath)) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
const footerTemplate = fs.readFileSync(footerPath, 'utf-8');
|
||||||
|
return renderTemplate(footerTemplate, {
|
||||||
|
year: new Date().getFullYear(),
|
||||||
|
rootPath
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Main build function
|
// Main build function
|
||||||
function build() {
|
function build() {
|
||||||
console.log('Building site...');
|
console.log('Building site...');
|
||||||
@@ -313,28 +327,31 @@ function build() {
|
|||||||
filters: generateFilterHTML(filters),
|
filters: generateFilterHTML(filters),
|
||||||
entries: generateEntryCards(entries),
|
entries: generateEntryCards(entries),
|
||||||
entryCount: entries.length,
|
entryCount: entries.length,
|
||||||
year: new Date().getFullYear()
|
year: new Date().getFullYear(),
|
||||||
|
footer: getFooter('')
|
||||||
});
|
});
|
||||||
|
|
||||||
// Write index.html
|
// Write index.html
|
||||||
fs.writeFileSync(path.join(DIST_DIR, 'index.html'), indexHtml);
|
fs.writeFileSync(path.join(DIST_DIR, 'index.html'), indexHtml);
|
||||||
|
|
||||||
// Generate badges info page
|
// Generate badges info page
|
||||||
const badgesTemplatePath = path.join(TEMPLATE_DIR, 'badges.html');
|
const badgesTemplatePath = path.join(TEMPLATE_DIR, 'om-markning.html');
|
||||||
if (fs.existsSync(badgesTemplatePath)) {
|
if (fs.existsSync(badgesTemplatePath)) {
|
||||||
const badgesTemplate = fs.readFileSync(badgesTemplatePath, 'utf-8');
|
const badgesTemplate = fs.readFileSync(badgesTemplatePath, 'utf-8');
|
||||||
const badgesHtml = renderTemplate(badgesTemplate, {
|
const badgesHtml = renderTemplate(badgesTemplate, {
|
||||||
year: new Date().getFullYear()
|
year: new Date().getFullYear(),
|
||||||
|
footer: getFooter('')
|
||||||
});
|
});
|
||||||
fs.writeFileSync(path.join(DIST_DIR, 'om-markning.html'), badgesHtml);
|
fs.writeFileSync(path.join(DIST_DIR, 'om-markning.html'), badgesHtml);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate about page
|
// Generate about page
|
||||||
const aboutTemplatePath = path.join(TEMPLATE_DIR, 'about.html');
|
const aboutTemplatePath = path.join(TEMPLATE_DIR, 'om-oss.html');
|
||||||
if (fs.existsSync(aboutTemplatePath)) {
|
if (fs.existsSync(aboutTemplatePath)) {
|
||||||
const aboutTemplate = fs.readFileSync(aboutTemplatePath, 'utf-8');
|
const aboutTemplate = fs.readFileSync(aboutTemplatePath, 'utf-8');
|
||||||
const aboutHtml = renderTemplate(aboutTemplate, {
|
const aboutHtml = renderTemplate(aboutTemplate, {
|
||||||
year: new Date().getFullYear()
|
year: new Date().getFullYear(),
|
||||||
|
footer: getFooter('')
|
||||||
});
|
});
|
||||||
fs.writeFileSync(path.join(DIST_DIR, 'om-oss.html'), aboutHtml);
|
fs.writeFileSync(path.join(DIST_DIR, 'om-oss.html'), aboutHtml);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,15 +75,6 @@
|
|||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
<footer class="site-footer">
|
{{ footer }}
|
||||||
<div class="container">
|
|
||||||
<p>Ursprung Sverige © {{ year }}</p>
|
|
||||||
<p class="footer-tagline">Stöd svensk ekonomi och kultur</p>
|
|
||||||
<nav class="footer-nav">
|
|
||||||
<a href="om-oss.html">Om oss</a>
|
|
||||||
<a href="om-markning.html">Om märkning</a>
|
|
||||||
</nav>
|
|
||||||
</div>
|
|
||||||
</footer>
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
@@ -65,15 +65,6 @@
|
|||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
<footer class="site-footer">
|
{{ footer }}
|
||||||
<div class="container">
|
|
||||||
<p>Ursprung Sverige © {{ year }}</p>
|
|
||||||
<p class="footer-tagline">Stöd svensk ekonomi och kultur</p>
|
|
||||||
<nav class="footer-nav">
|
|
||||||
<a href="om-oss.html">Om oss</a>
|
|
||||||
<a href="om-markning.html">Om märkning</a>
|
|
||||||
</nav>
|
|
||||||
</div>
|
|
||||||
</footer>
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
@@ -21,15 +21,6 @@
|
|||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
<footer class="site-footer">
|
{{ footer }}
|
||||||
<div class="container">
|
|
||||||
<p>Ursprung Sverige © {{ year }}</p>
|
|
||||||
<p class="footer-tagline">Stöd svensk ekonomi och kultur</p>
|
|
||||||
<nav class="footer-nav">
|
|
||||||
<a href="../om-oss.html">Om oss</a>
|
|
||||||
<a href="../om-markning.html">Om märkning</a>
|
|
||||||
</nav>
|
|
||||||
</div>
|
|
||||||
</footer>
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -43,16 +43,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
<footer class="site-footer">
|
{{ footer }}
|
||||||
<div class="container">
|
|
||||||
<p>Ursprung Sverige © {{ year }}</p>
|
|
||||||
<p class="footer-tagline">Stöd svensk ekonomi och kultur</p>
|
|
||||||
<nav class="footer-nav">
|
|
||||||
<a href="om-oss.html">Om oss</a>
|
|
||||||
<a href="om-markning.html">Om märkning</a>
|
|
||||||
</nav>
|
|
||||||
</div>
|
|
||||||
</footer>
|
|
||||||
|
|
||||||
<script src="filter.js"></script>
|
<script src="filter.js"></script>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
Reference in New Issue
Block a user