This is the template project that's checked out and configured when you run the bando-up command from ljsthw-bandolier. This is where the code really lives.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
bandolier-template/commands/gen_players.js

35 lines
1.0 KiB

import { knex } from "../lib/ormish.js";
import { Media } from "../lib/models.js";
import { base_host, site_name } from "../client/config.js";
import fs from "fs";
import _ from "lodash";
export const description = "Generates the bare player.html files for the Twitter cards.";
export const options = [
["--target <dirwithslash>", "directory to write files (end with /)", "./public/video/"],
["--template <filename>", "file to use for template", "rendered/player.html"]
];
export const main = async (opts) => {
const player = _.template(fs.readFileSync(opts.template));
if(!opts.target.endsWith("/")) {
console.error(`--target path must end in slash / but you have: ${ opts.target }`);
process.exit(1);
}
const all_media = await Media.all(knex.raw("title is not null"));
for(let media of all_media) {
const html = player({ base_host, site_name, media });
const outname = `${ opts.target }${ media.id }-${ media.slug }/player.html`;
fs.writeFileSync(outname, html);
}
process.exit(0);
}
export default { main };