photosite/dist/build.js

48 lines
1.7 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
require("dotenv/config");
const log_1 = require("./log");
const promises_1 = require("fs/promises");
const path_1 = require("path");
const db_1 = require("./db");
const env_1 = require("./env");
const templates_1 = require("./templates");
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();
this.www = (0, env_1.envString)('WWW', './www');
this.main();
}
async main() {
let photos;
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();
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);
}
}
}
new Build();
//# sourceMappingURL=build.js.map