noc-book-2/tests/utils.js
2023-10-08 14:56:44 -04:00

27 lines
678 B
JavaScript

const cheerio = require('cheerio');
const fs = require('node:fs');
const glob = require('glob');
const path = require('node:path');
function getEditorUrls() {
const editorUrls = new Map();
glob.sync('content/*.html').forEach((htmlFilePath) => {
const source = fs.readFileSync(htmlFilePath);
const $ = cheerio.load(source.toString());
$('[data-example-path]').each((_, el) => {
const $el = $(el);
const examplePath = $el.attr('data-example-path');
const editorUrl = $el.attr('data-p5-editor');
editorUrls.set(path.join('content/', examplePath), editorUrl);
});
});
return editorUrls;
}
module.exports = {
getEditorUrls,
};