OurBigBook logoOurBigBook Docs OurBigBook logoOurBigBook.comSite Source code
Rerender all articles by all users:
web/bin/rerender-articles.js
Rerender only the articles with specified slugs:
web/bin/rerender-articles.js johnsmith/mathematics maryjane/physics
Only rerender articles by johnsmith and maryjane:
web/bin/rerender-articles.js -a johnsmith -a maryjane
Rerender articles by all authors except johnsmith and maryjane:
web/bin/rerender-articles.js -A johnsmith -A maryjane
Rerendering has to be done to see updates on OurBigBook changes that change the render output.
Notably, this would be mandatory in case of CSS changes that require corresponding HTML changes.
As the website grows, we will likely need to do a lazy version of this that marks pages as outdated, and then renders on the fly, plus a background thread that always updates outdated pages.
The functionality of this script should be called from a migration whenever such HTML changes are required. TODO link to an example. We had one at web/migrations/20220321000000-output-update-ancestor.js that seemed to work, but lost it. It was simple though. Just you have to instantiate your own Sequelize instance after making the model change to move any data.
web/bin/rerender-articles.js
#!/usr/bin/env node

const path = require('path')

const commander = require('commander')

const models = require('../models')
const back_js = require('../back/js')
const { cliInt } = require('ourbigbook/nodejs_webpack_safe')

const program = commander.program
program.description('Re-render articles https://docs.ourbigbook.com/_file/web/bin/rerender-articles.js')
program.option('-a, --author <username>', 'only convert articles by this author', (v, p) => p.concat([v]), [])
program.option('--automatic-topic-links-max-words <val>', 'maximum number of words to put on automatic topic links', cliInt)
program.option('-A, --skip-author <username>', "don't convert articles by this author", (v, p) => p.concat([v]), [])
program.option('-d, --descendants', 'rerender all descendants of input slugs in addition to the articles themselves. Has no effect if no slugs are given as input (everything gets converted regardless in that case).')
program.option('-i, --ignore-errors', 'ignore errors', false)
program.argument('[slugs...]', 'list of slugs to convert, e.g. "barack-obama/quantum-mechanics". If not given, convert all articles matching the criteria of other options.')
program.parse(process.argv);
const opts = program.opts()
let [slugs] = program.processedArgs
const sequelize = models.getSequelize(path.dirname(__dirname));
(async () => {
await sequelize.models.Article.rerender({
  log: true,
  convertOptionsExtra: {
    automaticTopicLinksMaxWords: opts.automaticTopicLinksMaxWords,
    katex_macros: back_js.preloadKatex(),
  },
  authors: opts.author,
  descendants: opts.descendants,
  ignoreErrors: opts.ignoreErrors,
  slugs,
  skipAuthors: opts.skipAuthor,
})
})().finally(() => { return sequelize.close() });

Ancestors (6)

  1. Web CLI utils
  2. OurBigBook Web directory structure
  3. OurBigBook Web architecture
  4. OurBigBook Web development
  5. OurBigBook Web
  6. Home