nodoku-core 0.2.1 → 0.2.3

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.
@@ -12,16 +12,12 @@ register('./import-load-hooks.js', import.meta.url);
12
12
  */
13
13
  // @ts-ignore
14
14
  const template = (await import("./mustache/component-resolver.ts.hbs")).default;
15
- class TemplateView {
16
- modules = [];
17
- comps = [];
18
- }
19
15
  function calculateTemplateView(dirNodeModules = undefined) {
20
16
  if (!dirNodeModules) {
21
17
  dirNodeModules = `${path.resolve()}/node_modules`;
22
18
  }
23
19
  const manifests = loadManifestsFromFolder(dirNodeModules);
24
- const view = new TemplateView();
20
+ const view = { modules: [], comps: [] };
25
21
  manifests.forEach((m, k) => {
26
22
  let prefix = "";
27
23
  if (m.namespace) {
@@ -12,15 +12,12 @@ register('./import-load-hooks.js', import.meta.url);
12
12
  */
13
13
  // @ts-ignore
14
14
  const template = (await import("./mustache/visual-schema.json.hbs")).default;
15
- class TemplateView {
16
- components = new Map();
17
- }
18
15
  function calculateTemplateView(schemaDestinationDir, dirNodeModules = undefined) {
19
16
  if (!dirNodeModules) {
20
17
  dirNodeModules = path.resolve("./node_modules");
21
18
  }
22
19
  const components = loadManifestsFromFolder(dirNodeModules);
23
- const tv = new TemplateView();
20
+ const tv = { components: new Map() };
24
21
  components.forEach((m) => {
25
22
  m.components.forEach((cd, cn) => {
26
23
  const moduleDir = `${dirNodeModules}/${m.moduleName}`;
@@ -1,4 +1,3 @@
1
- import { ComponentDef, Manifest } from "./manifest.js";
2
1
  import fs from "node:fs";
3
2
  import path from "path";
4
3
  export function loadManifestsFromFolder(dir) {
@@ -23,7 +22,11 @@ function loadComponentsByManifest(dir, moduleName) {
23
22
  const stat = fs.statSync(moduleDir);
24
23
  if (stat.isFile()) {
25
24
  if (f == "nodoku.manifest.json") {
26
- const manifest = new Manifest(moduleName, moduleDir);
25
+ const manifest = {
26
+ moduleName: moduleName,
27
+ moduleDir: moduleDir,
28
+ components: new Map()
29
+ };
27
30
  console.log("found manifest ", `${dir}/${f}`, "reading...");
28
31
  let json;
29
32
  if (stat.isSymbolicLink()) {
@@ -39,7 +42,14 @@ function loadComponentsByManifest(dir, moduleName) {
39
42
  const v = json.components[k];
40
43
  console.log("adding ", k, v);
41
44
  // comps.set(k, Manifest.from(k, moduleName, v));
42
- manifest.components.set(k, new ComponentDef(v.implementation, v.schemaFile, v.optionsFile, v.defaultThemeFile, v.numBlocks));
45
+ // manifest.components.set(k, new ComponentDef(v.implementation, v.schemaFile, v.optionsFile, v.defaultThemeFile, v.numBlocks))
46
+ manifest.components.set(k, {
47
+ implementation: v.implementation,
48
+ themeSchema: v.schemaFile,
49
+ optionsSchema: v.optionsFile,
50
+ defaultThemeFile: v.defaultThemeFile,
51
+ numBlocks: v.numBlocks
52
+ });
43
53
  });
44
54
  return manifest;
45
55
  }
@@ -1,24 +1 @@
1
- export class ComponentDef {
2
- implementation;
3
- themeSchema;
4
- optionsSchema;
5
- defaultThemeFile;
6
- numBlocks;
7
- constructor(componentImplementation, componentSchema, optionsSchema, defaultThemeFile, numBlocks) {
8
- this.implementation = componentImplementation;
9
- this.themeSchema = componentSchema;
10
- this.optionsSchema = optionsSchema;
11
- this.defaultThemeFile = defaultThemeFile;
12
- this.numBlocks = numBlocks;
13
- }
14
- }
15
- export class Manifest {
16
- moduleName;
17
- moduleDir;
18
- namespace = undefined;
19
- components = new Map();
20
- constructor(moduleName, moduleDir) {
21
- this.moduleName = moduleName;
22
- this.moduleDir = moduleDir;
23
- }
24
- }
1
+ export {};
@@ -3,6 +3,10 @@ export class NdContentImage {
3
3
  title;
4
4
  alt;
5
5
  }
6
+ export class NdCallToAction {
7
+ ctaUrl = {};
8
+ ctaTitle;
9
+ }
6
10
  export class NdTranslatableText {
7
11
  key = "";
8
12
  ns = "";
@@ -49,9 +53,8 @@ export class NdContentBlock {
49
53
  h4;
50
54
  h5;
51
55
  h6;
52
- footer;
56
+ callToActions = [];
53
57
  paragraphs = [];
54
- // bgImageUrl?: NdTranslatableText;
55
58
  images = [];
56
59
  htmlElements = [];
57
60
  constructor(id, ns, lng) {
@@ -6,17 +6,12 @@ export async function DummyComp(props) {
6
6
  return <div>{await render(rowIndex, componentIndex, content[0], t)}</div>;
7
7
  }
8
8
  async function render(rowIndex, componentIndex, block, t) {
9
- // var style = {};
10
- // if (block.bgImageUrl) {
11
- // style = {backgroundImage: `url(${t(block.bgImageUrl)})`}
12
- // }
9
+ console.log("this is my block", block.callToActions.map(cta => `${cta.ctaUrl.key}`));
13
10
  return (<div className={"w-full w-full flex flex-col items-left justify-left border border-4 border-red-200 relative pb-10"}>
14
- {/*<div className={"top-0 bottom-0 left-0 right-0 absolute bg-cover bg-no-repeat"}*/}
15
- {/* style={{...style, zIndex: -11}}>*/}
16
- {/*</div>*/}
17
- <div className={"top-0 bottom-0 left-0 right-0 absolute bg-white "} style={{ zIndex: -5, opacity: 0.7 }}>
11
+ <div className={"top-0 bottom-0 left-0 right-0 absolute bg-white "} style={{ zIndex: -5, opacity: 0.7 }}></div>
12
+ <div className={"p-5 w-full bg-red-400 text-center"}>
13
+ dummy component<h3><b>{`ns-${block.namespace}-row-${rowIndex}-i-${componentIndex}`}</b></h3>
18
14
  </div>
19
- <div className={"p-5 w-full bg-red-400 text-center"}>dummy component<h3><b>{`ns-${block.namespace}-row-${rowIndex}-i-${componentIndex}`}</b></h3></div>
20
15
 
21
16
 
22
17
  <div className="p-5">
@@ -86,8 +81,10 @@ async function render(rowIndex, componentIndex, block, t) {
86
81
  </div>
87
82
 
88
83
  <div className={"absolute bottom-0 p-5"}>
89
- {block.footer?.key}
90
- <p>{block.footer && t(block.footer)}</p>
84
+ {block.callToActions.map((cta) => {
85
+ return <p><b>{`${t(cta.ctaTitle || cta.ctaUrl)}: ${t(cta.ctaUrl)}`}</b>{`${cta.ctaUrl.key}: ${t(cta.ctaUrl)}`}</p>;
86
+ })}
87
+
91
88
  </div>
92
89
 
93
90
  </div>);
@@ -6,6 +6,7 @@ import yaml from "js-yaml";
6
6
  import fs from "node:fs";
7
7
  import { mergeTheme } from "../theme-utils/theme-merger";
8
8
  import { defaultRowThemeImpl } from "../theme-utils/row-style";
9
+ import { ts } from "../index";
9
10
  async function defaultComponentResolver() {
10
11
  const compoDef = new NdComponentDefinition("unlimited", undefined, {});
11
12
  return { compo: DummyComp, compoDef: compoDef };
@@ -30,7 +31,8 @@ async function RenderingPage(props) {
30
31
  else {
31
32
  l = [await createRow(undefined, 0, content, lng, imageProvider, i18nextProvider, actualComponentResolver)];
32
33
  }
33
- return <div className={`${skin?.renderingPage?.base} ${skin?.renderingPage?.decoration}`}>{l}</div>;
34
+ const actualSkin = mergeTheme(skin, { renderingPage: { base: "", decoration: "" }, rows: [] });
35
+ return <div className={`rows-container ${ts(actualSkin, "renderingPage")}`}>{l}</div>;
34
36
  }
35
37
  function generateSkinByContentBlocks(blocks, skin) {
36
38
  const rendered = new Set();
@@ -74,7 +76,7 @@ async function createRow(row, iRow, blocks, lng, imageProvider, i18nProvider, co
74
76
  }
75
77
  const rowComponents = l.flatMap((p) => p);
76
78
  if (rowComponents.length == 0) {
77
- return <></>;
79
+ return <div key={`row-${iRow}`}></div>;
78
80
  }
79
81
  const numComponents = rowComponents.length;
80
82
  const rowEffectiveTheme = mergeTheme(row?.theme, defaultRowThemeImpl);
@@ -136,8 +138,8 @@ async function createRow(row, iRow, blocks, lng, imageProvider, i18nProvider, co
136
138
  if (rowEffectiveTheme.rowDisplay == "flex") {
137
139
  rowDisplay = "flex flex-row justify-center flex-wrap flex-1";
138
140
  }
139
- return (<div key={`row-${iRow}`} className={`${rowDisplay} ${rowEffectiveTheme?.base} ${rowEffectiveTheme?.decoration} class-row-${iRow}`}>
140
- {rowComponents.map((c) => <div className={`nd-component-holder ${flexBasis} ${rowEffectiveTheme.componentHolder?.base} ${rowEffectiveTheme.componentHolder?.decoration}`}>
141
+ return (<div key={`row-${iRow}`} className={`row-${iRow} ${rowDisplay} ${rowEffectiveTheme?.base} ${rowEffectiveTheme?.decoration} class-row-${iRow}`}>
142
+ {rowComponents.map((c, i) => <div key={`row-${iRow}-component-${i}`} className={`row-${iRow}-component-${i} nd-component-holder ${flexBasis} ${ts(rowEffectiveTheme, "componentHolder")}`}>
141
143
  {c}
142
144
  </div>)}
143
145
  </div>);
package/esm/index.js CHANGED
@@ -1,10 +1,10 @@
1
- import { NdContentImage, NdTranslatableText, NdList, NdCode, NdContentBlock } from "./content/nd-content";
1
+ import { NdContentImage, NdTranslatableText, NdList, NdCode, NdCallToAction, NdContentBlock } from "./content/nd-content";
2
2
  import { NdSkinComponent, NdRow, NdPageSkin, NdSkinComponentProps, NdContentSelector, NdComponentDefinition, NdThemeHierarchy } from "./skin/nd-skin";
3
3
  import { RenderingPageProps, RenderingPriority } from "./core/rendering-page-props";
4
4
  import { RenderingPage } from "./core/rendering-page";
5
5
  import { mergeTheme } from "./theme-utils/theme-merger";
6
6
  import { defaultRowThemeImpl } from "./theme-utils/row-style";
7
- export { NdContentImage, NdTranslatableText, NdList, NdCode, NdContentBlock, NdSkinComponent, NdRow, NdPageSkin, NdSkinComponentProps, NdContentSelector, NdComponentDefinition, NdThemeHierarchy };
7
+ export { NdContentImage, NdTranslatableText, NdList, NdCode, NdCallToAction, NdContentBlock, NdSkinComponent, NdRow, NdPageSkin, NdSkinComponentProps, NdContentSelector, NdComponentDefinition, NdThemeHierarchy };
8
8
  export { RenderingPageProps, RenderingPriority, RenderingPage };
9
9
  export { mergeTheme };
10
10
  export { DummyComp } from "./core/dummy-comp";
@@ -2,6 +2,7 @@ import { NdTranslatableText, NdList, NdContentBlock, NdContentImage, NdCode } fr
2
2
  import { Marked } from '@ts-stack/markdown';
3
3
  import { parse } from 'node-html-parser';
4
4
  import yaml from "js-yaml";
5
+ import { NdCallToAction } from "../../content/nd-content";
5
6
  const nsRegex = /.*\/(.*)\.md/;
6
7
  export async function contentMarkdownProvider(mdFileUrl, contentLng, ns = undefined) {
7
8
  return await fetch(mdFileUrl)
@@ -19,7 +20,7 @@ export async function contentMarkdownProvider(mdFileUrl, contentLng, ns = undefi
19
20
  return parseMarkdownAsContent(fileContent, contentLng, ns);
20
21
  });
21
22
  }
22
- const footerPattern = /^\|(.*)\|/;
23
+ const callToActionPattern = /^\|(.*)\|/;
23
24
  const codePattern = /<code class="lang-(\w+)">(.*)<\/code>/s;
24
25
  class BlockHolder {
25
26
  blockIndex;
@@ -34,7 +35,7 @@ class BlockHolder {
34
35
  this.blockIndex = blockIndex;
35
36
  this.blockDefIndex = blockDefIndex;
36
37
  }
37
- blockContent = { paragraphsIndex: [], imagesIndex: [], htmlStream: [] };
38
+ blockContent = { paragraphsIndex: [], imagesIndex: [], callToActionIndex: [], htmlStream: [] };
38
39
  hasContentH1AndBelow() {
39
40
  return this.blockContent.titleIndex != undefined || this.hasContentH2AndBelow();
40
41
  }
@@ -128,6 +129,12 @@ class BlockHolder {
128
129
  this.blockContent.htmlStream.push(childNode);
129
130
  return this;
130
131
  }
132
+ addCallToAction(childNode) {
133
+ this.blockContent.callToActionIndex.push(this.blockContent.htmlStream.length);
134
+ // console.log("adding html for cta", childNode.innerHTML)
135
+ this.blockContent.htmlStream.push(childNode);
136
+ return this;
137
+ }
131
138
  addHorizontalLine(childNode) {
132
139
  this.blockContent.htmlStream.push(childNode);
133
140
  return this;
@@ -168,6 +175,7 @@ class BlockHolder {
168
175
  // console.log("creating block: ", this.blockContent.paragraphsIndex)
169
176
  let pi = 0;
170
177
  let imi = 0;
178
+ let ci = 0;
171
179
  this.blockContent.htmlStream.forEach((htmlElem, i) => {
172
180
  let text = undefined;
173
181
  if (i === this.blockContent.titleIndex) {
@@ -242,21 +250,41 @@ class BlockHolder {
242
250
  imi++;
243
251
  }
244
252
  }
253
+ else if (this.blockContent.callToActionIndex.indexOf(i) >= 0) {
254
+ const cta = this.parseCallToAction(blockId, htmlElem, ci);
255
+ if (cta) {
256
+ newBlock.callToActions.push(cta);
257
+ text = cta;
258
+ ci++;
259
+ // console.log("added call to action: ", cta)
260
+ }
261
+ }
245
262
  else {
246
263
  text = new NdTranslatableText(this.ns, `${blockId}.htmlElements.${newBlock.htmlElements.length}`, "");
247
264
  }
248
265
  newBlock.htmlElements.push({ htmlElem: htmlElem, translatedText: text });
249
266
  });
250
- if (this.blockContent.footer && this.blockContent.footer.trim().length > 0) {
251
- newBlock.footer = new NdTranslatableText(this.ns, `${blockId}.footer`, this.blockContent.footer);
252
- }
253
- // if (this.blockContent.bgImage && this.blockContent.bgImage.getAttribute("src")) {
254
- // newBlock.bgImageUrl = new NdTranslatableText(this.ns, `${blockId}.bgImageUrl`,
255
- // this.blockContent.bgImage.getAttribute("src") as string, true);
267
+ // if (this.blockContent.footer && this.blockContent.footer.trim().length > 0) {
268
+ // newBlock.footer = new NdTranslatableText(this.ns, `${blockId}.footer`, this.blockContent.footer);
256
269
  // }
257
- // console.log("added block", newBlock)
258
270
  return newBlock;
259
271
  }
272
+ parseCallToAction(blockId, ctaHtml, ci) {
273
+ const cta = new NdCallToAction();
274
+ // console.log("parsing callToAction", ctaHtml.innerHTML, ctaHtml.rawTagName, ctaHtml.attributes, ctaHtml.childNodes.map(cn => cn.rawTagName));
275
+ // const res = callToActionPattern.exec(ctaHtml.innerHTML)
276
+ const cnRef = ctaHtml.childNodes.find(cn => cn.rawTagName === "a");
277
+ let url = "n/a";
278
+ let title = ctaHtml.innerHTML;
279
+ if (cnRef) {
280
+ url = cnRef.getAttribute("href") || url;
281
+ title = cnRef.textContent;
282
+ }
283
+ cta.ctaUrl = new NdTranslatableText(this.ns, `${blockId}.callToActions.${ci}.ctaUrl`, url);
284
+ cta.ctaTitle = new NdTranslatableText(this.ns, `${blockId}.callToActions.${ci}.ctaTitle`, title);
285
+ // console.log("returnin created cta: ", cta)
286
+ return cta;
287
+ }
260
288
  parseParagraph(blockId, p, pi) {
261
289
  if (p.rawTagName === "p" || p.rawTagName === "blockquote") {
262
290
  return new NdTranslatableText(this.ns, `${blockId}.paragraphs.${pi}`, p.innerHTML);
@@ -341,23 +369,22 @@ export function parseMarkdownAsContent(fileContents, contentLng, ns) {
341
369
  currentBlock.addParagraph(childNode);
342
370
  }
343
371
  else if (childNode.rawTagName === "p" || childNode.rawTagName === "blockquote") {
344
- const rFooter = footerPattern.exec(childNode.innerHTML);
345
- if (rFooter) {
346
- currentBlock.blockContent.footer = rFooter[1];
347
- }
348
- else if (childNode.childNodes && childNode.childNodes.filter(cn => cn.rawTagName == "img").length > 0) {
372
+ if (childNode.childNodes &&
373
+ childNode.childNodes.filter(cn => cn.rawTagName == "img").length > 0) {
349
374
  childNode.childNodes.filter(cn => cn.rawTagName == "img")
350
375
  .forEach((cn) => {
351
- const l = cn;
352
- // if (l.getAttribute("alt") === "bg-image") {
353
- // currentBlock.blockContent.bgImage = l;
354
- // } else {
355
376
  currentBlock.addImage(cn);
356
- // }
357
377
  });
358
378
  }
359
379
  else {
360
- currentBlock.addParagraph(childNode);
380
+ const rCta = callToActionPattern.exec(childNode.innerHTML);
381
+ if (rCta) {
382
+ // console.log("cta childNode", childNode)
383
+ currentBlock.addCallToAction(childNode);
384
+ }
385
+ else {
386
+ currentBlock.addParagraph(childNode);
387
+ }
361
388
  }
362
389
  }
363
390
  else if (childNode.rawTagName === "figure") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodoku-core",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "description": "basic foundation for nodoku static site generator",
5
5
  "exports": {
6
6
  ".": {
@@ -1,15 +1,13 @@
1
- export declare class ComponentDef {
1
+ export type ComponentDef = {
2
2
  implementation: string;
3
3
  themeSchema: string;
4
4
  optionsSchema: string;
5
5
  defaultThemeFile: string;
6
6
  numBlocks: string | number;
7
- constructor(componentImplementation: string, componentSchema: string, optionsSchema: string, defaultThemeFile: string, numBlocks: string | number);
8
- }
9
- export declare class Manifest {
7
+ };
8
+ export type Manifest = {
10
9
  moduleName: string;
11
10
  moduleDir: string;
12
- namespace: string | undefined;
11
+ namespace?: string;
13
12
  components: Map<string, ComponentDef>;
14
- constructor(moduleName: string, moduleDir: string);
15
- }
13
+ };
@@ -4,6 +4,10 @@ export declare class NdContentImage {
4
4
  title?: NdTranslatableText;
5
5
  alt?: NdTranslatableText;
6
6
  }
7
+ export declare class NdCallToAction {
8
+ ctaUrl: NdTranslatableText;
9
+ ctaTitle?: NdTranslatableText;
10
+ }
7
11
  export declare class NdTranslatableText {
8
12
  key: string;
9
13
  ns: string;
@@ -38,12 +42,12 @@ export declare class NdContentBlock {
38
42
  h4?: NdTranslatableText;
39
43
  h5?: NdTranslatableText;
40
44
  h6?: NdTranslatableText;
41
- footer?: NdTranslatableText;
45
+ callToActions: NdCallToAction[];
42
46
  paragraphs: (NdTranslatableText | NdList | NdCode)[];
43
47
  images: NdContentImage[];
44
48
  htmlElements: {
45
49
  htmlElem: HTMLElement;
46
- translatedText: (NdTranslatableText | NdContentImage | NdList | NdCode);
50
+ translatedText: (NdTranslatableText | NdContentImage | NdList | NdCode | NdCallToAction);
47
51
  }[];
48
52
  constructor(id: string, ns: string, lng: string);
49
53
  getByKey(key: string, ns: string): string | undefined;
package/types/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { NdContentImage, NdTranslatableText, NdList, NdCode, NdContentBlock } from "./content/nd-content";
1
+ import { NdContentImage, NdTranslatableText, NdList, NdCode, NdCallToAction, NdContentBlock } from "./content/nd-content";
2
2
  import { NdSkinComponent, NdRow, NdPageSkin, NdSkinComponentProps, NdContentSelector, NdComponentDefinition, NdThemeHierarchy, NdDefaultThemeName } from "./skin/nd-skin";
3
3
  import { RenderingPageProps, RenderingPriority } from "./core/rendering-page-props";
4
4
  import { RenderingPage } from "./core/rendering-page";
@@ -8,7 +8,7 @@ import { ThemeStyle } from "./theme-utils/theme-style";
8
8
  import { ExtendedThemeStyle } from "./theme-utils/extended-theme-style";
9
9
  import { ImageStyle } from "./theme-utils/image-style";
10
10
  import { RowStyle } from "./theme-utils/row-style";
11
- export { NdContentImage, NdTranslatableText, NdList, NdCode, NdContentBlock, NdSkinComponent, NdRow, NdPageSkin, NdSkinComponentProps, NdContentSelector, NdComponentDefinition, NdThemeHierarchy, type NdDefaultThemeName, type NdImageProps };
11
+ export { NdContentImage, NdTranslatableText, NdList, NdCode, NdCallToAction, NdContentBlock, NdSkinComponent, NdRow, NdPageSkin, NdSkinComponentProps, NdContentSelector, NdComponentDefinition, NdThemeHierarchy, type NdDefaultThemeName, type NdImageProps };
12
12
  export { RenderingPageProps, RenderingPriority, RenderingPage };
13
13
  export { mergeTheme, type ThemeStyle, type ExtendedThemeStyle, type ImageStyle };
14
14
  export type { I18nextProvider, AsyncFunctionComponent, ImageProvider };