Created
April 23, 2020 17:06
-
-
Save tareefdev/523f785ccb36aae0dd20746b52d70047 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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