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`,
|
||||
subtitle: entry.title,
|
||||
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
|
||||
function build() {
|
||||
console.log('Building site...');
|
||||
@@ -313,28 +327,31 @@ function build() {
|
||||
filters: generateFilterHTML(filters),
|
||||
entries: generateEntryCards(entries),
|
||||
entryCount: entries.length,
|
||||
year: new Date().getFullYear()
|
||||
year: new Date().getFullYear(),
|
||||
footer: getFooter('')
|
||||
});
|
||||
|
||||
// Write index.html
|
||||
fs.writeFileSync(path.join(DIST_DIR, 'index.html'), indexHtml);
|
||||
|
||||
// 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)) {
|
||||
const badgesTemplate = fs.readFileSync(badgesTemplatePath, 'utf-8');
|
||||
const badgesHtml = renderTemplate(badgesTemplate, {
|
||||
year: new Date().getFullYear()
|
||||
year: new Date().getFullYear(),
|
||||
footer: getFooter('')
|
||||
});
|
||||
fs.writeFileSync(path.join(DIST_DIR, 'om-markning.html'), badgesHtml);
|
||||
}
|
||||
|
||||
// Generate about page
|
||||
const aboutTemplatePath = path.join(TEMPLATE_DIR, 'about.html');
|
||||
const aboutTemplatePath = path.join(TEMPLATE_DIR, 'om-oss.html');
|
||||
if (fs.existsSync(aboutTemplatePath)) {
|
||||
const aboutTemplate = fs.readFileSync(aboutTemplatePath, 'utf-8');
|
||||
const aboutHtml = renderTemplate(aboutTemplate, {
|
||||
year: new Date().getFullYear()
|
||||
year: new Date().getFullYear(),
|
||||
footer: getFooter('')
|
||||
});
|
||||
fs.writeFileSync(path.join(DIST_DIR, 'om-oss.html'), aboutHtml);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user