@lexho111/plainblog 0.0.1
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/Article.js +6 -0
- package/Blog.js +55 -0
- package/README.md +17 -0
- package/index.js +4 -0
- package/package.json +22 -0
package/Article.js
ADDED
package/Blog.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import http from "http";
|
|
2
|
+
|
|
3
|
+
export default class Blog {
|
|
4
|
+
constructor() {
|
|
5
|
+
this.title = "";
|
|
6
|
+
this.articles = [];
|
|
7
|
+
this.style = "body { font-family: Arial; }";
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
setTitle(title) {
|
|
11
|
+
this.title = title;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
addArticle(article) {
|
|
15
|
+
this.articles.push(article);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
setStyle(style) {
|
|
19
|
+
this.style = style;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
startServer(port = 8080) {
|
|
23
|
+
const server = http.createServer((req, res) => {
|
|
24
|
+
res.writeHead(200, { "Content-Type": "text/html" });
|
|
25
|
+
res.end(this.toHTML());
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
server.listen(port, () => {
|
|
29
|
+
console.log(`Server running at http://localhost:${port}/`);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
print() {
|
|
34
|
+
console.log(`# ${this.title}`);
|
|
35
|
+
for (const article of this.articles) {
|
|
36
|
+
console.log(`## ${article.title}`);
|
|
37
|
+
console.log(article.content);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
toHTML() {
|
|
42
|
+
let html = `<style>${this.style}</style>`;
|
|
43
|
+
html += `<h1>${this.title}</h1>`;
|
|
44
|
+
|
|
45
|
+
for (const article of this.articles) {
|
|
46
|
+
html += `
|
|
47
|
+
<article>
|
|
48
|
+
<h2>${article.title}</h2>
|
|
49
|
+
<p>${article.content}</p>
|
|
50
|
+
</article>`;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return html;
|
|
54
|
+
}
|
|
55
|
+
}
|
package/README.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
```
|
|
2
|
+
import { Blog, Article } from "blog1234";
|
|
3
|
+
|
|
4
|
+
const blog = new Blog();
|
|
5
|
+
blog.setTitle("My Blog");
|
|
6
|
+
blog.setStyle("body { font-family: Arial, sans-serif; } h1 { color: #333; }");
|
|
7
|
+
|
|
8
|
+
const article1 = new Article("My First Post", "Hello world!");
|
|
9
|
+
blog.addArticle(article1);
|
|
10
|
+
|
|
11
|
+
const article2 = new Article(
|
|
12
|
+
"Good Evening!",
|
|
13
|
+
"Good Evening, Ladies and Gentleman!"
|
|
14
|
+
);
|
|
15
|
+
blog.addArticle(article2);
|
|
16
|
+
blog.startServer(8080);
|
|
17
|
+
```
|
package/index.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lexho111/plainblog",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "A tool for creating and serving a minimalist, single-page blog.",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"files": [
|
|
8
|
+
"index.js",
|
|
9
|
+
"Blog.js",
|
|
10
|
+
"Article.js"
|
|
11
|
+
],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"blog",
|
|
17
|
+
"html",
|
|
18
|
+
"server"
|
|
19
|
+
],
|
|
20
|
+
"author": "lexho111",
|
|
21
|
+
"license": "ISC"
|
|
22
|
+
}
|