@shevky/core 0.0.3 → 0.0.5

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
@@ -517,7 +517,9 @@ export class RenderEngine {
517
517
  return;
518
518
  }
519
519
 
520
- const configKeys = Object.keys(collectionsConfig);
520
+ const configKeys = Object.keys(collectionsConfig).filter(
521
+ (key) => key !== "includeContentFile",
522
+ );
521
523
  for (const configKey of configKeys) {
522
524
  const config = collectionsConfig[configKey];
523
525
  if (!config || typeof config !== "object") {
@@ -167,4 +167,16 @@ export class ContentFile {
167
167
  get isPostTemplate() {
168
168
  return this.template === "post";
169
169
  }
170
+
171
+ toObject() {
172
+ return {
173
+ header: this._header.raw,
174
+ body: {
175
+ content: this.content,
176
+ },
177
+ content: this.content,
178
+ isValid: this.isValid,
179
+ sourcePath: this.sourcePath,
180
+ };
181
+ }
170
182
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shevky/core",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
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.3",
40
40
  "@types/node": "^20.11.30",
41
41
  "@types/mustache": "^4.2.6",
42
42
  "@types/html-minifier-terser": "^7.0.2",
@@ -1,4 +1,4 @@
1
- import { io as _io } from "@shevky/base";
1
+ import { io as _io, config as _cfg } from "@shevky/base";
2
2
  import matter from "gray-matter";
3
3
 
4
4
  import { ContentFile } from "../lib/contentFile.js";
@@ -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
  */
@@ -171,6 +202,9 @@ export class ContentRegistry {
171
202
  return this.#_collectionsCache;
172
203
  }
173
204
 
205
+ const includeContentFile = Boolean(
206
+ _cfg?.content?.collections?.includeContentFile,
207
+ );
174
208
  /** @type {import("../types/index.d.ts").CollectionsByLang} */
175
209
  const pagesByLang = {};
176
210
  const contentFiles = this.files;
@@ -180,8 +214,10 @@ export class ContentRegistry {
180
214
  }
181
215
 
182
216
  const contentSummary = new ContentSummary(file);
217
+ const summaryBase = contentSummary.toObject();
183
218
  const summary = /** @type {import("../types/index.d.ts").CollectionEntry} */ ({
184
- ...contentSummary.toObject(),
219
+ ...summaryBase,
220
+ ...(includeContentFile ? file.toObject() : {}),
185
221
  canonical: this.#_metaEngine.buildContentUrl(
186
222
  file.canonical,
187
223
  file.lang,
@@ -246,6 +282,12 @@ export class ContentRegistry {
246
282
  return new ContentFile(data, content, filePath, isValid);
247
283
  }
248
284
 
285
+ #_resetCaches() {
286
+ this.#_collectionsCache = null;
287
+ this.#_footerPoliciesCache = null;
288
+ this.#_contentIndexCache = null;
289
+ }
290
+
249
291
  /**
250
292
  * @param {Record<string, import("../types/index.d.ts").CollectionEntry[]>} store
251
293
  * @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,
@@ -72,6 +91,11 @@ export type CollectionEntry = ContentSummaryLike & {
72
91
  type?: string;
73
92
  seriesTitle?: string;
74
93
  canonical?: string;
94
+ header?: ContentHeaderLike;
95
+ body?: ContentBodyLike;
96
+ content?: string;
97
+ isValid?: boolean;
98
+ sourcePath?: string;
75
99
  };
76
100
 
77
101
  export type CollectionsByLang = Record<string, Record<string, CollectionEntry[]>>;