@shevky/core 0.0.3 → 0.0.4

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.
@@ -137,6 +137,7 @@ class MetaEngine {
137
137
  quote,
138
138
  home: this.resolveLanguageHomePath(lang),
139
139
  url: _cfg.identity.url,
140
+ ui: _cfg.ui ?? {},
140
141
  currentLanguage: lang,
141
142
  currentCulture: _i18n.culture(lang),
142
143
  currentCanonical: (() => {
@@ -87,6 +87,7 @@ export class PluginEngine {
87
87
  ...(hook === _plugin.hooks.CONTENT_LOAD
88
88
  ? {
89
89
  contentFiles: this.#_contentRegistry.files,
90
+ addContent: (input) => this.#_contentRegistry.addContent(input),
90
91
  }
91
92
  : {}),
92
93
  ...(hook === _plugin.hooks.CONTENT_READY && this.#_metaEngine
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shevky/core",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "description": "A minimal, dependency-light static site generator.",
5
5
  "type": "module",
6
6
  "main": "shevky.js",
@@ -36,7 +36,7 @@
36
36
  },
37
37
  "homepage": "https://github.com/shevky/core#readme",
38
38
  "dependencies": {
39
- "@shevky/base": "^0.0.1",
39
+ "@shevky/base": "^0.0.2",
40
40
  "@types/node": "^20.11.30",
41
41
  "@types/mustache": "^4.2.6",
42
42
  "@types/html-minifier-terser": "^7.0.2",
@@ -52,9 +52,7 @@ export class ContentRegistry {
52
52
  this.#_cache.push(contentFile);
53
53
  }
54
54
 
55
- this.#_collectionsCache = null;
56
- this.#_footerPoliciesCache = null;
57
- this.#_contentIndexCache = null;
55
+ this.#_resetCaches();
58
56
  }
59
57
 
60
58
  get count() {
@@ -65,6 +63,39 @@ export class ContentRegistry {
65
63
  return this.#_cache;
66
64
  }
67
65
 
66
+ /**
67
+ * @param {import("../types/index.d.ts").ContentFileLike | ContentFile} input
68
+ */
69
+ addContent(input) {
70
+ if (!input) {
71
+ return;
72
+ }
73
+
74
+ if (input instanceof ContentFile) {
75
+ this.#_cache.push(input);
76
+ this.#_resetCaches();
77
+ return;
78
+ }
79
+
80
+ const header =
81
+ input.header && typeof input.header === "object" ? input.header : {};
82
+ const content =
83
+ typeof input.content === "string"
84
+ ? input.content
85
+ : typeof input.body?.content === "string"
86
+ ? input.body.content
87
+ : "";
88
+ const sourcePath =
89
+ typeof input.sourcePath === "string"
90
+ ? input.sourcePath
91
+ : "plugin://content/unknown.md";
92
+ const isValid = typeof input.isValid === "boolean" ? input.isValid : true;
93
+
94
+ const contentFile = new ContentFile(header, content, sourcePath, isValid);
95
+ this.#_cache.push(contentFile);
96
+ this.#_resetCaches();
97
+ }
98
+
68
99
  /**
69
100
  * @returns {Record<string, Array<{ key: string, label: string, url: string, lang: string }>>}
70
101
  */
@@ -246,6 +277,12 @@ export class ContentRegistry {
246
277
  return new ContentFile(data, content, filePath, isValid);
247
278
  }
248
279
 
280
+ #_resetCaches() {
281
+ this.#_collectionsCache = null;
282
+ this.#_footerPoliciesCache = null;
283
+ this.#_contentIndexCache = null;
284
+ }
285
+
249
286
  /**
250
287
  * @param {Record<string, import("../types/index.d.ts").CollectionEntry[]>} store
251
288
  * @param {string} key
package/scripts/cli.js CHANGED
@@ -65,10 +65,10 @@ function help() {
65
65
  },
66
66
  {
67
67
  header: "Project Details",
68
- content: "Project Home: {underline https://tatoglu.net/project/shevky}",
68
+ content: "Project Home: {underline https://shevky.github.io}",
69
69
  },
70
70
  {
71
- content: "GitHub: {underline https://github.com/fatihtatoglu/shevky}",
71
+ content: "GitHub: {underline https://github.com/shevky}",
72
72
  },
73
73
  ];
74
74
 
package/scripts/main.js CHANGED
@@ -4,7 +4,7 @@ import _cli from "./cli.js";
4
4
  import _build from "./build.js";
5
5
  import _init from "./init.js";
6
6
 
7
- const VERSION = "0.0.1";
7
+ const VERSION = "0.0.4";
8
8
 
9
9
  const __filename = _io.url.toPath(import.meta.url);
10
10
  const __dirname = _io.path.name(__filename);
package/types/index.d.ts CHANGED
@@ -27,9 +27,28 @@ export type PluginInstance = {
27
27
 
28
28
  export type PluginLoadContext = BasePluginLoadContext;
29
29
 
30
+ export type ContentHeaderLike = Record<string, any>;
31
+
32
+ export type ContentBodyLike = {
33
+ content?: string;
34
+ };
35
+
36
+ export type ContentFileLike = {
37
+ header?: ContentHeaderLike;
38
+ body?: ContentBodyLike;
39
+ content?: string;
40
+ isValid?: boolean;
41
+ sourcePath?: string;
42
+ };
43
+
30
44
  export interface PluginExecutionContext extends BasePluginContext {
31
45
  paths: ProjectPaths;
32
- contentFiles?: import("@shevky/base").ContentFileLike[];
46
+ contentFiles?: ContentFileLike[];
47
+ addContent?: (
48
+ input:
49
+ | ContentFileLike
50
+ | import("../lib/contentFile.js").ContentFile
51
+ ) => void;
33
52
  pages?: CollectionsByLang;
34
53
  contentIndex?: Record<
35
54
  string,