74 lines
1.8 KiB
JavaScript
74 lines
1.8 KiB
JavaScript
const fs = require("node:fs");
|
|
const path = require("node:path");
|
|
const pug = require("pug");
|
|
const sass = require("sass");
|
|
|
|
// Base directories
|
|
const srcDir = path.join(__dirname, "src");
|
|
const viewsDir = path.join(srcDir, "views");
|
|
const distDir = path.join(__dirname, "dist");
|
|
|
|
// Ensure dist directory exists
|
|
if (!fs.existsSync(distDir)) {
|
|
fs.mkdirSync(distDir, { recursive: true });
|
|
}
|
|
|
|
// Compile SCSS to CSS and save to dist
|
|
console.log("Compiling SCSS to CSS...");
|
|
try {
|
|
const result = sass.compile(path.join(srcDir, "styles.scss"), {
|
|
style: "compressed",
|
|
});
|
|
fs.writeFileSync(path.join(distDir, "styles.css"), result.css);
|
|
console.log("Successfully compiled SCSS to CSS");
|
|
} catch (error) {
|
|
console.error("Error compiling SCSS:", error);
|
|
}
|
|
|
|
// Define pages with their titles and taglines
|
|
const pages = [
|
|
{
|
|
name: "index",
|
|
title: "IRC Community",
|
|
tagline: "Modern IRC community",
|
|
},
|
|
{
|
|
name: "login",
|
|
title: "Login",
|
|
tagline: "Account Login",
|
|
},
|
|
{
|
|
name: "register",
|
|
title: "Registration",
|
|
tagline: "Account Registration",
|
|
},
|
|
{
|
|
name: "channels",
|
|
title: "Channels",
|
|
tagline: "IRC Channels",
|
|
},
|
|
];
|
|
|
|
// Compile each page
|
|
console.log("Compiling Pug templates to HTML...");
|
|
|
|
for (const page of pages) {
|
|
const pugFilePath = path.join(viewsDir, `${page.name}.pug`);
|
|
const htmlOutputPath = path.join(distDir, `${page.name}.html`);
|
|
|
|
try {
|
|
// Compile the template
|
|
const html = pug.renderFile(pugFilePath, {
|
|
title: page.title,
|
|
tagline: page.tagline,
|
|
});
|
|
|
|
// Write the compiled HTML to the output file
|
|
fs.writeFileSync(htmlOutputPath, html);
|
|
console.log(`Successfully compiled ${page.name}.pug to ${page.name}.html`);
|
|
} catch (error) {
|
|
console.error(`Error compiling ${page.name}.pug:`, error);
|
|
}
|
|
}
|
|
|
|
console.log("All files compiled successfully!");
|