Browse Source

Update work with Data files.

test-gpt-generated
Roman Axelrod 4 years ago
parent
commit
2a64defd56
  1. 41
      server.js

41
server.js

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

Loading…
Cancel
Save