@lexho111/plainblog 0.4.0 → 0.4.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 +3 -3
- package/build-styles.js +19 -39
- package/lexho111-plainblog-0.4.1.tgz +0 -0
- package/package.json +1 -1
- package/scripts.min.js +1 -2
- package/src/styles.css +48 -0
- package/styles.min.css +1 -2
- /package/{loader.js → src/loader.js} +0 -0
package/Blog.js
CHANGED
|
@@ -13,7 +13,7 @@ import path from "path";
|
|
|
13
13
|
import { fileURLToPath } from "url";
|
|
14
14
|
import { exec } from "child_process";
|
|
15
15
|
import { promisify } from "util";
|
|
16
|
-
import { compileStyles } from "./build-styles.js";
|
|
16
|
+
import { compileStyles, mergeStyles } from "./build-styles.js";
|
|
17
17
|
|
|
18
18
|
const execPromise = promisify(exec);
|
|
19
19
|
|
|
@@ -91,7 +91,7 @@ export default class Blog {
|
|
|
91
91
|
const __filename = fileURLToPath(import.meta.url);
|
|
92
92
|
const __dirname = path.dirname(__filename);
|
|
93
93
|
try {
|
|
94
|
-
this.scripts = fs.readFileSync(path.join(__dirname, "
|
|
94
|
+
this.scripts = fs.readFileSync(path.join(__dirname, "scripts.min.js"), "utf-8");
|
|
95
95
|
//console.log(this.scripts)
|
|
96
96
|
} catch (err) {
|
|
97
97
|
console.error(err);
|
|
@@ -536,7 +536,7 @@ export default class Blog {
|
|
|
536
536
|
|
|
537
537
|
this.loadScripts();
|
|
538
538
|
|
|
539
|
-
const finalStyles = this.styles
|
|
539
|
+
const finalStyles = await mergeStyles(this.styles, this.compiledStyles);
|
|
540
540
|
const html = formatHTML(data, this.scripts, finalStyles);
|
|
541
541
|
if (validate(html)) return html;
|
|
542
542
|
throw new Error("Error. Invalid HTML!");
|
package/build-styles.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { promises as fs } from "fs";
|
|
2
1
|
import path from "path";
|
|
3
2
|
import { pathToFileURL } from "url";
|
|
4
3
|
import * as sass from "sass";
|
|
@@ -6,26 +5,7 @@ import postcss from "postcss";
|
|
|
6
5
|
import autoprefixer from "autoprefixer";
|
|
7
6
|
import cssnano from "cssnano";
|
|
8
7
|
|
|
9
|
-
//
|
|
10
|
-
const srcDir = path.join("gulp_frontend", "src");
|
|
11
|
-
|
|
12
|
-
// Helper to find files recursively
|
|
13
|
-
async function getFiles(dir) {
|
|
14
|
-
const dirents = await fs.readdir(dir, { withFileTypes: true });
|
|
15
|
-
const files = await Promise.all(
|
|
16
|
-
dirents.map((dirent) => {
|
|
17
|
-
const res = path.resolve(dir, dirent.name);
|
|
18
|
-
return dirent.isDirectory() ? getFiles(res) : res;
|
|
19
|
-
})
|
|
20
|
-
);
|
|
21
|
-
return Array.prototype.concat(...files);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* compile .css and .scss files into one css-code
|
|
26
|
-
* @param {*} fileData a single file or an array of files
|
|
27
|
-
* @returns
|
|
28
|
-
*/
|
|
8
|
+
// array of files or a single file
|
|
29
9
|
export async function compileStyles(fileData) {
|
|
30
10
|
try {
|
|
31
11
|
let combinedCss = "";
|
|
@@ -39,7 +19,6 @@ export async function compileStyles(fileData) {
|
|
|
39
19
|
for (const file of scssFiles) {
|
|
40
20
|
try {
|
|
41
21
|
const result = sass.compileString(file.content.toString(), {
|
|
42
|
-
loadPaths: [srcDir],
|
|
43
22
|
style: "expanded",
|
|
44
23
|
url: pathToFileURL(file.path),
|
|
45
24
|
});
|
|
@@ -56,23 +35,6 @@ export async function compileStyles(fileData) {
|
|
|
56
35
|
for (const file of cssFiles) {
|
|
57
36
|
combinedCss += file.content + "\n";
|
|
58
37
|
}
|
|
59
|
-
} else {
|
|
60
|
-
const allFiles = await getFiles(srcDir);
|
|
61
|
-
const scssFiles = allFiles
|
|
62
|
-
.filter((f) => f.endsWith(".scss") && !path.basename(f).startsWith("_"))
|
|
63
|
-
.sort();
|
|
64
|
-
|
|
65
|
-
for (const file of scssFiles) {
|
|
66
|
-
try {
|
|
67
|
-
const result = sass.compile(file, {
|
|
68
|
-
loadPaths: [srcDir],
|
|
69
|
-
style: "expanded",
|
|
70
|
-
});
|
|
71
|
-
combinedCss += result.css + "\n";
|
|
72
|
-
} catch (err) {
|
|
73
|
-
console.error(`Error compiling ${path.basename(file)}:`, err.message);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
38
|
}
|
|
77
39
|
|
|
78
40
|
// 2. PostCSS (Autoprefixer + CSSNano)
|
|
@@ -89,3 +51,21 @@ export async function compileStyles(fileData) {
|
|
|
89
51
|
return "";
|
|
90
52
|
}
|
|
91
53
|
}
|
|
54
|
+
|
|
55
|
+
export async function mergeStyles(...cssContents) {
|
|
56
|
+
try {
|
|
57
|
+
const combinedCss = cssContents.join("\n");
|
|
58
|
+
|
|
59
|
+
if (combinedCss) {
|
|
60
|
+
const plugins = [autoprefixer(), cssnano()];
|
|
61
|
+
const result = await postcss(plugins).process(combinedCss, {
|
|
62
|
+
from: undefined,
|
|
63
|
+
});
|
|
64
|
+
return result.css;
|
|
65
|
+
}
|
|
66
|
+
return "";
|
|
67
|
+
} catch (error) {
|
|
68
|
+
console.error("Merge failed:", error);
|
|
69
|
+
return "";
|
|
70
|
+
}
|
|
71
|
+
}
|
|
Binary file
|
package/package.json
CHANGED
package/scripts.min.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
function generateRandomContent(t){let n="";for(let e=0;e<t;e++){var o=Math.random()*("z".charCodeAt(0)-"A".charCodeAt(0)),o=String.fromCharCode("A".charCodeAt(0)+o);n+=o}return n}function fillWithContent(){var e=document.getElementById("title");document.getElementById("content").value=generateRandomContent(200),e.value=generateRandomContent(50)}
|
|
1
|
+
function _createForOfIteratorHelper(e,t){var r,n,o,a,i="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(i)return o=!(n=!0),{s:function(){i=i.call(e)},n:function(){var e=i.next();return n=e.done,e},e:function(e){o=!0,r=e},f:function(){try{n||null==i.return||i.return()}finally{if(o)throw r}}};if(Array.isArray(e)||(i=_unsupportedIterableToArray(e))||t&&e&&"number"==typeof e.length)return i&&(e=i),a=0,{s:t=function(){},n:function(){return a>=e.length?{done:!0}:{done:!1,value:e[a++]}},e:function(e){throw e},f:t};throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _unsupportedIterableToArray(e,t){var r;if(e)return"string"==typeof e?_arrayLikeToArray(e,t):"Map"===(r="Object"===(r={}.toString.call(e).slice(8,-1))&&e.constructor?e.constructor.name:r)||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?_arrayLikeToArray(e,t):void 0}function _arrayLikeToArray(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function _regenerator(){var g,e="function"==typeof Symbol?Symbol:{},t=e.iterator||"@@iterator",r=e.toStringTag||"@@toStringTag";function n(e,t,r,n){var o,a,i,c,l,u,f,s,d,t=t&&t.prototype instanceof h?t:h,t=Object.create(t.prototype);return _regeneratorDefine2(t,"_invoke",(o=e,a=r,f=n||[],s=!1,d={p:u=0,n:0,v:g,a:p,f:p.bind(g,4),d:function(e,t){return i=e,c=0,l=g,d.n=t,y}},function(e,t,r){if(1<u)throw TypeError("Generator is already running");for(s&&1===t&&p(t,r),c=t,l=r;(m=c<2?g:l)||!s;){i||(c?c<3?(1<c&&(d.n=-1),p(c,l)):d.n=l:d.v=l);try{if(u=2,i){if(m=i[e=c?e:"next"]){if(!(m=m.call(i,l)))throw TypeError("iterator result is not an object");if(!m.done)return m;l=m.value,c<2&&(c=0)}else 1===c&&(m=i.return)&&m.call(i),c<2&&(l=TypeError("The iterator does not provide a '"+e+"' method"),c=1);i=g}else if((m=(s=d.n<0)?l:o.call(a,d))!==y)break}catch(e){i=g,c=1,l=e}finally{u=1}}return{value:m,done:s}}),!0),t;function p(e,t){for(c=e,l=t,m=0;!s&&u&&!r&&m<f.length;m++){var r,n=f[m],o=d.p,a=n[2];3<e?(r=a===t)&&(l=n[(c=n[4])?5:c=3],n[4]=n[5]=g):n[0]<=o&&((r=e<2&&o<n[1])?(c=0,d.v=t,d.n=n[1]):o<a&&(r=e<3||n[0]>t||a<t)&&(n[4]=e,n[5]=t,d.n=a,c=0))}if(r||1<e)return y;throw s=!0,t}}var y={};function h(){}function o(){}function a(){}var m=Object.getPrototypeOf,e=[][t]?m(m([][t]())):(_regeneratorDefine2(m={},t,function(){return this}),m),i=a.prototype=h.prototype=Object.create(e);function c(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,a):(e.__proto__=a,_regeneratorDefine2(e,r,"GeneratorFunction")),e.prototype=Object.create(i),e}return _regeneratorDefine2(i,"constructor",o.prototype=a),_regeneratorDefine2(a,"constructor",o),_regeneratorDefine2(a,r,o.displayName="GeneratorFunction"),_regeneratorDefine2(i),_regeneratorDefine2(i,r,"Generator"),_regeneratorDefine2(i,t,function(){return this}),_regeneratorDefine2(i,"toString",function(){return"[object Generator]"}),(_regenerator=function(){return{w:n,m:c}})()}function _regeneratorDefine2(e,t,r,n){var a=Object.defineProperty;try{a({},"",{})}catch(e){a=0}(_regeneratorDefine2=function(e,t,r,n){function o(t,r){_regeneratorDefine2(e,t,function(e){return this._invoke(t,r,e)})}t?a?a(e,t,{value:r,enumerable:!n,configurable:!n,writable:!n}):e[t]=r:(o("next",0),o("throw",1),o("return",2))})(e,t,r,n)}function asyncGeneratorStep(e,t,r,n,o,a,i){try{var c=e[a](i),l=c.value}catch(e){return void r(e)}c.done?t(l):Promise.resolve(l).then(n,o)}function _asyncToGenerator(c){return function(){var e=this,i=arguments;return new Promise(function(t,r){var n=c.apply(e,i);function o(e){asyncGeneratorStep(n,t,r,o,a,"next",e)}function a(e){asyncGeneratorStep(n,t,r,o,a,"throw",e)}o(void 0)})}}var isLoading=!1;function handleScroll(){return _handleScroll.apply(this,arguments)}function _handleScroll(){return(_handleScroll=_asyncToGenerator(_regenerator().m(function e(){return _regenerator().w(function(e){for(;;)switch(e.n){case 0:if(isLoading)return e.a(2);e.n=1;break;case 1:if(document.documentElement.scrollHeight-window.innerHeight-window.scrollY<100)return e.n=2,loadMore();e.n=2;break;case 2:return e.a(2)}},e)}))).apply(this,arguments)}function loadMore(){return _loadMore.apply(this,arguments)}function _loadMore(){return(_loadMore=_asyncToGenerator(_regenerator().m(function e(){var t,r,n,o,a,i,c,l;return _regenerator().w(function(e){for(;;)switch(e.p=e.n){case 0:if(console.log("load more"),t=document.getElementById("articles"),t=t.querySelectorAll("article"),t=t[t.length-1],console.log("lastArticle",t),t){e.n=1;break}return e.a(2);case 1:if(r=parseInt(t.getAttribute("data-id")),console.log("lastId ".concat(r)),isNaN(r))return e.a(2);e.n=2;break;case 2:if((n=r-1)<1)return console.log("nextId < 1 ".concat(n<1)),window.removeEventListener("scroll",handleScroll),e.a(2);e.n=3;break;case 3:return isLoading=!0,o="/api/articles?startID=".concat(n,"&limit=5"),console.log("load more ".concat(o)),e.p=4,e.n=5,fetch(o);case 5:if((o=e.v).ok)return e.n=6,o.json();e.n=7;break;case 6:if((l=e.v).articles&&0<l.articles.length){a=_createForOfIteratorHelper(l.articles);try{for(a.s();!(i=a.n()).done;)fillWithContent((c=i.value).title,c.content,c.createdAt,c.id)}catch(e){a.e(e)}finally{a.f()}}case 7:e.n=9;break;case 8:e.p=8,l=e.v,console.error("Failed to load articles:",l);case 9:isLoading=!1;case 10:return e.a(2)}},e,null,[[4,8]])}))).apply(this,arguments)}function getFormattedDate(e){var t=e.getFullYear(),r=String(e.getMonth()+1).padStart(2,"0"),n=String(e.getDate()).padStart(2,"0"),o=String(e.getHours()).padStart(2,"0"),e=String(e.getMinutes()).padStart(2,"0");return"".concat(t,"/").concat(r,"/").concat(n," ").concat(o,":").concat(e)}function fillWithContent(e,t,r,n){var o=document.createElement("article"),n=(n&&o.setAttribute("data-id",n),document.createElement("h2")),a=document.createElement("span"),i=document.createElement("p");n.textContent=e,a.textContent=getFormattedDate(new Date(r)),i.textContent=t,o.appendChild(n),o.appendChild(a),o.appendChild(i),document.getElementById("articles").appendChild(o)}function test(){console.log("123")}document.addEventListener("DOMContentLoaded",function(){window.addEventListener("scroll",handleScroll)});
|
package/src/styles.css
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
.grid {
|
|
2
|
+
border: 0 solid #000;
|
|
3
|
+
display: grid;
|
|
4
|
+
gap: 0.25rem;
|
|
5
|
+
grid-template-columns: 1fr;
|
|
6
|
+
}
|
|
7
|
+
.grid article {
|
|
8
|
+
border: 0 solid #ccc;
|
|
9
|
+
border-radius: 4px;
|
|
10
|
+
min-width: 0;
|
|
11
|
+
overflow-wrap: break-word;
|
|
12
|
+
padding: 0.25rem;
|
|
13
|
+
}
|
|
14
|
+
.grid article h2 {
|
|
15
|
+
color: rgb(53, 53, 53);
|
|
16
|
+
margin-bottom: 5px;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.grid article .datetime {
|
|
20
|
+
margin: 0;
|
|
21
|
+
color: rgb(117, 117, 117);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.grid article p {
|
|
25
|
+
margin-top: 10px;
|
|
26
|
+
margin-bottom: 0;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
article a {
|
|
30
|
+
color: rgb(105, 105, 105);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
article a:visited {
|
|
34
|
+
color: rgb(105, 105, 105);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
h1 {
|
|
38
|
+
color: #696969;
|
|
39
|
+
}
|
|
40
|
+
nav a {
|
|
41
|
+
color: #3b40c1;
|
|
42
|
+
font-size: 20px;
|
|
43
|
+
text-decoration: underline;
|
|
44
|
+
}
|
|
45
|
+
nav a:visited {
|
|
46
|
+
color: #3b40c1;
|
|
47
|
+
text-decoration-color: #3b40c1;
|
|
48
|
+
}
|
package/styles.min.css
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
/* source-hash: fa9deb7a7f0781f463cd3e8fd3c3ceddec518535b0a6d13af7309ef9a2f76c32 */
|
|
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 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;text-decoration:underline}nav a:visited{color:#3b40c1;text-decoration-color:#3b40c1}
|
|
File without changes
|