assemblyline.sh

Helpers for station code

import { renderLocal, pooled, countWords, stripFrontmatter } from '@assemblyline/lib-factory';

renderLocal(importMetaUrl, relativePath, data)

Reads an EJS template relative to the calling file and renders it with data. Returns the rendered string.

ArgumentWhat it is
importMetaUrlThe caller's import.meta.url
relativePathThe template's path from the caller's folder, such as './report.md'
dataThe template's variables
await ctx.attachReport(renderLocal(import.meta.url, './report.md', { results, counts }));

It reads the file on every call and throws when it is missing. How to write a template: Write reports from templates.

pooled(items, concurrency, fn)

Runs async fn(item, index) on every item, with at most concurrency running at once. Returns the results in the order of items. A throw in fn rejects the whole call.

const pages = await pooled(page_numbers, 4, (n) => renderPage(pdf, n));

countWords(text)

The number of whitespace-separated words in text.

stripFrontmatter(markdown)

Removes a leading YAML frontmatter block (--- … ---) and the whitespace after it. Returns the text unchanged when it has none.