photosite/dist/build.js

48 lines
1.7 KiB
JavaScript
Raw Normal View History

2024-01-06 05:25:07 +00:00
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
2024-01-08 20:10:39 +00:00
require("dotenv/config");
2024-01-06 05:25:07 +00:00
const log_1 = require("./log");
2024-12-11 02:38:41 +00:00
const promises_1 = require("fs/promises");
const path_1 = require("path");
const db_1 = require("./db");
2024-12-11 02:38:41 +00:00
const env_1 = require("./env");
const templates_1 = require("./templates");
2024-01-06 05:25:07 +00:00
class Build {
constructor() {
this.log = (0, log_1.createLog)('build');
this.log.info(`Building site: ${new Date()}`);
this.tmpl = new templates_1.Templates();
this.db = new db_1.DB();
2024-12-11 02:38:41 +00:00
this.www = (0, env_1.envString)('WWW', './www');
this.main();
}
async main() {
let photos;
2024-12-11 02:38:41 +00:00
let html;
let data = {
title: (0, env_1.envString)('TITLE', 'Unknown'),
h1: (0, env_1.envString)('H1', 'Unknown'),
artist: (0, env_1.envString)('ARTIST', 'Unknown'),
umami_url: (0, env_1.envString)('UMAMI_URL', null),
umami_id: (0, env_1.envString)('UMAMI_ID', null),
year: (new Date()).getFullYear()
};
let home = (0, path_1.join)(this.www, 'index.html');
await this.tmpl.build();
photos = await this.db.getAll();
2024-12-11 02:38:41 +00:00
photos = photos.map((photo) => {
photo.thumbHeight = Math.round((420.0 / photo.width) * photo.height) + 4;
return photo;
});
html = await this.tmpl.render('index', { ...data, photos });
try {
await (0, promises_1.writeFile)(home, html, 'utf8');
this.log.info(`Wrote ${home}`);
}
catch (err) {
this.log.error(`Error writing home page`, err);
}
2024-01-06 05:25:07 +00:00
}
}
new Build();
//# sourceMappingURL=build.js.map