Compare commits

...

2 Commits

Author SHA1 Message Date
Klemek de26feb05c Merge pull request #16 from Klemek/dev
v1.2.5
2019-07-01 23:17:56 +02:00
Klemek 8bb455b576 Fixed draft rendering bug 2019-07-01 23:15:13 +02:00
5 changed files with 25 additions and 12 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "gitblog.md",
"version": "1.2.4",
"version": "1.2.5",
"description": "A static blog using Markdown pulled from your git repository.",
"main": "src/server.js",
"dependencies": {
+3 -2
View File
@@ -69,8 +69,9 @@ module.exports = (config) => {
Object.keys(articles).forEach((key) => delete articles[key]);
Object.keys(dict).forEach((key) => articles[key] = dict[key]);
const nb = Object.keys(articles).length;
const dnb = Object.values(articles).filter(a => a.draft).length;
if (nb > 0)
console.log(cons.ok, `loaded ${nb} article${nb > 1 ? 's' : ''}`);
console.log(cons.ok, `loaded ${nb} article${nb > 1 ? 's' : ''} (${dnb} drafted)`);
else
console.log(cons.warn, `no articles loaded, check your configuration`);
@@ -220,7 +221,7 @@ module.exports = (config) => {
if (!article)
showError(req, res, 404);
else {
renderer.render(path.join(article.realPath, config['article']['index']), (err, html) => {
renderer.render(article.realPath, (err, html) => {
if (err) {
console.log(cons.error, `failed to render article ${req.path} : ${err}`);
return showError(req, res, 500);
+2 -2
View File
@@ -82,7 +82,7 @@ module.exports = (config) => {
const article = {
path: joinUrl(p[0], p[1], p[2]),
draft: p[3] === config['article']['draft'],
realPath: path.join(config['data_dir'], p[0], p[1], p[2]),
realPath: path.join(config['data_dir'], p[0], p[1], p[2], p[3]),
year: parseInt(p[0]),
month: parseInt(p[1]),
day: parseInt(p[2])
@@ -90,7 +90,7 @@ module.exports = (config) => {
article.date = new Date(article.year, article.month, article.day);
article.date.setUTCHours(0);
remaining++;
readIndexFile(path.join(article.realPath, p[3]), config['article']['thumbnail_tag'], (err, info) => {
readIndexFile(article.realPath, config['article']['thumbnail_tag'], (err, info) => {
if (err)
return cb(err);
article.title = info.title || config['article']['default_title'];
+15 -3
View File
@@ -322,12 +322,11 @@ describe('Test articles rendering', () => {
});
});
test('500 no index', (done, fail) => {
test('500 fail to render', (done, fail) => {
utils.createEmptyDirs([path.join(dataDir, '2019', '05', '05'),]);
fs.writeFileSync(path.join(dataDir, '2019', '05', '05', 'index.md'), '# Hello');
fs.writeFileSync(path.join(dataDir, testTemplate), '<%- article.content %><%- `<a href="${article.url}">reload</a>` %>');
fs.writeFileSync(path.join(dataDir, testTemplate), '<%- articl.content %><%- `<a href="${article.url}">reload</a>` %>');
app.reload(() => {
config['article']['index'] = 'invalid.md';
request(app).get('/2019/05/05/hello/').then((response) => {
expect(response.statusCode).toBe(500);
done();
@@ -359,6 +358,19 @@ describe('Test articles rendering', () => {
}, fail);
});
test('200 rendered draft', (done, fail) => {
utils.createEmptyDirs([path.join(dataDir, '2019', '05', '05'),]);
fs.writeFileSync(path.join(dataDir, '2019', '05', '05', 'draft.md'), '# Hello');
fs.writeFileSync(path.join(dataDir, testTemplate), '<%- article.content %><%- `<a href="${article.url}">reload</a>` %>');
app.reload(() => {
request(app).get('/2019/05/05/hello/').then((response) => {
expect(response.statusCode).toBe(200);
expect(response.text).toBe('<h1 id="hello">Hello</h1><a href="/2019/05/05/hello/">reload</a>');
done();
});
}, fail);
});
test('200 other url', (done, fail) => {
utils.createEmptyDirs([path.join(dataDir, '2019', '05', '05'),]);
utils.createEmptyFiles([
+4 -4
View File
@@ -236,7 +236,7 @@ describe('Test article fetching', () => {
expect(Object.keys(dict).length).toBe(1);
expect(dict[joinUrl('2019', '05', '05')]).toEqual({
path: joinUrl('2019', '05', '05'),
realPath: dir,
realPath: file,
year: 2019,
month: 5,
draft: false,
@@ -267,7 +267,7 @@ describe('Test article fetching', () => {
expect(Object.keys(dict).length).toBe(1);
expect(dict[joinUrl('2019', '05', '05')]).toEqual({
path: joinUrl('2019', '05', '05'),
realPath: dir,
realPath: file,
year: 2019,
month: 5,
day: 5,
@@ -298,7 +298,7 @@ describe('Test article fetching', () => {
expect(Object.keys(dict).length).toBe(1);
expect(dict[joinUrl('2019', '05', '05')]).toEqual({
path: joinUrl('2019', '05', '05'),
realPath: dir,
realPath: file,
year: 2019,
month: 5,
day: 5,
@@ -326,7 +326,7 @@ describe('Test article fetching', () => {
expect(Object.keys(dict).length).toBe(1);
expect(dict[joinUrl('2019', '05', '05')]).toEqual({
path: joinUrl('2019', '05', '05'),
realPath: dir,
realPath: file,
year: 2019,
month: 5,
draft: false,