Categories listing done
This commit is contained in:
parent
56e4623dd8
commit
59e7b3cb8d
|
@ -1,3 +1,4 @@
|
|||
/node_modules/
|
||||
/nbproject/
|
||||
/rethink.sh
|
||||
/rethink.sh
|
||||
/ressources/
|
31
app.js
31
app.js
|
@ -3,6 +3,8 @@ const express = require('express'),
|
|||
cors = require("cors"),
|
||||
app = express(),
|
||||
log = require("color-logs")(true, true, "Dryusdan.fr"),
|
||||
fs = require("fs"),
|
||||
path = require('path'),
|
||||
hbs = require('hbs');
|
||||
|
||||
log.info("Application started and now preparing");
|
||||
|
@ -14,17 +16,14 @@ var corsOptions = {
|
|||
"preflightContinue": false
|
||||
};
|
||||
|
||||
hbs.registerHelper('list', function(items, options) {
|
||||
//console.log(items);
|
||||
hbs.registerHelper('list', function(tabs, options) {
|
||||
|
||||
var out = '';
|
||||
var l=items.length;
|
||||
for(var i=0; i<l; i++) {
|
||||
//console.log(items[i]);
|
||||
out = out + "" + options.fn(items[i]) + "";
|
||||
|
||||
|
||||
for(var x in tabs){
|
||||
for(var i in tabs[x]){
|
||||
out = out + "" + options.fn(tabs[x][i]) + "";
|
||||
}
|
||||
}
|
||||
//console.log(out);
|
||||
return out;
|
||||
});
|
||||
|
||||
|
@ -45,9 +44,6 @@ class App {
|
|||
res.setHeader("Content-type", "text/html");
|
||||
res.render('template.hbs', tplData);
|
||||
});
|
||||
|
||||
|
||||
|
||||
});
|
||||
app.get("/:slug", function(req, res){
|
||||
res.setHeader("Content-type", "text/plain");
|
||||
|
@ -64,5 +60,14 @@ class App {
|
|||
|
||||
}
|
||||
|
||||
new App("/", config.appPort);
|
||||
|
||||
/** Preparing cache **/
|
||||
//async.waterfall([], );
|
||||
/*async.waterfall([
|
||||
function generateCache(callback){
|
||||
callback;
|
||||
}
|
||||
], function (err){
|
||||
|
||||
}
|
||||
);*/
|
|
@ -1,21 +1,19 @@
|
|||
const log = require('color-logs')(true, true, "Categories.class.js"),
|
||||
path = require('path'),
|
||||
fs = require("fs");
|
||||
|
||||
|
||||
class Categories {
|
||||
constructor(r, rtdbConn){
|
||||
this.rdbConn = rtdbConn;
|
||||
this.db = r;
|
||||
}
|
||||
|
||||
list(callback) {
|
||||
this.db.table('categories').run(this.rdbConn, function(err, cursor){
|
||||
if(err) throw err;
|
||||
cursor.toArray(function(err, result){
|
||||
if(err) throw err;
|
||||
callback(result);
|
||||
});
|
||||
});
|
||||
const srcpath = 'ressources';
|
||||
var listDir = fs.readdirSync(srcpath).filter(file => fs.lstatSync(path.join(srcpath, file)).isDirectory());
|
||||
var listCtg = {};
|
||||
for(var x = 0; x < listDir.length; x++){
|
||||
var params = JSON.parse(fs.readFileSync(srcpath+'/'+listDir[x]+'/params.json', 'utf8'));
|
||||
listCtg[x] = [{'title': params.title, 'slug': listDir[x]}]
|
||||
}
|
||||
callback(listCtg);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,8 +6,6 @@ const log = require('color-logs')(true, true, "Template.class.js"),
|
|||
var Categories = require('../classes/Categories.class.js');
|
||||
class Template {
|
||||
|
||||
constructor(){
|
||||
}
|
||||
|
||||
getNav(callback){
|
||||
var categories = new Categories();
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"name": "blog",
|
||||
"name": "nodezzarela",
|
||||
"version": "1.0.0",
|
||||
"lockfileVersion": 1,
|
||||
"dependencies": {
|
||||
|
|
Reference in New Issue