forked from OceanUwU/slaytabase
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrenametoids.js
More file actions
30 lines (26 loc) · 1.43 KB
/
renametoids.js
File metadata and controls
30 lines (26 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import fs from 'fs';
let data = JSON.parse(fs.readFileSync('./docs/data.json'));
let oldRedirects = [[],[]];
for (let c of data.cards) {
let modPath = `./docs/${c.mod}/`
let oldPath = `cards/${c.color.slice(0,10)}-${c.name.replaceAll(' ', '').replaceAll(':', '-').replaceAll('\'', '').replaceAll('?', '').replaceAll('"', '').replaceAll('/', '')}.png`;
let newPath = `cards/${c.id.replaceAll(' ', '').replaceAll(':', '-').replaceAll('\'', '').replaceAll('?', '').replaceAll('"', '').replaceAll('/', '')}.png`;
if (fs.existsSync(modPath+oldPath))
fs.renameSync(modPath+oldPath, modPath+newPath);
let wikiPath = modPath+'index.html';
fs.writeFileSync(wikiPath, fs.readFileSync(wikiPath, 'utf-8').replaceAll(oldPath, newPath));
oldRedirects[0].push(encodeURI(oldPath));
oldRedirects[1].push(encodeURI(newPath));
}
for (let p of data.potions) {
let modPath = `./docs/${p.mod}/`
let oldPath = `potions/${p.name.replaceAll(' ', '')}.png`;
let newPath = `potions/${p.id.replaceAll(' ', '').replaceAll(':', '-')}.png`;
if (fs.existsSync(modPath+oldPath))
fs.renameSync(modPath+oldPath, modPath+newPath);
let wikiPath = modPath+'index.html';
fs.writeFileSync(wikiPath, fs.readFileSync(wikiPath, 'utf-8').replaceAll(oldPath, newPath));
oldRedirects[0].push(encodeURI(oldPath));
oldRedirects[1].push(encodeURI(newPath));
}
fs.writeFileSync('./oldredirects.json', JSON.stringify(oldRedirects));