Skip to content

Instantly share code, notes, and snippets.

@WatheqAlshowaiter
Forked from tareefdev/it-scoop.js
Created April 23, 2020 17:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WatheqAlshowaiter/0b8f8f63b0f067f62ab434c938e138bb to your computer and use it in GitHub Desktop.
Save WatheqAlshowaiter/0b8f8f63b0f067f62ab434c938e138bb to your computer and use it in GitHub Desktop.
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