async function pugify(filename, options, isReload = false) {
  /** Path for the output file */
  let newfile = undefined;
  options = options || {};
  options.package = pkg;
  // const isAPI = options.api && !filename.endsWith('docs/api.pug');

  const _editLink = 'https://github.com/Automattic/mongoose/blob/master' +
    filename.replace(cwd, '');
  options.editLink = options.editLink || _editLink;

  /** Set which path to read, also pug uses this to resolve relative includes from */
  let inputFile = filename;

  if (options.api) {
    // only re-parse the api file when in a reload, because it is done once at file load
    if (isReload) {
      apiReq.parseFile(options.file);
      // overwrite original options because of reload
      options = { ...options, ...apiReq.docs.get(options.file) };
    }
    inputFile = path.resolve(cwd, 'docs/api_split.pug');
  }

  let contents = fs.readFileSync(path.resolve(cwd, inputFile)).toString();

  if (options.acquit) {
    contents = transform(contents, getTests());

    contents = contents.replaceAll(/^```acquit$/gmi, '```javascript');
  }
  if (options.markdown) {
    const lines = contents.split('\n');
    lines.splice(2, 0, cpc);
    contents = lines.join('\n');
    contents = wrapMarkdown(
      contents,
      path.relative(path.dirname(filename), path.join(cwd, 'docs/layout')),
      versionObj.versionedPath
    );
    newfile = filename.replace('.md', '.html');
  }

  options.filename = inputFile;
  options.filters = {
    markdown: function(block) {
      return markdown.parse(block);
    }
  };

  if (options.api) {
    newfile = path.resolve(cwd, filename);
    options.docs = Array.from(docsFilemap.apiDocs.values());
  }

  newfile = newfile || filename.replace('.pug', '.html');

  /** Unversioned final documentation path */
  const docsPath = newfile;

  if (versionObj.versionedDeploy) {
    newfile = path.resolve(cwd, path.join('.', versionObj.versionedPath), path.relative(cwd, newfile));
    await fs.promises.mkdir(path.dirname(newfile), { recursive: true });
  }

  options.outputUrl = newfile.replace(cwd, '');
  options.jobs = jobs;
  options.versions = versionObj;

  options.opencollectiveSponsors = opencollectiveSponsors;

  let str = await pugRender(contents, options).catch(console.error);

  if (typeof str !== 'string') {
    return;
  }

  str = mapURLs(str, '/' + path.relative(cwd, docsPath));

  await fs.promises.writeFile(newfile, str).catch((err) => {
    console.error('could not write', err.stack);
  }).then(() => {
    console.log('%s : rendered %s', (new Date()).toISOString(), newfile);
  });
}
Render a given file with the given options
@param {String} filename The documentation file path to render
@param {import("../docs/source/index").DocsOptions} options The options to use to render the file (api may be overwritten at reload)
@param {Boolean} isReload Indicate this is a reload of the file
@returns