@lexho111/plainblog 0.5.17 → 0.5.18

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 CHANGED
@@ -74,6 +74,7 @@ export default class Blog {
74
74
  //#scriptsHash = "";
75
75
  #stylesheetPath = "";
76
76
  compilestyle = false;
77
+ #initPromise = null;
77
78
 
78
79
  setTitle(title) {
79
80
  this.#title = title;
@@ -94,12 +95,6 @@ export default class Blog {
94
95
 
95
96
  set title(t) {
96
97
  this.#title = t;
97
- if (!this.#databaseModel) {
98
- this.#databaseModel = new DatabaseModel(this.database);
99
- }
100
- console.log(`connected to database`);
101
- if (t != this.#title && t.length == 0)
102
- this.#databaseModel.updateBlogTitle(t);
103
98
  }
104
99
 
105
100
  get title() {
@@ -197,6 +192,8 @@ export default class Blog {
197
192
 
198
193
  /** initializes database */
199
194
  async init() {
195
+ if (this.#initPromise) return this.#initPromise;
196
+ this.#initPromise = (async () => {
200
197
  //this.loadStyles();
201
198
  //this.loadScripts();
202
199
  // if there is a stylesheet path provided, process it
@@ -296,6 +293,8 @@ export default class Blog {
296
293
  const responseData = { title: title, articles: dbArticles };
297
294
  this.#applyBlogData(responseData);
298
295
  }
296
+ })();
297
+ return this.#initPromise;
299
298
  }
300
299
 
301
300
  /** post a blog article */
@@ -341,7 +340,7 @@ export default class Blog {
341
340
 
342
341
  /** start a http server with default port 8080 */
343
342
  async startServer(port = 8080) {
344
- if (this.#databaseModel === undefined) await this.init(); // init blog if it didn't already happen
343
+ await this.init();
345
344
 
346
345
  const server = http.createServer(async (req, res) => {
347
346
  // API routes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lexho111/plainblog",
3
- "version": "0.5.17",
3
+ "version": "0.5.18",
4
4
  "description": "A tool for creating and serving a minimalist, single-page blog.",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -1 +0,0 @@
1
- body{font-family:Arial}.grid{border:0 solid #000;display:grid;grid-gap:.25rem;gap:.25rem;grid-template-columns:1fr}.grid article{border:0 solid #ccc;border-radius:4px;min-width:0;word-wrap:break-word;padding:.25rem}.grid article h2{color:#353535;margin-bottom:5px}.grid article .datetime{color:#757575;margin:0}.grid article p{margin-bottom:0;margin-top:10px}article a,article a:visited,h1{color:#696969}nav a{color:#3b40c1;font-size:20px;-webkit-text-decoration:underline;text-decoration:underline}nav a:visited{color:#3b40c1;text-decoration-color:#3b40c1}#wrapper{max-width:500px;width:100%}@media screen and (max-width:1000px){*{font-size:4vw}#wrapper{box-sizing:border-box;max-width:100%;padding:0 10px;width:100%}}