Merge branch 'feature/#9' into develop
This commit is contained in:
commit
9bcd24af23
|
@ -11,13 +11,14 @@ var id,
|
|||
slug;
|
||||
|
||||
class Article {
|
||||
constructor(id, title, author, date, img, slug){
|
||||
constructor(id, title, author, date, img, slug, content = null){
|
||||
this.setId(id);
|
||||
this.setTitle(title);
|
||||
this.setAuthor(author);
|
||||
this.setDate(date);
|
||||
this.setImg(img);
|
||||
this.setSlug(slug);
|
||||
(content !== null)?this.setContent(content):'';
|
||||
}
|
||||
|
||||
setId(id){
|
||||
|
@ -33,7 +34,7 @@ class Article {
|
|||
}
|
||||
|
||||
setContent(content){
|
||||
this.content = content;
|
||||
this.content = markdown.toHTML(content);
|
||||
}
|
||||
|
||||
setImg(img){
|
||||
|
@ -76,10 +77,6 @@ class Article {
|
|||
return this.slug;
|
||||
}
|
||||
|
||||
getCompiledContent(){
|
||||
return markdown.toHTML(this.getContent());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = Article;
|
||||
|
|
|
@ -12,7 +12,6 @@ hbs.registerHelper('listArticle', function(tabs, options) {
|
|||
var out = '';
|
||||
|
||||
for(var x in options['data']['root']){
|
||||
//log.debug(options.fn(options['data']['root'][x]));
|
||||
out = out + "" + options.fn(options['data']['root'][x]) + "";
|
||||
if(i == 3){
|
||||
i= 1;
|
||||
|
@ -34,8 +33,22 @@ hbs.registerHelper('listNav', function(tabs, options) {
|
|||
return out;
|
||||
});
|
||||
|
||||
hbs.registerHelper('article', function(tabs, options) {
|
||||
var out = '';
|
||||
log.debug(options['data']['root']);
|
||||
for(var x in options['data']['root']){
|
||||
out = out + "" + options.fn(options['data']['root'][x]) + "";
|
||||
|
||||
}
|
||||
return out;
|
||||
});
|
||||
|
||||
class Categories {
|
||||
|
||||
/**
|
||||
*
|
||||
* @returns {<Promise>} html : the html code of navbar
|
||||
*/
|
||||
getNav(){
|
||||
var db = new dbConnector();
|
||||
return db.get({
|
||||
|
@ -96,6 +109,11 @@ class Categories {
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {<Categorie>} categorie : object categorie
|
||||
* @returns {<Promise> listArticleToHTML} a list of article in HTML format
|
||||
*/
|
||||
getListArticles(categorie){
|
||||
var db = new dbConnector();
|
||||
return db.get({
|
||||
|
@ -117,16 +135,20 @@ class Categories {
|
|||
return new Promise((resolve) => {
|
||||
var data = JSON.parse(result);
|
||||
for(var i in data){
|
||||
categorie.setArticle(new Article(data[i].id,data[i].title, data[i].author, data[i].date, data[i].img, data[i].slug))
|
||||
categorie.setArticle(new Article(data[i].id,data[i].title, data[i].author, data[i].date, data[i].img, data[i].slug));
|
||||
}
|
||||
log.debug(categorie);
|
||||
resolve(this.listArticlesToHTM(categorie));
|
||||
resolve(this.listArticlesToHTML(categorie));
|
||||
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
listArticlesToHTM(categorie){
|
||||
/**
|
||||
*
|
||||
* @param {<Categorie>} categorie : object categorie
|
||||
* @returns {<Promise>} a list of article in HTML format
|
||||
*/
|
||||
listArticlesToHTML(categorie){
|
||||
return new Promise((resolve, reject) => {
|
||||
fs.readFile('./views/articles/list.hbs', 'utf-8', (error, source) => {
|
||||
hbs.registerHelper('articles', (articles) =>{
|
||||
|
@ -141,92 +163,47 @@ class Categories {
|
|||
|
||||
/**
|
||||
*
|
||||
* @returns {Promise} the list of article
|
||||
* @param {<Categorie>} categorie : object categorie
|
||||
* @param {string} uri the uri of article
|
||||
* @returns {<Promise>} a compiled article in HTML
|
||||
*/
|
||||
getHome(){
|
||||
return new Promise((resolve, reject) => {
|
||||
fs.readFile('./views/articles/list.hbs', 'utf-8', (error, source) => {
|
||||
var data = require('../ressources/lastArticles.json');
|
||||
hbs.registerHelper('articles', (articles) =>{
|
||||
return articles;
|
||||
});
|
||||
var template = hbs.compile(source);
|
||||
var html = template(data);
|
||||
resolve(html);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
getDisclaimer(){
|
||||
return new Promise((resolve, reject) => {
|
||||
fs.readFile('./views/articles/disclaimer.hbs', 'utf-8', (error, source) => {
|
||||
var data = require('../ressources/disclaimer.json');
|
||||
hbs.registerHelper('articles', (articles) =>{
|
||||
return articles;
|
||||
});
|
||||
var template = hbs.compile(source);
|
||||
var html = template(data);
|
||||
resolve(html);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {type} slug : url of categorie
|
||||
* @returns {Promise} the list of article in this categorie
|
||||
*/
|
||||
/*getListArticles(slug){
|
||||
return new Promise((resolve, reject) => {
|
||||
fs.readFile('./views/articles/list.hbs', 'utf-8', (error, source) => {
|
||||
var pathOfArticles = "./ressources/"+slug+"";
|
||||
var dataObj = {};
|
||||
fs.readdir(pathOfArticles, (err, files)=> {
|
||||
if(err){
|
||||
resolve(new Error("File not exist"));
|
||||
}
|
||||
else{
|
||||
var i = 0;
|
||||
files.forEach((file) => {
|
||||
if(file != "params.json"){
|
||||
if(path.extname(file) == ".json"){
|
||||
dataObj[i] = require('.'+pathOfArticles+"/"+file);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
var objectSize = Object.keys(dataObj).length;
|
||||
var data = "{";
|
||||
for(var x in dataObj){
|
||||
if(x < objectSize-1){
|
||||
data += "\""+x+"\""+":"+JSON.stringify(dataObj[x])+',';
|
||||
}
|
||||
else{
|
||||
data += "\""+x+"\""+":"+JSON.stringify(dataObj[x])+'';
|
||||
}
|
||||
}
|
||||
data += "}";
|
||||
data = JSON.parse(data);
|
||||
|
||||
hbs.registerHelper('articles', (articles) =>{
|
||||
return articles;
|
||||
});
|
||||
|
||||
var template = hbs.compile(source);
|
||||
var html = template(data);
|
||||
resolve(html);
|
||||
getArticle(categorie, uri){
|
||||
var db = new dbConnector();
|
||||
return db.get({
|
||||
"select" : {
|
||||
"articles" : [
|
||||
"id",
|
||||
"title",
|
||||
"slug",
|
||||
"author",
|
||||
"date",
|
||||
"img",
|
||||
"content"
|
||||
]
|
||||
},
|
||||
"condition" : {
|
||||
"categorie_id" : categorie.getId(),
|
||||
"slug" : uri
|
||||
},
|
||||
"limit" : ""
|
||||
}).then((result) => {
|
||||
return new Promise((resolve) => {
|
||||
var data = JSON.parse(result);
|
||||
categorie.setArticle(new Article(data[0].id,data[0].title, data[0].author, data[0].date, data[0].img, data[0].slug, data[0].content));
|
||||
fs.readFile('./views/articles/article.hbs', 'utf-8', (error, source) => {
|
||||
if(error){
|
||||
log.error(error);
|
||||
}
|
||||
hbs.registerHelper('displayArticle', (article) =>{
|
||||
return article;
|
||||
});
|
||||
var template = hbs.compile(source);
|
||||
var html = template(categorie.getArticles());
|
||||
resolve(html);
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Categories;
|
|
@ -33,30 +33,6 @@ router.get("/", function(req, res){
|
|||
console.log(err);
|
||||
throw err;
|
||||
});
|
||||
/*Promise.all([
|
||||
template.getNav(),
|
||||
categories.getHome(),
|
||||
categories.getDisclaimer()
|
||||
]).then(data => {
|
||||
var nav = data[0];
|
||||
var content = data[1];
|
||||
var disclaimer = data[2];
|
||||
res.setHeader("Content-type", "text/html");
|
||||
var tplData = {
|
||||
"blogName": config.blogName,
|
||||
"title": config.homeTitle,
|
||||
"nav": nav,
|
||||
"content": content,
|
||||
"disclaimer": disclaimer
|
||||
};
|
||||
res.render('template.hbs', tplData);
|
||||
}).catch(err => {
|
||||
res.setHeader("Content-type", "text/plain");
|
||||
|
||||
resp.send(res.end("erreur"));
|
||||
});*/
|
||||
|
||||
|
||||
});
|
||||
|
||||
router.get("/:uri/", function(req, res){
|
||||
|
@ -79,40 +55,38 @@ router.get("/:uri/", function(req, res){
|
|||
};
|
||||
res.render('template.hbs', tplData);
|
||||
})
|
||||
/*var content = data[1];
|
||||
var dataCategories = data[2];*/
|
||||
|
||||
}).catch(err => {
|
||||
res.setHeader("Content-type", "text/plain");
|
||||
res.end("erreur");
|
||||
});
|
||||
});
|
||||
|
||||
/*router.get("/:categories/:slug", function(req, res){
|
||||
router.get("/:categories/:slug", function(req, res){
|
||||
var categories = new Categories();
|
||||
var articles = new Articles();
|
||||
Promise.all([
|
||||
template.getNav(),
|
||||
categories.getCategorie(req.params.categories),
|
||||
articles.getArticle(req.params.categories, req.params.slug)
|
||||
categories.getNav(),
|
||||
categories.getCategorie(req.params.categories)
|
||||
]).then(data => {
|
||||
var nav = data[0];
|
||||
var dataCategories = data[1];
|
||||
var content = data[2];
|
||||
res.setHeader("Content-type", "text/html");
|
||||
var tplData = {
|
||||
"blogName": config.blogName,
|
||||
"title": articles.title+" - "+dataCategories.title+" - "+ config.blogName,
|
||||
"nav": nav,
|
||||
"content": content,
|
||||
"disclaimer": ''
|
||||
};
|
||||
res.render('template.hbs', tplData);
|
||||
var categorie = data[1];
|
||||
categories.getArticle(categorie, req.params.slug).then((result) => {
|
||||
res.setHeader("Content-type", "text/html");
|
||||
var tplData = {
|
||||
"blogName": config.siteTitle,
|
||||
"title": categorie.getTitle() + " - "+config.siteHomeTitle,
|
||||
"nav": nav,
|
||||
"content": result,
|
||||
"disclaimer": ''
|
||||
};
|
||||
res.render('template.hbs', tplData);
|
||||
})
|
||||
}).catch(err => {
|
||||
log.debug(err);
|
||||
res.setHeader("Content-type", "text/plain");
|
||||
res.end("erreur");
|
||||
});
|
||||
});*/
|
||||
});
|
||||
router.use(express.static("./public"));
|
||||
|
||||
module.exports = router;
|
|
@ -1,18 +1,20 @@
|
|||
<main>
|
||||
<section>
|
||||
<nav>
|
||||
<button class="prev"><!--<img src="/assets/img/prev.png">Précédent--></button>
|
||||
<img class="blackAsset separator" src="/assets/img/separator.png">
|
||||
<button class="next"><!--Suivant<img src="/assets/img/next.png">--></button>
|
||||
</nav>
|
||||
<article>
|
||||
<div class="articleTitle">
|
||||
<h1>{{title}}</h1>
|
||||
<p class="author">Par {{author}}</p>
|
||||
</div>
|
||||
<div class="content">
|
||||
{{{content}}}
|
||||
</div>
|
||||
</article>
|
||||
</section>
|
||||
</main>
|
||||
{{#article data}}
|
||||
<main>
|
||||
<section>
|
||||
<nav>
|
||||
<button class="prev"><!--<img src="/assets/img/prev.png">Précédent--></button>
|
||||
<img class="blackAsset separator" src="/assets/img/separator.png">
|
||||
<button class="next"><!--Suivant<img src="/assets/img/next.png">--></button>
|
||||
</nav>
|
||||
<article>
|
||||
<div class="articleTitle">
|
||||
<h1>{{title}}</h1>
|
||||
<p class="author">Par {{author}}</p>
|
||||
</div>
|
||||
<div class="content">
|
||||
{{{content}}}
|
||||
</div>
|
||||
</article>
|
||||
</section>
|
||||
</main>
|
||||
{{/article}}
|
Reference in New Issue