mirror of
https://github.com/nature-of-code/noc-book-2
synced 2024-11-16 07:47:48 +01:00
27 lines
678 B
JavaScript
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,
|
|
};
|