const fs = require('fs');
const data = `/xxxxx/old/1.html /xxxxx/new/1.html
/xxxxx/old/2.html /xxxxx/new/2.html
/xxxxx/old/3.html /xxxxx/new/3.html
/xxxxx/old/4.html /xxxxx/new/4.html
/xxxxx/old/5.html /xxxxx/new/5.html
/xxxxx/old/6.html /xxxxx/new/6.html
/xxxxx/old/7.html /xxxxx/new/7.html
/xxxxx/old/8.html /xxxxx/new/8.html
/xxxxx/old/9.html /xxxxx/new/9.html
/xxxxx/old/10.html /xxxxx/new/10.html
/xxxxx/old/11.html /xxxxx/new/11.html
/xxxxx/old/12.html /xxxxx/new/12.html
/xxxxx/old/13.html /xxxxx/new/13.html
/xxxxx/old/14.html /xxxxx/new/14.html
/xxxxx/old/15.html /xxxxx/new/15.html`;
let line = data.split("\n");
let getHtmlTitle = (url) => {
let html = fs.readFileSync('.' + url, 'utf8');
let title = html.match(/<title[\s\S]*?title>/)[0];
return title;
},
makeRedirect = (title, url) => {
return `<!doctype html>
<html>
<head>
<meta charset="utf-8">
${title}
<meta http-equiv="refresh" content="0;URL=${url}">
</head>
<body>
</body>
</html>`;
};
for(let i = 0; i < line.length; i++){
let html,
title;
line[i] = line[i].split("\t");
title = getHtmlTitle(line[i][0]);
html = makeRedirect(title, line[i][1]);
fs.writeFileSync('.' + line[i][0], html);
}