blowfish/processUsers.js

84 lines
2.2 KiB
JavaScript
Raw Normal View History

2023-07-14 05:12:21 -05:00
const fs = require('fs');
const puppeteer = require("puppeteer");
const usersFolderPath = "./exampleSite/content/users/"
let rawdata = fs.readFileSync(usersFolderPath + 'users.json');
let users = JSON.parse(rawdata);
2023-07-14 05:28:12 -05:00
const files = fs.readdirSync(usersFolderPath);
console.log(files);
2023-07-14 05:12:21 -05:00
2023-07-14 05:28:12 -05:00
for (file in files) {
2023-07-14 05:12:21 -05:00
2023-07-14 05:28:12 -05:00
let stats = fs.statSync(usersFolderPath + files[file]);
if (files[file] != 'users.json' && files[file] != '_index.md' && files[file] != 'tempusers.txt' && files[file] != 'oldindex.md') {
console.log('deleting: ', files[file]);
if (stats.isDirectory()) {
fs.rmdirSync(usersFolderPath + files[file], { recursive: true, force: true });
} else {
fs.unlinkSync(usersFolderPath + files[file]);
}
}
}
2023-07-14 05:12:21 -05:00
2023-07-14 05:28:12 -05:00
puppeteer
.launch({
defaultViewport: {
width: 1280,
height: 800,
},
})
.then(async (browser) => {
2023-07-14 05:12:21 -05:00
2023-07-14 05:28:12 -05:00
const page = await browser.newPage();
2023-07-14 05:12:21 -05:00
2023-07-14 05:28:12 -05:00
for (var i in users) {
console.log(i, users[i].title);
var userMDFile = "---\n\
title: \""+ users[i].title + "\"\n\
slug: \"users\"\n\
tags: []\n\
externalUrl: \""+ users[i].url + "\"\n\
showDate: false\n\
showAuthor: false\n\
showReadingTime: false\n\
showEdit: false\n\
showLikes: false\n\
showViews: false\n\
layoutBackgroundHeaderSpace: false\n\
\r---\n";
var dir = usersFolderPath + i + users[i].title;
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir);
}
fs.writeFileSync(dir + '/index.md', userMDFile);
await page.goto(users[i].url);
await page.screenshot({ path: dir + "/feature.png" });
}
await browser.close();
});
2023-07-14 05:12:21 -05:00
/*
puppeteer
.launch({
defaultViewport: {
width: 1280,
height: 800,
},
})
.then(async (browser) => {
const page = await browser.newPage();
await page.goto("https://nytimes.com");
await page.screenshot({ path: "nyt-puppeteer.png" });
await browser.close();
});*/