@lexho111/plainblog 0.2.0 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Blog.js +15 -50
- package/README.md +2 -2
- package/package.json +1 -1
- package/test/server.test.js +1 -1
package/Blog.js
CHANGED
|
@@ -250,9 +250,14 @@ export default class Blog {
|
|
|
250
250
|
loggedin = true;
|
|
251
251
|
}
|
|
252
252
|
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
253
|
+
try {
|
|
254
|
+
const html = this.toHTML(loggedin); // render this blog to HTML
|
|
255
|
+
res.writeHead(200, { "Content-Type": "text/html; charset=UTF-8" });
|
|
256
|
+
res.end(html);
|
|
257
|
+
} catch (err) {
|
|
258
|
+
res.writeHead(500, { "Content-Type": "text/plain" });
|
|
259
|
+
res.end("Internal Server Error");
|
|
260
|
+
}
|
|
256
261
|
} else {
|
|
257
262
|
// Error 404
|
|
258
263
|
res.writeHead(404, { "Content-Type": "application/json" });
|
|
@@ -373,37 +378,17 @@ export default class Blog {
|
|
|
373
378
|
}
|
|
374
379
|
|
|
375
380
|
/** print markdown to the console */
|
|
376
|
-
|
|
381
|
+
print() {
|
|
377
382
|
const data = {
|
|
378
383
|
title: this.title,
|
|
379
384
|
articles: this.articles,
|
|
380
385
|
};
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
return new Promise((resolve, reject) => {
|
|
384
|
-
let markdownResult = "";
|
|
385
|
-
pipeline(
|
|
386
|
-
Readable.from([data]),
|
|
387
|
-
new MapTransform((chunk) => formatMarkdown(chunk, this.scripts, this.styles)),
|
|
388
|
-
new Writable({
|
|
389
|
-
write(chunk, encoding, callback) {
|
|
390
|
-
markdownResult += chunk.toString();
|
|
391
|
-
callback();
|
|
392
|
-
},
|
|
393
|
-
}),
|
|
394
|
-
(err) => {
|
|
395
|
-
if (err) reject(err);
|
|
396
|
-
else {
|
|
397
|
-
console.log(markdownResult)
|
|
398
|
-
resolve(markdownResult);
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
);
|
|
402
|
-
});
|
|
386
|
+
const markdown = formatMarkdown(data);
|
|
387
|
+
return markdown;
|
|
403
388
|
}
|
|
404
389
|
|
|
405
390
|
/** render this blog content to valid html */
|
|
406
|
-
|
|
391
|
+
toHTML(loggedin) {
|
|
407
392
|
const data = {
|
|
408
393
|
title: this.title,
|
|
409
394
|
articles: this.articles,
|
|
@@ -413,28 +398,8 @@ export default class Blog {
|
|
|
413
398
|
|
|
414
399
|
if(loggedin) data.login = `<a href="/logout">logout</a>`;
|
|
415
400
|
else data.login = `<a href="/login">login</a>`;
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
pipeline(
|
|
420
|
-
Readable.from([data]),
|
|
421
|
-
new MapTransform((chunk) => formatHTML(chunk, this.scripts, this.styles)),
|
|
422
|
-
new MapTransform((chunk) => {
|
|
423
|
-
const html = chunk.toString();
|
|
424
|
-
if (validate(html)) return html;
|
|
425
|
-
throw new Error("Error. Invalid HTML!");
|
|
426
|
-
}),
|
|
427
|
-
new Writable({
|
|
428
|
-
write(chunk, encoding, callback) {
|
|
429
|
-
htmlResult += chunk.toString();
|
|
430
|
-
callback();
|
|
431
|
-
},
|
|
432
|
-
}),
|
|
433
|
-
(err) => {
|
|
434
|
-
if (err) reject(err);
|
|
435
|
-
else resolve(htmlResult);
|
|
436
|
-
}
|
|
437
|
-
);
|
|
438
|
-
});
|
|
401
|
+
const html = formatHTML(data, this.scripts, this.styles);
|
|
402
|
+
if (validate(html)) return html;
|
|
403
|
+
throw new Error("Error. Invalid HTML!");
|
|
439
404
|
}
|
|
440
405
|
}
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Plainblog
|
|
2
2
|
|
|
3
|
-
Plainblog is a simple blog generator to help you to set up and to maintain a minimalistic **single-page blog**. You can add new articles directly in the browser.
|
|
3
|
+
Plainblog is a simple blog generator to help you to set up and to maintain a minimalistic **single-page blog**. You can add new articles directly in the browser.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -20,7 +20,7 @@ blog.setStyle("body { font-family: Arial, sans-serif; } h1 { color: #333; }");
|
|
|
20
20
|
blog.startServer(8080);
|
|
21
21
|
```
|
|
22
22
|
|
|
23
|
-
Now you can
|
|
23
|
+
Now you can open your blog in your webbrowser on `http://localhost:8080`. Login via the login link in the navbar to begin with adding new articles, the password is '**_admin_**'.
|
|
24
24
|
|
|
25
25
|
## More Features
|
|
26
26
|
|
package/package.json
CHANGED
package/test/server.test.js
CHANGED
|
@@ -105,6 +105,6 @@ describe("server test", () => {
|
|
|
105
105
|
const responseData = await response.json();
|
|
106
106
|
expect(responseData).toEqual(newArticle);
|
|
107
107
|
|
|
108
|
-
expect(
|
|
108
|
+
expect(blog.toHTML()).toContain(newArticle.content); // does blog contain my new article?
|
|
109
109
|
});
|
|
110
110
|
});
|