mirror of
https://github.com/badlogic/heissepreise.git
synced 2024-06-27 19:05:53 +02:00
Fix pages generation.
This commit is contained in:
parent
e714d720b0
commit
c95451c5d8
36
pages.js
36
pages.js
|
@ -1,19 +1,31 @@
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
|
const path = require("path");
|
||||||
const analysis = require("./analysis.js");
|
const analysis = require("./analysis.js");
|
||||||
const template = require("./template.js");
|
const template = require("./template.js");
|
||||||
|
const outputDir = path.resolve("docs");
|
||||||
|
const dataDir = path.join(outputDir, "data");
|
||||||
|
|
||||||
if (process.argv.length < 3) {
|
function deleteFiles(folderPath) {
|
||||||
console.log("Usage: node pages.js <output-dir>");
|
const files = fs.readdirSync(folderPath);
|
||||||
console.log();
|
|
||||||
console.log("e.g. node pages.js docs/");
|
files.forEach((file) => {
|
||||||
console.log();
|
const filePath = path.join(folderPath, file);
|
||||||
process.exit(1);
|
|
||||||
|
if (filePath !== dataDir) {
|
||||||
|
if (fs.statSync(filePath).isFile()) {
|
||||||
|
fs.unlinkSync(filePath);
|
||||||
|
} else {
|
||||||
|
deleteFiles(filePath);
|
||||||
|
fs.rmdirSync(filePath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
(async function () {
|
(async function () {
|
||||||
try {
|
try {
|
||||||
const outputDir = process.argv[2];
|
if (!fs.existsSync(outputDir)) fs.mkdirSync(outputDir);
|
||||||
const dataDir = outputDir + "/data";
|
deleteFiles(outputDir);
|
||||||
template.generateSite("site", outputDir, false);
|
template.generateSite("site", outputDir, false);
|
||||||
|
|
||||||
analysis.migrateCompression(dataDir, ".json", ".json.br");
|
analysis.migrateCompression(dataDir, ".json", ".json.br");
|
||||||
|
@ -23,9 +35,15 @@ if (process.argv.length < 3) {
|
||||||
const items = analysis.readJSON(`${dataDir}/latest-canonical.json.${analysis.FILE_COMPRESSOR}`);
|
const items = analysis.readJSON(`${dataDir}/latest-canonical.json.${analysis.FILE_COMPRESSOR}`);
|
||||||
for (const store of analysis.STORE_KEYS) {
|
for (const store of analysis.STORE_KEYS) {
|
||||||
const storeItems = items.filter((item) => item.store === store);
|
const storeItems = items.filter((item) => item.store === store);
|
||||||
analysis.writeJSON(`${dataDir}/latest-canonical.${store}.compressed.json`, false, storeItems, 0, true);
|
analysis.writeJSON(`${dataDir}/latest-canonical.${store}.compressed.json`, storeItems, false, 0, true);
|
||||||
}
|
}
|
||||||
|
fs.readdirSync(dataDir).forEach((file) => {
|
||||||
|
const filePath = path.join(dataDir, file);
|
||||||
|
if (fs.statSync(filePath).isFile() && !file.startsWith("latest-canonical")) fs.unlinkSync(filePath);
|
||||||
|
});
|
||||||
|
analysis.migrateCompression(dataDir, ".json.br", ".json");
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|
4
pages.sh
4
pages.sh
|
@ -4,11 +4,11 @@ if [[ $repository_name == *.github.io ]]; then
|
||||||
echo "Name ends with github.io"
|
echo "Name ends with github.io"
|
||||||
else
|
else
|
||||||
echo "Name does not end with github.io, not generating pages"
|
echo "Name does not end with github.io, not generating pages"
|
||||||
# exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
npm install
|
npm install
|
||||||
node pages.js docs
|
node pages.js
|
||||||
|
|
||||||
pushd docs
|
pushd docs
|
||||||
git add *
|
git add *
|
||||||
|
|
Loading…
Reference in New Issue
Block a user