-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathextract_elementor.js
More file actions
30 lines (26 loc) · 874 Bytes
/
extract_elementor.js
File metadata and controls
30 lines (26 loc) · 874 Bytes
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
const fs = require("fs");
const path = require("path");
const skipExisting = process.argv[2] === "skipExisting";
console.log(`Skipping existing files: ${skipExisting}`);
const specificFile = process.argv[2];
const rootDir = path.join(path.dirname(__filename), "pages");
const outputDir = path.join(path.dirname(__filename), "elementor");
const files = fs.readdirSync(rootDir);
files.forEach((file) => {
if (!file.endsWith(".json")) {
return;
}
if (skipExisting && fs.existsSync(path.join(outputDir, file))) {
return;
}
if (specificFile && file !== specificFile) {
return;
}
const filePath = path.join(rootDir, file);
const content = JSON.parse(fs.readFileSync(filePath, "utf8"));
const elementor = JSON.parse(content.meta._elementor_data);
fs.writeFileSync(
path.join(outputDir, file),
JSON.stringify(elementor, null, 2)
);
});