nodoku-core 0.1.4 → 0.1.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.
package/README.md ADDED
@@ -0,0 +1,903 @@
1
+ <!-- TOC -->
2
+ * [Nodoku foundation](#nodoku-foundation)
3
+ * [Nodoku content flow](#nodoku-content-flow)
4
+ * [Nodoku skin](#nodoku-skin)
5
+ * [Getting started](#getting-started)
6
+ * [Prerequisites](#prerequisites)
7
+ * [Installation](#installation)
8
+ * [Integrating Nodoku into a project](#integrating-nodoku-into-a-project)
9
+ * [Loding and parsing of the content MD file](#loding-and-parsing-of-the-content-md-file)
10
+ * [Explicitly providing content blockId](#explicitly-providing-content-blockid)
11
+ * [Automatic generation of content blockId](#automatic-generation-of-content-blockid)
12
+ * [Loading of the skin Yaml file](#loading-of-the-skin-yaml-file)
13
+ * [Rendering Nodoku](#rendering-nodoku)
14
+ * [Nodoku component resolver](#nodoku-component-resolver)
15
+ * [Configuring Nodoku project](#configuring-nodoku-project)
16
+ * [Tailwind configuration](#tailwind-configuration)
17
+ * [Webpack configuration](#webpack-configuration)
18
+ * [Nodoku component bundle](#nodoku-component-bundle)
19
+ * [Nodoku manifest](#nodoku-manifest-)
20
+ * [Nodoku skin](#nodoku-skin-1)
21
+ * [Nodoku visual component theme](#nodoku-visual-component-theme)
22
+ * [The Nodoku skin Yaml file](#the-nodoku-skin-yaml-file)
23
+ * [Schema for Nodoku skin Yaml file](#schema-for-nodoku-skin-yaml-file)
24
+ * [Customizing Nodoku page appearance](#customizing-nodoku-page-appearance)
25
+ * [Nodoku generation scripts](#nodoku-generation-scripts)
26
+ <!-- TOC -->
27
+
28
+ GitHub link: https://github.com/nodoku/nodoku-core
29
+
30
+ Nodoku is a static site generator, where the content is provided via MD (markdown) files, and the visual representation is controlled using Yaml files - called _skin_.
31
+
32
+ Nodoku promotes the content-first approach, when the content creation process is not being distracted by the considerations related to the visual representation and design.
33
+
34
+ Instead, the content is created first as an MD file, demarcated by the special markers into content blocks, and then each block is rendered using the configuration provided in a Yaml file called _skin_.
35
+
36
+ Figure 1 shows a screenshot of a part of a landing page created with Nodoku.
37
+
38
+ <figure>
39
+ <img
40
+ src="./docs/nodoku-way-card-screenshot.png"
41
+ alt="Nodoku landing page part with 3 cards"
42
+ title="Nodoku landing page part with 3 cards"
43
+ />
44
+ <figcaption>
45
+ <b>Figure 1</b>: A part of a landing page, created using Nodoku.
46
+ It has 3 cards, organized in a row, where the content of each card is supplied by an MD file. The mapping between content and visual representation is configured in a Yaml file.
47
+ </figcaption>
48
+ </figure>
49
+
50
+
51
+
52
+ Nodoku is a set of libraries, the most important of which is nodoku-core, intended to be used with the **_NextJS_** framework for generation of static sites.
53
+
54
+ Nodoku is intended to be used in server side rendering, it is not suitable for client side.
55
+
56
+ nodoku-core doesn't contain the visual representation for content blocks. Instead, the visual representation is supplied via separated dependencies, such as **_nodoku-flowbite_** (components based on [Flowbite](https://flowbite.com/docs/getting-started/introduction/)) and **_nodoku-mambaui_** (components based on [MambaUI](https://mambaui.com/components/hero)).
57
+
58
+ More set of components can be added, and included in the project as required.
59
+
60
+ The structure of the skin files is organized by rows, each row having one or more components.
61
+
62
+ The mapping between visual representation and the content block is performed using the concept of _selector_. Selector is a set of matching conditions, attached to a visual component in the skin Yaml file.
63
+
64
+ The actual rendering is performed in two steps:
65
+ - first, for a given visual component a set of matching content blocks is determined, using the selector and the meta-data of the content block
66
+
67
+
68
+ - second, this flow of content blocks is provided to the rendering mechanism of the visual component for actual rendering.
69
+
70
+ This decoupling allows for great level of flexibility and reuse between the content and the visual representation.
71
+
72
+ If the visual components support [Tailwind](https://tailwindcss.com/docs/installation), the Tailwind customization can be provided in the skin Yaml file to fine tune the visual representation.
73
+
74
+ You can learn more about the rationale behind Nodoku and the main principles in the blog article: [Nodoku: a lo-code static site generator, promoting a content-first approach based on Markdown files](https://epanikas.hashnode.dev/nodoku-a-lo-code-static-site-generator-promoting-a-content-first-approach-based-on-markdown-files)
75
+
76
+ # Nodoku foundation
77
+
78
+ Nodoku is organized around two flows of data:
79
+ - the content flow (supplied via a Markdown file)
80
+ - the visual representation flow (supplied via Yaml file called _skin_)
81
+
82
+ The Nodoku engine will take care of parsing these files and supply them to the designated visual components for rendering.
83
+
84
+ ## Nodoku content flow
85
+
86
+ As has been mentioned above, the Nodoku content flow is supplied via an MD file.
87
+
88
+ The content flow in Nodoku is organized around an entity called _content block_, which is a single piece of content suitable for rendering by a Nodoku visual component. The set of such components constitute the Nodoku content flow.
89
+
90
+ The content block has a predefined structure. It is designed to be more or less generic, and _visual representation agnostic_. In particular this is important to implement the _content-first_ principle, where the content can (and should!) be created first, without any visual design considerations.
91
+
92
+ Nodoku engine parses the MD file to extract the set of content blocks, that are contained in such file. The content blocks are delimited by a special markers - the content block delimiters.
93
+
94
+ The content block delimiter is a small piece of Yaml code snippet, embedded directly into the MD file.
95
+
96
+ For example, the content, that has been used to generate the screeshnot on Figure 1 is the following:
97
+
98
+ ```markdown
99
+
100
+ ```yaml
101
+ nd-block:
102
+ attributes:
103
+ sectionName: nodoku-way
104
+ ``
105
+
106
+ # Step 1: _Think_
107
+ ## Create content promoting your product or service as an **MD file**
108
+ ...
109
+ Concentrate on the subject of your product / service to highlight its advantages.
110
+ ...
111
+ |Get started|
112
+
113
+ # Step 2: _Skin_
114
+ ## Skin the MD file using simple **Yaml config** and available components
115
+ ...
116
+ Once you are happy with the message your landing page conveys,
117
+ start by skinning it up.
118
+ ...
119
+ |Get started|
120
+
121
+ # Step 3: _Fine tune_
122
+ ## Use configuration options to fine tune your landing page presentation
123
+ ...
124
+ If the default presentation doesn't suit your needs, you can tweak it up
125
+ using the config options of each component to fine tune it for your needs.
126
+ ...
127
+ |Get started|
128
+
129
+ ```
130
+
131
+ The first thing one would notice in this MD excerpt is the small Yaml code snippet.
132
+
133
+ ```yaml
134
+ nd-block:
135
+ attributes:
136
+ sectionName: nodoku-way
137
+ ```
138
+
139
+ This Yaml code snippet is a content block delimiter, and it contains the content block meta-data, such as _id_, _attributes_ and _tags_.
140
+
141
+ The schema for this Yaml code snippet can be found in the Json schema file : **_nodoku-core/schemas/md-content-block-delimiter.json_**
142
+
143
+ The content block has the following predefined, fixed structure:
144
+ ```typescript
145
+ class NdContentBlock {
146
+ // content block meta-data
147
+ id: string;
148
+ lng: string;
149
+ attributes: {key: string, value: string}[] = [];
150
+ tags: string[] = []
151
+ namespace: string;
152
+
153
+ // the actual textual content
154
+ title?: NdTranslatedText; // a title
155
+ subTitle?: NdTranslatedText; // a subtitle
156
+ h3?: NdTranslatedText; // h3 header
157
+ h4?: NdTranslatedText; // h4 header
158
+ h5?: NdTranslatedText; // h5 header
159
+ h6?: NdTranslatedText; // h6 header
160
+ footer?: NdTranslatedText; // footer
161
+ paragraphs: NdTranslatedText[]; // set of paragraphs
162
+ bgImageUrl?: NdTranslatedText; // background image
163
+ images: NdContentImage[] = []; // set of images
164
+ }
165
+ ```
166
+ where _NdTranslatedText_ represents a piece of text, that can be used for i18next translation (see below)
167
+ ```typescript
168
+ class NdTranslatedText {
169
+ key: string; // the translation key
170
+ ns: string; // the translation namespace
171
+ text: string; // the fallback text, extracted from content
172
+ }
173
+ ```
174
+
175
+ As one can see, the content block _cannot_ contain more than instance of each type of headers: title (h1), subtitle (h2), h3, etc.
176
+
177
+ But it _can_ contain several headers of different types, for example, a title (h1) and subtitle (h2)
178
+
179
+ > Hence, the parsing of the MD file goes as follows:
180
+ > - if the Yaml nd-block is encountered, a new content block is started, which would absord all the content elements that are discovered below, until a new content block is started
181
+ > - if a header (of any kind) is encountered
182
+ > - if a header of the same kind or below exists in the current block
183
+ > - finalize the current block
184
+ > - start a new block
185
+ > - and copy the metadata from the current block to the new one
186
+ > - otherwise
187
+ > - add the corresponding header to the current block
188
+
189
+ This approach allows for smooth content definition, where a common content block metadata is defined only once, and all the subsequent pieces of content are treated as new blocks with the same metadata.
190
+
191
+ Thanks to this parsing approach, the excerpt of the MD file, shown above, defines 3 content blocks - one per card shown on the screenshot of Figure 1 - instead of only one.
192
+
193
+
194
+ ## Nodoku skin
195
+
196
+ Nodoku skin is a Yaml file which configures the visual representation of the content defined in a markdown file.
197
+
198
+ The Nodoku page layout is organized as a set of rows, each row having its configured set of components.
199
+
200
+ Each layout row can have one or more visual components.
201
+
202
+ Here is an example of a typical Nodoku skin file:
203
+
204
+ ```yaml
205
+ rows:
206
+ - row:
207
+ components:
208
+ - mambaui/card:
209
+ selector:
210
+ attributes:
211
+ sectionName: nodoku-way
212
+ ```
213
+
214
+ In this example, we define a row containing components of type _mambaui/card_
215
+
216
+ The selector defines the content blocks that should be rendered using this visual component. In our case, these are all the content blocks having an attribute `sectionName` equal to `nodoku-way`.
217
+
218
+ Recall, that according to our MD file we are actually having 3 content blocks matching this criteria:
219
+ - Step 1: _Think_
220
+ - Step 2: _Skin_
221
+ - Step 3: _Fine tune_
222
+
223
+ Naturally, a single card component cannot display more than one content block.
224
+
225
+ Consequently, according to the skin Yaml file, the Nodoku engine will apply the same visual component definition to all the three matching content blocks.
226
+
227
+ And this process will end up rendering the screenshot presented on Figure 1.
228
+
229
+ It's worth noting that a visual component can support arbitrary number of content blocks. For example, the _flowbite/carousel_ component can display any number of content blocks.
230
+
231
+ Consequently, if the skin Yaml file had the following configuration:
232
+ ```yaml
233
+ rows:
234
+ - row:
235
+ components:
236
+ - flowbite/carousel:
237
+ selector:
238
+ attributes:
239
+ sectionName: nodoku-way
240
+ ```
241
+
242
+ it would have had the following visual rendering:
243
+
244
+ <figure>
245
+ <img
246
+ src="./docs/nodoku-way-carousel-screenshot.png"
247
+ alt="Nodoku landing page part with carousel"
248
+ title="Nodoku landing page part with carousel"
249
+ />
250
+ <figcaption>
251
+ <b>Figure 2</b>: Three content blocks, rendered as the carousel component.
252
+ </figcaption>
253
+ </figure>
254
+
255
+
256
+
257
+ # Getting started
258
+
259
+ ## Prerequisites
260
+
261
+ As has been mentioned above, Nodoku is a library intended to be used within the NextJS framework. The creation of a NextJS project is out of scope for the current documentation.
262
+
263
+ We assume that the user is already familiar with the following concepts:
264
+ - **_NextJS_**:
265
+ - Nodoku is written to be used in server side rendering in NextJS
266
+ - **_Typescript_**:
267
+ - Nodoku is written using Typescript (5.x), it uses the ECMAScript Modules (ESM) as module standard. It doesn't ship as CommonJS or UMD modules.
268
+ - **_Tailwind CSS_**:
269
+ - Nodoku heavily relies on Tailwind for visual appearance. All the Nodoku components are using Tailwind for their default visual configuration. And Tailwind can be used for skin customization.
270
+ - **_React and JSX_**:
271
+ - you need a basic knowledge of React and JSX as all the Nodoku visual compnents are async functions returning JSX (see the declaration of _AsyncFunctionComponent_).
272
+ - **_Webpack config_**:
273
+ - when using Nodoku with flowbite (see [nodoku-flowbite](https://github.com/nodoku/nodoku-flowbite)) it might be required to modify the default Webpack configuration to make sure only one instance of flowbite is used
274
+
275
+ ## Installation
276
+ In order to use Nodoku one needs to install the **_nodoku-core_** library (this one) and at least one component library for Nodoku (for example, nodoku-flowbite)
277
+
278
+
279
+ ```shell
280
+ npm install nodoku-core nodoku-flowbite
281
+ ```
282
+
283
+ ## Integrating Nodoku into a project
284
+
285
+ The entry point of a Nodoku library is the **_RenderingPage_** component.
286
+
287
+ This component receives as properties the flow of content blocks and the skin, and renders accordingly.
288
+
289
+ Here is a typical example of the usage of the RenderingPage TSX component:
290
+
291
+ ```tsx
292
+
293
+ // load and parse the content MD file
294
+ const content: NdContentBlock[] = await contentMarkdownProvider("<url location of the content file>.md", "en", "nodoku-landing")
295
+
296
+ // load the Yaml skin file
297
+ const skin: NdPageSkin = await skinYamlProvider("<url location of the skin file>.yaml")
298
+
299
+ ...
300
+
301
+ <RenderingPage
302
+ lng={lng}
303
+ renderingPriority={RenderingPriority.skin_first}
304
+ skin={skin}
305
+ content={content}
306
+ componentResolver={defaultComponentResolver}
307
+ />
308
+ ```
309
+
310
+ ### Loding and parsing of the content MD file
311
+
312
+ First, we parse the content MD file, using the predefined function _contentMarkdownProvider_.
313
+
314
+ The implementation of this function is intentionally kept simple, so that it can easily be replaced by a custom provider, if for some reason the standard one cannot be used.
315
+
316
+ ```ts
317
+ async function contentMarkdownProvider(
318
+ mdFileUrl: string,
319
+ contentLng: string,
320
+ ns: string): Promise<NdContentBlock[]> {
321
+
322
+ return await fetch(mdFileUrl)
323
+ .then(response => response.text())
324
+ .then(fileContent => {
325
+ return parseMarkdownAsContent(fileContent, contentLng, ns)
326
+ })
327
+ }
328
+ ```
329
+
330
+ The real parsing happens in the function _parseMarkdownAsContent_, which can also be used directly, if for some reason the URL of the MD file is not available.
331
+
332
+ The result of this phase is the set of content blocks, represented as an array of _NdContentBlock_ items.
333
+
334
+ Each content block that is extracted from the content MD file has an id - called **_blcokId_**.
335
+
336
+ The content block id is an important concept as it serves as a prefix for the translation keys, generated for that content block.
337
+
338
+ The Nodoku content blocks are made available for translation and localization out of the box.
339
+
340
+ Hence, the unique translation keys given for each piece of textual information is important.
341
+
342
+ The contenb blockId can
343
+ - either be provided directly as metadata in the delimiting Yaml code snippet
344
+ - or, if not explicitly provided, it is generated automatically, using the metadata available
345
+
346
+ #### Explicitly providing content blockId
347
+
348
+ The content blockId can be provided directly in the Yaml code snippet, delimiting the content blocks:
349
+
350
+ ```yaml
351
+ nd-block:
352
+ id: nodoku-way-think
353
+ ```
354
+
355
+ As this:
356
+
357
+ ```markdown
358
+ ```yaml
359
+ nd-block:
360
+ id: nodoku-way-think
361
+ attributes:
362
+ sectionName: nodoku-way
363
+ ``
364
+
365
+ # Step 1: _Think_
366
+ ## Create content promoting your product or service as an **MD file**
367
+
368
+ ```
369
+
370
+ This would generate the content block with blockId **_nodoku-way-think_**
371
+
372
+
373
+ and consequently the following translation keys will be generated for this block:
374
+ > - nodoku-way-think.title
375
+ > - nodoku-way-think.subTitle
376
+
377
+ #### Automatic generation of content blockId
378
+
379
+ It might be tedious to require the end user to explicitly provide a metadata, including blockId, for each and every content.
380
+
381
+ After all, Nodoku's philosophy is a _content first_ approach, where the textual content creation should be as seamless and straightforward, as possible.
382
+
383
+ Hence, Nodoku parser will generate the blockId automatically, if not provided, using the sequential index of the content block.
384
+
385
+
386
+ Consider this example:
387
+
388
+ ```markdown
389
+ ```yaml
390
+ nd-block:
391
+ attributes:
392
+ sectionName: nodoku-way
393
+ ``
394
+
395
+ # Step 1: _Think_
396
+ ## Create content promoting your product or service as an **MD file**
397
+ ```
398
+
399
+
400
+
401
+
402
+
403
+ ### Loading of the skin Yaml file
404
+
405
+ Likewise, there is a readily available parser for Yaml files, used as Nodoku skin. Recall, that _skin_ is a configuration for visual page rendering.
406
+
407
+ ```ts
408
+ async function skinYamlProvider(yamlFileUrl: string): Promise<NdPageSkin> {
409
+ return await fetch(yamlFileUrl)
410
+ .then(response => response.text())
411
+ .then(parseYamlContentAsSkin);
412
+ }
413
+ ```
414
+
415
+ If, for some reason, the standard implementation is not suitable for particular needs, one can easily replace this function by another one, using _parseYamlContentAsSkin_ as the actual parser.
416
+
417
+ The result of this parsing is an instance of _NdPageSkin_, which conveys the necessary information regarding the Nodoku skin.
418
+
419
+ ### Rendering Nodoku
420
+
421
+ Finally, when the skin and content are loaded, we can invoke the actual rendering using the provided component _RenderingPage_.
422
+
423
+ RenderingPage is an async JSX function, which is suitable for usage in the NextJS environment.
424
+
425
+ Let's have a closer look at its properties:
426
+
427
+ ```ts
428
+ class RenderingPageProps {
429
+ lng: string;
430
+ content: NdContentBlock[];
431
+ skin: NdPageSkin | undefined = undefined;
432
+ renderingPriority: RenderingPriority = RenderingPriority.content_first;
433
+ componentResolver: ComponentResolver | undefined = undefined;
434
+ imageUrlProvider: ImageUrlProvider | undefined = undefined;
435
+ i18nextProvider: I18nextProvider | undefined = undefined;
436
+ }
437
+ ```
438
+
439
+ - **_lng_**: the language in which the page should be rendered. Nodoku supports localization out of the box (see more on Nodoku localization in [nodoku-i18n](https://github.com/nodoku/nodoku-i18n))
440
+
441
+
442
+ - **_content_**: the content flow, represented as an array of NdContentBlock instances. The content blocks are usually parsed from a Markdown file using the provided parser _contentMarkdownProvider_.
443
+
444
+
445
+ - **_skin_**: an instance of NdPageSkin class representing the Nodoku skin - configuration of the visual representation of the page. It is usually loaded from a Yaml file using the supplied loader _skinYamlProvider_.
446
+
447
+
448
+ - **_renderingPriority_**: this parameter is an enum that can have two values:
449
+ - > **_content_first_**: the content is rendered as it appears in the markdown file, sequentially, block by block, from top to bottom. If a visual component is configured in the skin Yaml file, this visual component is used for rendering the content block. Otherwise, a default visual component is used
450
+ - > **_skin_first_**: the rendering is fully prescribed by the skin Yaml file. The components are rendered in the order they appear in the Yaml file
451
+ If a content block is not matched by any of the visual components in the skin Yaml file, it is not rendered at all. If a content block matches more than one visual component, each visual component is rendered, and the same content block will appear several times on the page.
452
+
453
+
454
+ - **_componentProvider_**: the function returning an actual implementation of the component, given its name, as specified in the skin. The signature is as follows:
455
+ > ```(componentName: string) => Promise<AsyncFunctionComponent>```
456
+ >
457
+ where AsyncFunctionComponent is the following function:
458
+ > ```(props: NdSkinComponentProps) => Promise<JSX.Element>```
459
+
460
+ the actual implementations, respecting the _AsyncFunctionComponent_ signature, are usually supplied via the component bundles, such as **_[nodoku-flowbite](https://github.com/nodoku/nodoku-flowbite)_** and **_[nodoku-mambaui](https://github.com/nodoku/nodoku-mambaui)_**
461
+
462
+
463
+ - **_imageUrlProvider_**: the function allowing to customize the image URL conversion for rendering. It may so happen that the URL of images appearing in the MD file are different from those appearing on the page. For example, we often use the relative notation for images in the MD file, whereas this is not suitable for page rendering. The conversion between URL's in the MD file, and the URL's on the page can be provided using this parameter. The default implementation strips the leading dots, thus naively converting a relative url to an absolute one. Like this (more sophisticated patterns can be implemented, if required):
464
+ > **_../images/my-image-123.png_** will be converted to **_/images/my-image-123.png_**
465
+
466
+
467
+ - **_i18nextProvider_**: this parameter can be used to provide the localization mechanism for Nodoku. This function is supposed to return an object containing the **_t()_** function, which will further be used for translating the text.
468
+ > type I18nextProvider = (lng: string) => Promise<{t: (text: NdTranslatedText) => string}>
469
+
470
+ Note, that the provided **_t()_** function takes as an argument the whole NdTranslatedText structure, which contains the translation namespace, the key and the default value, extracted from the content.
471
+
472
+ This parameter is optional. If not provided, the text from the content MD file is used.
473
+
474
+
475
+
476
+ For more details see [nodoku-i18n](https://github.com/nodoku/nodoku-i18n)
477
+
478
+ ### Nodoku component resolver
479
+
480
+ The component resolver is expected to resolve each component name in a textual form, as extract from the skin file, to an actual component definition, among other things containing the actual Javascript function that should be called to render the component.
481
+
482
+ > As the components are provided as external dependencies, Nodoku supplies a special script - **_nodoku-gen-component-resolver_** - that should be launched from command line to automatically generate the component resolver.
483
+
484
+ Here is the typical example of the generated component resolver, that is crucial for successful functioning of Nodoku:
485
+
486
+ ```ts
487
+
488
+ import {AsyncFunctionComponent, DummyComp, NdComponentDefinition} from "nodoku-core";
489
+
490
+ import { NodokuFlowbite } from "nodoku-flowbite";
491
+
492
+ const components: Map<string, {compo: AsyncFunctionComponent, compoDef: NdComponentDefinition}> =
493
+ new Map<string, {compo: AsyncFunctionComponent, compoDef: NdComponentDefinition}>();
494
+
495
+ components.set("flowbite/card", {
496
+ compo: NodokuFlowbite.Card,
497
+ compoDef: new NdComponentDefinition(1,
498
+ "./schemas/nodoku-flowbite/dist/schemas/components/card/default-theme.yml")
499
+ });
500
+
501
+ // other component definitions go here
502
+
503
+ export function nodokuComponentResolver(componentName: string): Promise<{compo: AsyncFunctionComponent, compoDef: NdComponentDefinition}> {
504
+ const f: {compo: AsyncFunctionComponent, compoDef: NdComponentDefinition} | undefined =
505
+ components.get(componentName);
506
+ return Promise.resolve(f ? f : {compo: DummyComp, compoDef: new NdComponentDefinition(1)});
507
+ }
508
+
509
+ ```
510
+
511
+ Recall that the _componentResolver_ is one of the properties of the _RenderingPage_ component.
512
+
513
+ Thanks to this function Nodoku can find the correspondence between the component name specified in the skin Yaml file, and the actual component implementation.
514
+
515
+ It is worth noting here that **_nodoku-core_** is the Nodoku engine, which contains the resolving and parsing functionality, but it contains no visual components.
516
+
517
+ The visual components are supposed to be supplied as external library dependency, such as _nodoku-flowbite_ and _nodoku-mambaui_.
518
+
519
+ The static map, that is generated by the scirpt _nodoku-gen-component-resolver_, associates with each component name two attributes:
520
+ - **_compo_**: the function that is to be called to render the component
521
+ - **_compoDef_**: the definition of the component. The component defintion is loaded from the Nodoku manifest, supplied in the bundle where this component is defined. The component definition includes the following fields:
522
+ - **_numBlocks_**: the maximum number of blocks this component supports
523
+ - **_defaultThemeYaml_**: the Yaml file defining the default component visual configuration (usually uses Tailwind class names)
524
+
525
+ These components parameters are defined in a special file - **_nodoku.manifest.json_** - which is supposed to be shipped within the component bundle. See below for more details.
526
+
527
+ ## Configuring Nodoku project
528
+
529
+ ### Tailwind configuration
530
+
531
+ Since Nodoku is heavily relying on Tailwind, the Nodoku project is supposed to be configured accordingly. Otherwise, the Tailwind classes won't be parsed, and the page would not be rendered correctly.
532
+
533
+ To understand how to configure Tailwind we first need to understand how Tailwind functions.
534
+
535
+ Tailwind is a set of predefined CSS classes, each having its own responsibility and value.
536
+
537
+ For example, ```mt-10``` results in the following CSS being genrated by Tailwind:
538
+
539
+ ```css
540
+ .mt-10 {
541
+ margin-top: 2.5rem;
542
+ }
543
+ ```
544
+ Since there are a lot of those Tailwind classes, not all of them are included in the final bindle, but only those that are actually used in the project.
545
+
546
+ Hence, Tailwind needs to know what files to parse to look for actual Tailwind classes that are being used. Only the CSS classes discovered during this parsing, will be included in the final bundle.
547
+
548
+ In order for Nodoku to function properly, one needs to include all the places where potentially Tailwind classes can be encountered.
549
+
550
+ Here is the typical **_tailwind.config.ts_**
551
+
552
+ ```ts
553
+ import flowbite from "flowbite-react/tailwind";
554
+ import type {Config} from "tailwindcss";
555
+ import * as typo from '@tailwindcss/typography';
556
+
557
+
558
+ const config: Config = {
559
+ content: [
560
+ "./src/**/*.ts",
561
+ "./src/**/*.tsx",
562
+ "./src/**/*.js",
563
+ "./src/**/*.jsx",
564
+
565
+ "./node_modules/nodoku-core/dist/esm/**/*.js",
566
+ "./node_modules/nodoku-core/dist/esm/**/*.jsx",
567
+ "./node_modules/nodoku-components/dist/esm/**/*.js",
568
+ "./node_modules/nodoku-components/dist/esm/**/*.jsx",
569
+ "./node_modules/nodoku-flowbite/dist/esm/**/*.js",
570
+ "./node_modules/nodoku-flowbite/dist/esm/**/*.jsx",
571
+ "./node_modules/nodoku-flowbite/dist/schemas/**/*.yml",
572
+ "./node_modules/nodoku-mambaui/dist/esm/**/*.js",
573
+ "./node_modules/nodoku-mambaui/dist/esm/**/*.jsx",
574
+ "./node_modules/nodoku-mambaui/dist/schemas/**/*.yml",
575
+ "./public/**/*.html",
576
+ "./src/**/*.{html,js}",
577
+ "./public/site/**/*.yaml",
578
+ flowbite.content(),
579
+ ],
580
+
581
+ theme: {
582
+ extend: {
583
+ aspectRatio: {
584
+ 'carousel': '4 / 1.61',
585
+ },
586
+ typography: {
587
+ DEFAULT: {
588
+ css: {
589
+ maxWidth: 'unset',
590
+ }
591
+ }
592
+ }
593
+ },
594
+ },
595
+ plugins: [
596
+ flowbite.plugin(),
597
+ typo.default(),
598
+ ],
599
+ };
600
+
601
+ export default config;
602
+
603
+ ```
604
+
605
+ Let's have a closer look at this configuration:
606
+
607
+ - **_content_**: should contain all the paths where Tailwind classes are located, and consequently will be parsed by Tailwind for class extraction.
608
+ - for each Nodoku component bundle it should contain the all the ```.js```, ```.jsx``` and ```.yml``` files, because it might contain the Tailwind classes
609
+ - if a component bundle using _flowbite-react_ is used (such as _nodoku-flowbite_), its plugin should be included in the content
610
+ - **_theme_**: this is a standard Tailwind's theme definition. For example, in this example we are defining a new aspectRation value called ```carousel```, which later can be used for styling Nodoku components
611
+ - **_plugins_**: this section includes plugins needed for Nodoku components to work properly
612
+ - **_flowbite.plugin()_** - if components based on flowbite-react are used, this plugin should be included
613
+ - **_typo.default()_** - if the [Nodoku Typography](https://github.com/nodoku/nodoku-components) plugin is used, this plugin should be included
614
+
615
+ For more details on Tailwind config see the section "[Configuring Tailwind](https://github.com/nodoku/nodoku-flowbite?tab=readme-ov-file#configuring-tailwind)" in one of the Nodoku component bundles - [nodoku-flowbite](https://github.com/nodoku/nodoku-flowbite).
616
+
617
+ ### Webpack configuration
618
+
619
+ It might so happen that we'll need to configure the Webpack in order for Nodoku to run properly.
620
+
621
+ In particular this problem becomes apparent if we are using flowbite-react, in order to ensure that only instance of flowbite-react is included in the final bundle.
622
+
623
+ Otherwise, the flowbite-react theme might not work properly, and all the customizations of this theme will not be applied.
624
+
625
+ Webpack configuration in a NextJS project is not trivial, as we don't have access directly to the file webpack.config.js.
626
+
627
+ Instead, we should be redefining the **_nextConfig_** in _next.config.mjs_ as follows:
628
+
629
+ ```js
630
+ import path from "node:path";
631
+
632
+ const nextConfig = (phase, {defaultConfig}) => {
633
+ /**
634
+ * @type {import('next').NextConfig}
635
+ */
636
+ const nextConfig = {
637
+ /* config options here */
638
+ ...defaultConfig,
639
+ webpack: ((config, opts) => {
640
+ config.resolve.alias["flowbite-react"] = path.resolve('./node_modules/flowbite-react');
641
+ config.resolve.alias["flowbite"] = path.resolve('./node_modules/flowbite');
642
+ return config;
643
+ })
644
+ }
645
+
646
+ return nextConfig
647
+ }
648
+
649
+ export default nextConfig;
650
+ ```
651
+
652
+ Note that we pin down the resolution of _flowbite_ and _flowbite-react_ to the particular dependencies in our _node_modules_ folder.
653
+
654
+ # Nodoku component bundle
655
+
656
+ As has already been mentioned above, Nodoku visual components are supplied as a component bundle - a standard NPM dependency, that can be installed using the standard NPM installation process
657
+ > ```npm install <nodoku component bundle>```
658
+
659
+ for example:
660
+ > ```npm install nodoku-flowbite```
661
+
662
+ ## Nodoku manifest
663
+
664
+ Each component bundle should be shipped with a special file called **_nodoku.manifest.json_**.
665
+
666
+ This json file is a visit card of the component bundle: it contains all the information required for Nodoku engine to treat correctly the component and use it following the configuration in the Nodoku skin Yaml file.
667
+
668
+ Here is an excerpt from such file for nodoku-flowbite:
669
+
670
+ ```json
671
+ {
672
+ "namespace": "NodokuFlowbite",
673
+ "components": {
674
+ ..
675
+ "flowbite/carousel": {
676
+ "schemaFile": "./dist/schemas/components/carousel/visual-schema.json",
677
+ "optionsFile": "./dist/schemas/components/carousel/options-schema.json",
678
+ "defaultThemeFile": "./dist/schemas/components/carousel/default-theme.yml",
679
+ "implementation": "Carousel",
680
+ "numBlocks": "unlimited"
681
+ },
682
+ ...
683
+ }
684
+ }
685
+ ```
686
+
687
+ Let's have a closer look at the attributes of each Nodoku visual component:
688
+
689
+ - **_namespace_**: the Javascript namespace where out of which the component is being exported.
690
+
691
+ The presence of the namespace attribute instructs the generator of the component resolver (nodoku-gen-component-resolver) to insert the component definition prefixed with the namespace.
692
+ ```ts
693
+ import { NodokuFlowbite } from "nodoku-flowbite";
694
+ components.set("flowbite/carousel", {compo: NodokuFlowbite.Carousel, ...});
695
+ ```
696
+ The Nodoku manifest cannot have more than one namespace.
697
+
698
+
699
+ - **_components_**: is a object associating a textual component name with the data structure that is used to extract the component definition. This data structure include:
700
+
701
+
702
+ - **_schemaFile_**: is a Json schema file representing the data structure of the visual theme of the component (see [Schema for Nodoku skin Yaml file](#schema-for-nodoku-skin-yaml-file))
703
+
704
+
705
+ - **_optionsFile_**: is a Json schema file representing the data structure of the functional options of the component (see [Schema for Nodoku skin Yaml file](#schema-for-nodoku-skin-yaml-file))
706
+
707
+
708
+ - **_defaultThemeFile_**: a Yaml file containing the default Tailwind configuration of the component
709
+
710
+
711
+ - **_implementation_**: the actual Javascript function rendering this compnent. (the signature should correspond to _AsyncFunctionComponent_)
712
+
713
+
714
+ - **_numBlocks_**: number of content blocks this component can accept for rendering. This parameter can either be a positive number of the predefined value '_unlimited_'
715
+
716
+
717
+
718
+ The _numBlocks_ parameter is used by the Nodoku engine to calculate the correct number of content blocks this visual component is capable of rendering. This parameter is normally either **_1_** or **_'unlimited'_**.
719
+
720
+ The _defaultThemeYaml_ attribute is an important parameter designating the Yaml file where the default Tailwind configuration is located. Normally each Nodoku visual component comes as an empty JSX scaffolding, which delegates the styling - the actual Tailwind classes - to the external data structure, the component default theme.
721
+
722
+ # Nodoku skin
723
+
724
+
725
+ The Nodoku skin is a Yaml file which configures the Nodoku rendering.
726
+
727
+ Recall, that in Nodoku there is a strict separation between the content and the visual representation.
728
+
729
+ The content is provided via an MD file, whereas the mapping between the content blocks and visual components are defined in the _skin_.
730
+
731
+ The skin also defines the necessary customizations and fine-tuning of the page visual representation, if required.
732
+
733
+ ## Nodoku visual component theme
734
+
735
+ Normally, each JSX block in a visual component is styled using the Tailwind class names. This styling is typically composed of two parts: _base_ and _decoration_.
736
+
737
+ Consider the following example:
738
+
739
+ ```tsx
740
+ <h3 className={`${effectiveTheme.titleStyle?.base} ${effectiveTheme.titleStyle?.decoration}`}>
741
+ {t(block.title)}
742
+ </h3>
743
+
744
+ <h4 className={`${effectiveTheme.subTitleStyle?.base} ${effectiveTheme.subTitleStyle?.decoration}`}>
745
+ {t(block.subTitle)}
746
+ </h4>
747
+ ```
748
+
749
+ The component theme is supplied to the component by the Nodoku engine, and comes in as a data structure containing two elements:
750
+ - one for title styling _effectiveTheme.**titleStyle**_
751
+ - and one for subtitle styling _effectiveTheme.**subTitleStyle**_
752
+
753
+ Each such element is called _ThemeStyle_, and is composed of two string attributes: _base_ and _decoration_
754
+
755
+ The component theme consists of several attributes of type _ThemeStyle_.
756
+
757
+ Here is an excerpt from the component theme _flowbite/card_
758
+
759
+ ```ts
760
+ export class CardTheme {
761
+ ...
762
+ titleStyle?: ThemeStyle;
763
+ subTitleStyle?: ThemeStyle;
764
+ ...
765
+ }
766
+ ```
767
+ where ThemeStyle is defined as follows:
768
+ ```ts
769
+ export class ThemeStyle {
770
+ base: string;
771
+ decoration: string;
772
+ }
773
+ ```
774
+
775
+ For each component there is a default theme supplied in a Yaml file, and this file is defined for the given visual component in the Nodoku manifest.
776
+
777
+ In addition, the theme of each component can further be customized in the skin Yaml file.
778
+
779
+
780
+ # The Nodoku skin Yaml file
781
+
782
+
783
+
784
+
785
+ The skin Yaml file has a predefined structure, which can be summarized as follows:
786
+
787
+ ```yaml
788
+ global:
789
+ renderingPage:
790
+ # styles applied to the whole page
791
+ theme:
792
+ # attributes defined on the global level for all the component themes
793
+ themes:
794
+ # contains the list of theme customizations, where each theme from the list is applied sequentially on each content block rendered by the component of a given type in a single row
795
+ components:
796
+ <component-name>:
797
+ theme:
798
+ # defines a theme customization for a particular component
799
+ themes:
800
+ # defines a list of theme customizations for a particular component, where each theme from the list is applied sequentially on each content block rendered by the component of this type in a single row
801
+
802
+ rows:
803
+ # list of rows
804
+ - row:
805
+ theme:
806
+ # styling classes applied on the row level
807
+ maxCols:
808
+ # optional: a limit on a number of visual components in a row. By default, the max number of elements in a row is 12 (grid-cols-12 from Tailwind) but it can be reduced to 1, when we need content blocks to be located one beneat the other
809
+ components:
810
+ <component-name>:
811
+ selector:
812
+ # the data structure defining the selector to be applied on content blocks to select the matching content blocks that would be rendered by this component
813
+ options:
814
+ # a component may accept an options object, which can be defined here
815
+ theme:
816
+ # the customization of the component's scheme
817
+ themes:
818
+ # a list of theme customizations for the given component, where each theme from the list is applied sequentially on each content block rendered by the component of this type in a single row
819
+ ```
820
+
821
+ The customization is applied progressively, from the least specific theme to the most specific, starting from the default theme of the component.
822
+
823
+ Since the Nodoku skin file is large, and can contain many customization options, it is desirable to have a schema file that would guide the user through the process of defining and editing of the skin.
824
+
825
+ ## Schema for Nodoku skin Yaml file
826
+
827
+ In order to make the Nodoku skin creation process more convenient and predictable, Nodoku provides a possibility to create a schema file for a project, with a given set of Nodoku component bundles, defined in NPM dependencies (in package.json).
828
+
829
+ Similar to the generation script for Nodoku component resolver, there is a script for generation of the Nodoku skin schema: **_nodoku-gen-skin-schema_**
830
+
831
+ One can run this script to automatically generate a Nodoku skin schema file.
832
+
833
+ The schema file by default is generated in the folder
834
+ > <project folder>/schemas
835
+
836
+ After the schema generation script completes, the **_./schemas_** folder should look as follows:
837
+
838
+ <figure>
839
+ <img
840
+ src="./docs/schemas-folder-expanded.png"
841
+ alt="project schemas folder after schema generation"
842
+ title="project schemas folder after schema generation"
843
+ />
844
+ <figcaption>
845
+ <b>Figure 3</b>: The <b>./schemas</b> folder contains the schema file - <b>visual-schema.json</b> - to be applied on the Nodoku skin Yaml file
846
+ </figcaption>
847
+ </figure>
848
+
849
+ The generated schema file - ./schemas/visual-schema.json - can be applied to the skin Yaml file in several ways:
850
+ - use [the IDE mechanism of schema application](https://www.jetbrains.com/help/idea/yaml.html#json_schema)
851
+ - use the **_yaml-language-server_** header (the first row) for the Yaml file as follows:
852
+
853
+ ```yaml
854
+ # yaml-language-server: $schema=../../../schemas/visual-schema.json
855
+
856
+ global:
857
+ renderingPage:
858
+ base: dark:text-gray-200 text-gray-700
859
+
860
+ rows:
861
+ - row:
862
+ theme:
863
+ decoration: mb-10
864
+
865
+ ```
866
+
867
+ ## Customizing Nodoku page appearance
868
+
869
+ The main principle of component customization in Nodoku consists of cascading application of themes, defined on different levels:
870
+ - **_global level_**: the section **_global_** in the Yaml file. This level can further be divided to
871
+ - **_theme level_**: where any attribute for any component can be defined
872
+ - **_component level_**: where attributes for a given component can be defined
873
+ - **_rows level_**: where the list of rows defines each its set of components
874
+ - **_component in a row level_**: the most specific customization, where a particular component can be customized
875
+
876
+ The process of customization starts from the component's default theme and works its way through all the defined customizations, until the most specific level is reached.
877
+
878
+
879
+
880
+
881
+ # Nodoku generation scripts
882
+
883
+ The nodoku-core provides the following scripts, that are used to generate component resolver and visual schema, by scanning the **node_modules** folder of the project
884
+
885
+
886
+ - **nodoku-gen-component-resolver**: generates the component resolver by scanning node_modules and searching for nodoku component libraries - the libraries providing the nodoku.manifest.json file. For more details see [Nodoku component resolver](#nodoku-component-resolver)
887
+
888
+
889
+ - **nodoku-gen-visual-schema**: generates the json schema file thate can be used to validate the Nodoku skin schema file. For more details see [Schema for Nodoku skin Yaml file](#schema-for-nodoku-skin-yaml-file)
890
+
891
+ To simplify the use of these script it is recommended to add them in the project's package.json file as follows:
892
+
893
+ ```json
894
+ {
895
+ ...
896
+ "scripts": {
897
+ "gen-component-resolver": "nodoku-gen-component-resolver",
898
+ "gen-skin-schema": "nodoku-gen-skin-schema"
899
+ },
900
+ ...
901
+ }
902
+ ```
903
+
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodoku-core",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "basic foundation for nodoku static site generator",
5
5
  "exports": {
6
6
  ".": {