some correction

This commit is contained in:
Dryusdan 2017-07-03 16:59:35 +02:00
parent 584a4d90d8
commit 2b23778dfd
8 changed files with 412 additions and 345 deletions

7
app.js
View file

@ -45,7 +45,7 @@ class App {
res.setHeader("Content-type", "text/html");
var tplData = {
"blogName": config.blogName,
"title": 'Accueil',
"title": config.homeTitle,
"nav": nav,
"content": content
};
@ -71,7 +71,7 @@ class App {
res.setHeader("Content-type", "text/html");
var tplData = {
"blogName": config.blogName,
"title": dataCategories.title,
"title": dataCategories.title+" - "+ config.blogName,
"nav": nav,
"content": content
};
@ -96,14 +96,13 @@ class App {
res.setHeader("Content-type", "text/html");
var tplData = {
"blogName": config.blogName,
"title": dataCategories.title,
"title": articles.title+" - "+dataCategories.title+" - "+ config.blogName,
"nav": nav,
"content": content
};
res.render('template.hbs', tplData);
}).catch(err => {
res.setHeader("Content-type", "text/plain");
console.log(err);
res.end("erreur");
});
});

View file

@ -28,12 +28,12 @@ class Articles {
fs.readFile(contentPath, 'utf-8', (error, content) => {
var content = markdown.toHTML(content);
const articleParams = require("."+paramPath);
this.title = articleParams.title;
var data = {
'title':articleParams.title,
'author': articleParams.author,
'content': content
};
console.log(data);
hbs.registerHelper('articles', (articles) =>{
return articles;
});

View file

@ -51,6 +51,7 @@ class Categories {
hbs.registerHelper('articles', (articles) =>{
return articles;
});
//console.log(data);
var template = hbs.compile(source);
var html = template(data);
resolve(html);
@ -66,17 +67,74 @@ class Categories {
getListArticles(slug){
return new Promise((resolve, reject) => {
fs.readFile('./views/articles/list.hbs', 'utf-8', (error, source) => {
const data = require('../ressources/lastArticles.json');
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);
// console.log(data);
//console.log(data[0]['title']);
hbs.registerHelper('articles', (articles) =>{
return articles;
});
var template = hbs.compile(source);
var html = template(data);
var html = html + template(data);
resolve(html);
}
});
//const data = require('../ressources/lastArticles.json');
// hbs.registerHelper('articles', (articles) =>{
// return articles;
// });
});
});
}
/**
var fs = require('fs');
fs.readdir('/', function (err, files) { // '/' denotes the root folder
if (err) throw err;
files.forEach( function (file) {
fs.lstat('/'+file, function(err, stats) {
if (!err && stats.isDirectory()) { //conditing for identifying folders
$('ul#foldertree').append('<li class="folder">'+file+'</li>');
}
else{
$('ul#foldertree').append('<li class="file">'+file+'</li>');
}
});
});
});
*/
}

View file

@ -29,7 +29,6 @@ class Template {
});
var template = hbs.compile(source);
var html = template(articles);
//console.log(html);
resolve(html);
});
});

View file

@ -1,4 +1,5 @@
{
"appPort": "8888",
"blogName": "Dryusdan"
"blogName": "Dryusdan",
"homeTitle": "Dryusdan.fr, blog d'un passionné d'informatique"
}

View file

@ -0,0 +1,10 @@
<main class="transparent">
<section>
<div class="flexgrid">
<div class="row">
{{{lists}}}
</div>
</div>
</section>
</main>

View file

@ -2,7 +2,7 @@
<html lang="fr">
<head>
<meta charset="UTF-8">
<title>{{title}} - {{blogName}}</title>
<title>{{title}}</title>
<link rel="stylesheet" href="/assets/css/global.css">
</head>
<body>