Skip to content

Commit

Permalink
Get examples from file system instead of crawling website
Browse files Browse the repository at this point in the history
  • Loading branch information
bartaz committed Apr 4, 2024
1 parent 481aed5 commit e1ecbe5
Showing 1 changed file with 27 additions and 9 deletions.
36 changes: 27 additions & 9 deletions snapshots.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
const fs = require('fs');
const path = require('path');

const PORT = process.env.PORT || 8101;

module.exports = async () => {
const {default: GetSiteUrls} = await import('get-site-urls');
let links = await GetSiteUrls(`http://0.0.0.0:${PORT}/`);
let urls = [];
async function getExampleFiles() {
//
let files = await fs.promises.readdir(path.join(process.cwd(), 'templates/docs/examples'), {recursive: true});

files = files.filter((file) => path.dirname(file) !== '.' && file.endsWith('.html') && !path.basename(file).startsWith('_'));

return files;
}

links = links.found
// only snapshot examples, not the whole site
.filter((url) => url.includes('/docs/examples/'))
// remove standalone examples listing from screenshots
.filter((url) => !url.match(/examples\/standalone$/));
const DOCS_URL = `http://localhost:${PORT}/docs/examples/`;

function getExampleUrls(files) {
return files.map((file) => {
file = file.replace('.html', '');
return DOCS_URL + file;
});
}

async function run() {
let links = getExampleUrls(await getExampleFiles());
let urls = [];

for (var i = 0; i < links.length; i++) {
const url = links[i];
Expand All @@ -25,4 +39,8 @@ module.exports = async () => {
}

return urls;
}

module.exports = async () => {
return await run();
};

0 comments on commit e1ecbe5

Please sign in to comment.