Update work with Data files.
This commit is contained in:
@@ -39,35 +39,31 @@ app.engine('.hbs', hbs.engine);
|
||||
app.set('view engine', '.hbs');
|
||||
app.set('views', projectDir + 'layouts');
|
||||
|
||||
app.get('/', async (req, res) => {
|
||||
let dataFiles = await fs.readdir('./data');
|
||||
dataFiles = dataFiles
|
||||
.filter((fileName) => fileName.split('.').pop() === 'json')
|
||||
.map((fileName) => {
|
||||
const splitName = fileName.split('.');
|
||||
splitName.pop();
|
||||
const name = splitName.join('');
|
||||
return {
|
||||
name,
|
||||
active: (req.query.data) && req.query.data === name,
|
||||
};
|
||||
});
|
||||
const dataFiles = prepareListOfDataFiles(await fs.readdir('./data'));
|
||||
|
||||
app.get('/', async (req, res) => {
|
||||
let jsonFileName = (req.query.data) ? req.query.data : 'default';
|
||||
if (!jsonFileName || !await fsExtra.exists(`./data/${jsonFileName}.json`)) {
|
||||
jsonFileName = 'default';
|
||||
}
|
||||
|
||||
const jsonFileName = (req.query.data) ? req.query.data : 'default';
|
||||
const data = await fsExtra.readJson(`./data/${jsonFileName}.json`);
|
||||
|
||||
Object.assign(data, {
|
||||
config: {
|
||||
projectDir,
|
||||
dataFiles,
|
||||
dataFiles: dataFiles.map((name) => {
|
||||
return {
|
||||
name,
|
||||
active: jsonFileName === name,
|
||||
};
|
||||
}),
|
||||
cssUrl: config.get('cssUrl')
|
||||
}
|
||||
});
|
||||
|
||||
data.helpers = {
|
||||
include_partial(path) {
|
||||
return projectDir + path;
|
||||
}
|
||||
include_partial: (path) => projectDir + path,
|
||||
}
|
||||
|
||||
res.render('page-container', data);
|
||||
@@ -145,6 +141,17 @@ function buildStyleFiles() {
|
||||
.pipe(gulp.dest('src/'))
|
||||
}
|
||||
|
||||
function prepareListOfDataFiles(dataFiles) {
|
||||
return dataFiles
|
||||
.filter((fileName) => fileName.split('.').pop() === 'json')
|
||||
.map((fileName) => {
|
||||
const splitName = fileName.split('.');
|
||||
splitName.pop();
|
||||
return splitName.join('');
|
||||
})
|
||||
.sort();
|
||||
}
|
||||
|
||||
// TODO:
|
||||
//
|
||||
// [v] Add Gulp for CSS/JS Styling
|
||||
|
||||
Reference in New Issue
Block a user