forked from devfreebooks/devfreebooks.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
categories.js
26 lines (21 loc) · 1.03 KB
/
categories.js
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
const fs = require('fs-extra');
const path = require('path');
const PUBLIC_DIR = path.join(__dirname, 'public');
const CATEGORIES_DIR = path.join(PUBLIC_DIR, '_categories');
const output = { index: { categories: [] } };
console.log('Generating categories pages');
fs.readdirSync(CATEGORIES_DIR).forEach((file) => {
const categoryName = file.replace('.json', '');
const categoryJSONPath = path.join(CATEGORIES_DIR, file);
const newCategoryPath = path.join(PUBLIC_DIR, categoryName);
const newCategoryJSONPath = path.join(newCategoryPath, '_data.json');
const newCategoryJADEPath = path.join(newCategoryPath, 'index.jade');
fs.emptyDirSync(newCategoryPath);
fs.copySync(categoryJSONPath, newCategoryJSONPath);
fs.writeFileSync(newCategoryJADEPath, '!= partial("../_shared/thumb_books")', 'utf8');
output.index.categories.push(categoryName);
});
const categoriesPath = path.join(PUBLIC_DIR, '_data.json');
fs.removeSync(categoriesPath);
fs.writeJsonSync(categoriesPath, output);
console.log('Categories generated successfully!');