Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
const cheerio = require("cheerio");
const { readFileSync, writeFileSync } = require("fs");
const fs = require("fs");
var TurndownService = require("turndown");
const path = require("path");
const years = [
"2009",
"2010",
"2011",
"2012",
"2013",
"2014",
"2015",
"2016",
"2017",
"2018",
"2019",
"2020"
];
var turndownService = new TurndownService();
const re = /<\s*img[^>]*>(.*?)/g;
let md = "";
function test(year) {
const startPoint = `/home/tareef/websites/www.it-scoop.com/${year}/`;
const monthesDirs = fs.readdirSync(startPoint);
for (const dir of monthesDirs) {
const articles = fs.readdirSync(path.join(startPoint, dir));
for (const article of articles) {
const fromPath = path.join(startPoint, dir, article);
const isDir = fs.lstatSync(fromPath).isDirectory();
const isExist = fs.existsSync(`${fromPath}/index.html`);
if (isDir && isExist) {
const file = readFileSync(`${fromPath}/index.html`);
const $ = cheerio.load(file);
const html = $(".wrap.container").html();
const htmlWImg = html.replace(re, "");
md += htmlWImg;
} else {
return;
}
}
}
}
years.forEach(year => {
test(year);
});
writeFileSync("/home/tareef/it.html", md);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment