@lexho111/plainblog 0.3.4 → 0.3.6

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
@@ -125,7 +125,7 @@ export default class Blog {
125
125
  this.styles += style;
126
126
  }
127
127
 
128
- set assets(files) {
128
+ set stylesheetPath(files) {
129
129
  this.assetFiles = files;
130
130
  }
131
131
 
@@ -201,6 +201,10 @@ export default class Blog {
201
201
  const dbTitle = await this.#databaseModel.getBlogTitle();
202
202
  const dbArticles = await this.#databaseModel.findAll();
203
203
  //console.log(`articles: ${JSON.stringify(dbarticles)}`)
204
+ if(dbArticles.length == 0) {
205
+ dbArticles.push(new Article("Sample Entry #1", "Prow scuttle parrel provost Sail ho shrouds spirits boom mizzenmast yardarm. Pinnace holystone mizzenmast quarter crow's nest nipperkin grog yardarm hempen halter furl. Swab barque interloper chantey doubloon starboard grog black jack gangway rutters.", new Date()));
206
+ dbArticles.push(new Article("Sample Entry #2", "Deadlights jack lad schooner scallywag dance the hempen jig carouser broadside cable strike colors. Bring a spring upon her cable holystone blow the man down spanker Shiver me timbers to go on account lookout wherry doubloon chase. Belay yo-ho-ho keelhaul squiffy black spot yardarm spyglass sheet transom heave to.", new Date()));
207
+ }
204
208
  this.reloadScriptsStylesOnGET = false;
205
209
  if(this.reloadScriptsStylesOnGET) console.log("reload scripts and styles on GET-Request");
206
210
  let title = "";
@@ -478,10 +482,13 @@ export default class Blog {
478
482
  * @param {string[]} files - Array of file paths to process.
479
483
  */
480
484
  async processAssets(files) {
485
+ // Normalize input to array (handles string or array)
486
+ const fileList = Array.isArray(files) ? files : [files];
487
+
481
488
  const __filename = fileURLToPath(import.meta.url);
482
489
  const __dirname = path.dirname(__filename);
483
- const styleFiles = files.filter(
484
- (f) => (f.endsWith(".scss") || f.endsWith(".css")) && !f.endsWith(".min.css")
490
+ const styleFiles = fileList.filter(
491
+ (f) => typeof f === "string" && (f.endsWith(".scss") || f.endsWith(".css")) && !f.endsWith(".min.css")
485
492
  );
486
493
  //const scriptFiles = files.filter((f) => f.endsWith(".js") && !f.endsWith(".min.js"));
487
494
 
@@ -509,7 +516,7 @@ export default class Blog {
509
516
  this.#stylesHash = currentHash;
510
517
 
511
518
  // Compile styles using the standalone script
512
- this.compiledStyles = await compileStyles();
519
+ this.compiledStyles = await compileStyles(fileData);
513
520
 
514
521
  await fs.promises.writeFile(
515
522
  path.join(__dirname, "styles.min.css"),
package/README.md CHANGED
@@ -63,7 +63,7 @@ const blog = new Blog();
63
63
  blog.title = "My Blog";
64
64
  blog.style = "body { font-family: Arial, sans-serif; } h1 { color: #333; }";
65
65
  blog.password = "mypassword";
66
- blog.assets = ["my-assets/styles.scss","my-assets/scripts123.js"];
66
+ blog.stylesheetPath = ["my-assets/styles.scss"];
67
67
 
68
68
  blog.startServer(8080);
69
69
  ```
package/blog.db CHANGED
Binary file
package/blog.json ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "title": "",
3
+ "articles": [
4
+ {
5
+ "title": "hello",
6
+ "content": "hello world!"
7
+ }
8
+ ]
9
+ }
package/build-styles.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { promises as fs } from "fs";
2
2
  import path from "path";
3
+ import { pathToFileURL } from "url";
3
4
  import * as sass from "sass";
4
5
  import postcss from "postcss";
5
6
  import autoprefixer from "autoprefixer";
@@ -20,28 +21,47 @@ async function getFiles(dir) {
20
21
  return Array.prototype.concat(...files);
21
22
  }
22
23
 
23
- export async function compileStyles() {
24
+ export async function compileStyles(fileData) {
24
25
  try {
25
- const allFiles = await getFiles(srcDir);
26
+ let combinedCss = "";
26
27
 
27
- // Filter for .scss files and exclude partials (files starting with _)
28
- // Sort them to ensure consistent concatenation order
29
- const scssFiles = allFiles
30
- .filter((f) => f.endsWith(".scss") && !path.basename(f).startsWith("_"))
31
- .sort();
28
+ if (fileData) {
29
+ const scssFiles = fileData.filter(
30
+ (f) =>
31
+ f.path.endsWith(".scss") && !path.basename(f.path).startsWith("_")
32
+ );
32
33
 
33
- let combinedCss = "";
34
+ for (const file of scssFiles) {
35
+ try {
36
+ const result = sass.compileString(file.content.toString(), {
37
+ loadPaths: [srcDir],
38
+ style: "expanded",
39
+ url: pathToFileURL(file.path),
40
+ });
41
+ combinedCss += result.css + "\n";
42
+ } catch (err) {
43
+ console.error(
44
+ `Error compiling ${path.basename(file.path)}:`,
45
+ err.message
46
+ );
47
+ }
48
+ }
49
+ } else {
50
+ const allFiles = await getFiles(srcDir);
51
+ const scssFiles = allFiles
52
+ .filter((f) => f.endsWith(".scss") && !path.basename(f).startsWith("_"))
53
+ .sort();
34
54
 
35
- // 1. Compile Sass
36
- for (const file of scssFiles) {
37
- try {
38
- const result = sass.compile(file, {
39
- loadPaths: [srcDir],
40
- style: "expanded",
41
- });
42
- combinedCss += result.css + "\n";
43
- } catch (err) {
44
- console.error(`Error compiling ${path.basename(file)}:`, err.message);
55
+ for (const file of scssFiles) {
56
+ try {
57
+ const result = sass.compile(file, {
58
+ loadPaths: [srcDir],
59
+ style: "expanded",
60
+ });
61
+ combinedCss += result.css + "\n";
62
+ } catch (err) {
63
+ console.error(`Error compiling ${path.basename(file)}:`, err.message);
64
+ }
45
65
  }
46
66
  }
47
67
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lexho111/plainblog",
3
- "version": "0.3.4",
3
+ "version": "0.3.6",
4
4
  "description": "A tool for creating and serving a minimalist, single-page blog.",
5
5
  "main": "index.js",
6
6
  "type": "module",
package/styles.min.css CHANGED
@@ -1,2 +1,2 @@
1
- .grid{border:0 solid #000;display:grid;gap:.25rem;grid-template-columns:1fr}.grid article{border:0 solid #ccc;border-radius:4px;min-width:0;overflow-wrap:break-word;padding:.25rem}h1{color:#7f0000}nav a{color:#3b40c1;font-size:20px;text-decoration:underline}nav a:visited{color:#3b40c1;text-decoration-color:#3b40c1}
2
- /* source-hash: 91ab1d754238759404d2b8becfe52372f6f7b9c0f136b8b125c69faadeacd9d7 */
1
+ .grid{border:0 solid #000;display:grid;gap:.25rem;grid-template-columns:1fr}.grid article{border:0 solid #ccc;border-radius:4px;min-width:0;overflow-wrap:break-word;padding:.25rem}h1{color:blue}nav a{color:#3b40c1;font-size:20px;text-decoration:underline}nav a:visited{color:#3b40c1;text-decoration-color:#3b40c1}
2
+ /* source-hash: 2883123eb5327954a734dbf32eae2082e8448c15170daa28704ce7b8882036d5 */
Binary file
Binary file
Binary file
Binary file
@@ -1 +0,0 @@
1
- function test(){console.log("123")}
@@ -1,2 +0,0 @@
1
- .grid{border:0 solid #000;display:grid;gap:.25rem;grid-template-columns:1fr}.grid article{border:0 solid #ccc;border-radius:4px;min-width:0;overflow-wrap:break-word;padding:.25rem}.grid article h1{color:red}nav a:visited{color:#3b40c1;text-decoration-color:#3b40c1}body{background-color:#fdfdfd;font-family:Arial}nav a{color:#3b40c1;font-size:20px;text-decoration:underline}.datetime{color:#434343;font-style:italic}h2{margin:0 0 5px}p{margin-top:10px}span{margin:0}
2
- /*# sourceMappingURL=styles.min.css.map */
@@ -1 +0,0 @@
1
- {"version":3,"sources":["styles-compiled.css","styles.css"],"names":[],"mappings":"AAAA,MAIA,mBAAA,CAHA,YAAA,CAEA,UAAA,CADA,yBAGA,CACA,cAEA,mBAAA,CACA,iBAAA,CACA,WAAA,CACA,wBAAA,CAJA,cAKA,CACA,iBACA,SACA,CAOA,cACA,aAAA,CACA,6BACA,CCzBA,KACA,wBAAA,CACA,iBACA,CAEA,MAEA,aAAA,CACA,cAAA,CAFA,yBAGA,CAEA,UAEA,aAAA,CADA,iBAEA,CAEA,GAEA,cACA,CAEA,EACA,eACA,CAEA,KACA,QACA","file":"styles.min.css","sourcesContent":[".grid {\n display: grid;\n grid-template-columns: 1fr;\n gap: 0.25rem;\n border: 0px solid black;\n}\n.grid article {\n padding: 0.25rem;\n border: 0px solid #ccc;\n border-radius: 4px;\n min-width: 0; /* Allow grid items to shrink */\n overflow-wrap: break-word; /* Break long words */\n}\n.grid article h1 {\n color: red;\n}\n\nnav a {\n text-decoration: underline;\n color: rgb(59, 64, 193);\n font-size: 20px;\n}\nnav a:visited {\n color: rgb(59, 64, 193);\n text-decoration-color: rgb(59, 64, 193);\n}","body {\n background-color: rgb(253, 253, 253);\n font-family: Arial;\n}\n\nnav a {\n text-decoration: underline;\n color: rgb(59, 64, 193);\n font-size: 20px;\n}\n\n.datetime {\n font-style: italic;\n color: rgb(67, 67, 67);\n}\n\nh2 {\n margin: 0;\n margin-bottom: 5px;\n}\n\np {\n margin-top: 10px;\n}\n\nspan {\n margin: 0;\n}\n"]}