nodoku-core 0.1.1 → 0.1.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.
- package/README.md +697 -0
- package/dist/esm/bin/generate-component-default-theme.js +1 -0
- package/dist/esm/bin/generate-component-default-theme.js.map +1 -0
- package/dist/esm/bin/generate-component-resolver.js +1 -0
- package/dist/esm/bin/generate-component-resolver.js.map +1 -0
- package/dist/esm/bin/generate-content-schema.js +1 -0
- package/dist/esm/bin/generate-content-schema.js.map +1 -0
- package/dist/esm/bin/generate-skin-schema.js +1 -0
- package/dist/esm/bin/generate-skin-schema.js.map +1 -0
- package/dist/esm/bin/import-load-hooks.js +1 -0
- package/dist/esm/bin/import-load-hooks.js.map +1 -0
- package/dist/esm/bin/manifest-loader.js +1 -0
- package/dist/esm/bin/manifest-loader.js.map +1 -0
- package/dist/esm/bin/manifest.js +1 -0
- package/dist/esm/bin/manifest.js.map +1 -0
- package/dist/esm/bin/mustache/component-resolver.ts.hbs +1 -1
- package/dist/esm/content/nd-content.js +1 -0
- package/dist/esm/content/nd-content.js.map +1 -0
- package/dist/esm/core/dummy-comp.jsx +1 -0
- package/dist/esm/core/dummy-comp.jsx.map +1 -0
- package/dist/esm/core/providers.js +1 -0
- package/dist/esm/core/providers.js.map +1 -0
- package/dist/esm/core/rendering-page-props.js +18 -5
- package/dist/esm/core/rendering-page-props.js.map +1 -0
- package/dist/esm/core/rendering-page.jsx +13 -35
- package/dist/esm/core/rendering-page.jsx.map +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/providers/content/content-markdown-provider.js +1 -0
- package/dist/esm/providers/content/content-markdown-provider.js.map +1 -0
- package/dist/esm/providers/skin/skin-yaml-provider.js +1 -0
- package/dist/esm/providers/skin/skin-yaml-provider.js.map +1 -0
- package/dist/esm/skin/nd-skin.js +1 -0
- package/dist/esm/skin/nd-skin.js.map +1 -0
- package/dist/esm/theme-utils/extended-theme-style.js +1 -0
- package/dist/esm/theme-utils/extended-theme-style.js.map +1 -0
- package/dist/esm/theme-utils/theme-merger.js +1 -0
- package/dist/esm/theme-utils/theme-merger.js.map +1 -0
- package/dist/esm/theme-utils/theme-style.js +1 -0
- package/dist/esm/theme-utils/theme-style.js.map +1 -0
- package/dist/types/core/providers.d.ts +1 -1
- package/dist/types/core/rendering-page-props.d.ts +4 -4
- package/package.json +1 -1
- package/README.MD +0 -46
package/README.md
ADDED
|
@@ -0,0 +1,697 @@
|
|
|
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
|
+
* [Content parsing](#content-parsing)
|
|
10
|
+
* [Loading of the skin Yaml file](#loading-of-the-skin-yaml-file)
|
|
11
|
+
* [Rendering Nodoku](#rendering-nodoku)
|
|
12
|
+
* [Nodoku component resolver](#nodoku-component-resolver)
|
|
13
|
+
* [Nodoku component bundle](#nodoku-component-bundle)
|
|
14
|
+
* [Nodoku manifest](#nodoku-manifest-)
|
|
15
|
+
* [Nodoku skin](#nodoku-skin-1)
|
|
16
|
+
* [Nodoku visual component theme](#nodoku-visual-component-theme)
|
|
17
|
+
* [The Nodoku skin Yaml file](#the-nodoku-skin-yaml-file)
|
|
18
|
+
* [Schema for Nodoku skin Yaml file](#schema-for-nodoku-skin-yaml-file)
|
|
19
|
+
* [Customizing Nodoku page appearance](#customizing-nodoku-page-appearance)
|
|
20
|
+
* [Nodoku generation scripts](#nodoku-generation-scripts)
|
|
21
|
+
<!-- TOC -->
|
|
22
|
+
|
|
23
|
+
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_.
|
|
24
|
+
|
|
25
|
+
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.
|
|
26
|
+
|
|
27
|
+
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_.
|
|
28
|
+
|
|
29
|
+
Figure 1 shows a screenshot of a part of a landing page created with Nodoku.
|
|
30
|
+
|
|
31
|
+
<figure>
|
|
32
|
+
<img
|
|
33
|
+
src="./docs/nodoku-way-card-screenshot.png"
|
|
34
|
+
alt="Nodoku landing page part with 3 cards"
|
|
35
|
+
title="Nodoku landing page part with 3 cards"
|
|
36
|
+
/>
|
|
37
|
+
<figcaption>
|
|
38
|
+
<b>Figure 1</b>: A part of a landing page, created using Nodoku.
|
|
39
|
+
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.
|
|
40
|
+
</figcaption>
|
|
41
|
+
</figure>
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
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.
|
|
46
|
+
|
|
47
|
+
Nodoku is intended to be used in server side rendering, it is not suitable for client side.
|
|
48
|
+
|
|
49
|
+
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)).
|
|
50
|
+
|
|
51
|
+
More set of components can be added, and included in the project as required.
|
|
52
|
+
|
|
53
|
+
The structure of the skin files is organized by rows, each row having one or more components.
|
|
54
|
+
|
|
55
|
+
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.
|
|
56
|
+
|
|
57
|
+
The actual rendering is performed in two steps:
|
|
58
|
+
- 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
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
- second, this flow of content blocks is provided to the rendering mechanism of the visual component for actual rendering.
|
|
62
|
+
|
|
63
|
+
This decoupling allows for great level of flexibility and reuse between the content and the visual representation.
|
|
64
|
+
|
|
65
|
+
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.
|
|
66
|
+
|
|
67
|
+
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)
|
|
68
|
+
|
|
69
|
+
# Nodoku foundation
|
|
70
|
+
|
|
71
|
+
Nodoku is organized around two flows of data:
|
|
72
|
+
- the content flow (supplied via a Markdown file)
|
|
73
|
+
- the visual representation flow (supplied via Yaml file called _skin_)
|
|
74
|
+
|
|
75
|
+
The Nodoku engine will take care of parsing these files and supply them to the designated visual components for rendering.
|
|
76
|
+
|
|
77
|
+
## Nodoku content flow
|
|
78
|
+
|
|
79
|
+
As has been mentioned above, the Nodoku content flow is supplied via an MD file.
|
|
80
|
+
|
|
81
|
+
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.
|
|
82
|
+
|
|
83
|
+
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.
|
|
84
|
+
|
|
85
|
+
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.
|
|
86
|
+
|
|
87
|
+
The content block delimiter is a small piece of Yaml code snippet, embedded directly into the MD file.
|
|
88
|
+
|
|
89
|
+
For example, the content, that has been used to generate the screeshnot on Figure 1 is the following:
|
|
90
|
+
|
|
91
|
+
```markdown
|
|
92
|
+
|
|
93
|
+
```yaml
|
|
94
|
+
nd-block:
|
|
95
|
+
attributes:
|
|
96
|
+
sectionName: nodoku-way
|
|
97
|
+
``
|
|
98
|
+
|
|
99
|
+
# Step 1: _Think_
|
|
100
|
+
## Create content promoting your product or service as an **MD file**
|
|
101
|
+
...
|
|
102
|
+
Concentrate on the subject of your product / service to highlight its advantages.
|
|
103
|
+
...
|
|
104
|
+
|Get started|
|
|
105
|
+
|
|
106
|
+
# Step 2: _Skin_
|
|
107
|
+
## Skin the MD file using simple **Yaml config** and available components
|
|
108
|
+
...
|
|
109
|
+
Once you are happy with the message your landing page conveys,
|
|
110
|
+
start by skinning it up.
|
|
111
|
+
...
|
|
112
|
+
|Get started|
|
|
113
|
+
|
|
114
|
+
# Step 3: _Fine tune_
|
|
115
|
+
## Use configuration options to fine tune your landing page presentation
|
|
116
|
+
...
|
|
117
|
+
If the default presentation doesn't suit your needs, you can tweak it up
|
|
118
|
+
using the config options of each component to fine tune it for your needs.
|
|
119
|
+
...
|
|
120
|
+
|Get started|
|
|
121
|
+
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
The first thing one would notice in this MD excerpt is the small Yaml code snippet.
|
|
125
|
+
|
|
126
|
+
```yaml
|
|
127
|
+
nd-block:
|
|
128
|
+
attributes:
|
|
129
|
+
sectionName: nodoku-way
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
This Yaml code snippet is a content block delimiter, and it contains the content block meta-data, such as _id_, _attributes_ and _tags_.
|
|
133
|
+
|
|
134
|
+
The schema for this Yaml code snippet can be found in the Json schema file : **_nodoku-core/docs/md-content-block-delimiter.json_**
|
|
135
|
+
|
|
136
|
+
The content block has the following predefined, fixed structure:
|
|
137
|
+
```typescript
|
|
138
|
+
class NdContentBlock {
|
|
139
|
+
// content block meta-data
|
|
140
|
+
id: string;
|
|
141
|
+
lng: string;
|
|
142
|
+
attributes: {key: string, value: string}[] = [];
|
|
143
|
+
tags: string[] = []
|
|
144
|
+
namespace: string;
|
|
145
|
+
|
|
146
|
+
// the actual textual content
|
|
147
|
+
title?: NdTranslatedText; // a title
|
|
148
|
+
subTitle?: NdTranslatedText; // a subtitle
|
|
149
|
+
h3?: NdTranslatedText; // h3 header
|
|
150
|
+
h4?: NdTranslatedText; // h4 header
|
|
151
|
+
h5?: NdTranslatedText; // h5 header
|
|
152
|
+
h6?: NdTranslatedText; // h6 header
|
|
153
|
+
footer?: NdTranslatedText; // footer
|
|
154
|
+
paragraphs: NdTranslatedText[]; // set of paragraphs
|
|
155
|
+
bgImageUrl?: NdTranslatedText; // background image
|
|
156
|
+
images: NdContentImage[] = []; // set of images
|
|
157
|
+
}
|
|
158
|
+
```
|
|
159
|
+
where _NdTranslatedText_ represents a piece of text, that can be used for i18next translation (see below)
|
|
160
|
+
```typescript
|
|
161
|
+
class NdTranslatedText {
|
|
162
|
+
key: string; // the translation key
|
|
163
|
+
ns: string; // the translation namespace
|
|
164
|
+
text: string; // the fallback text, extracted from content
|
|
165
|
+
}
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
As one can see, the content block _cannot_ contain more than instance of each type of headers: title (h1), subtitle (h2), h3, etc.
|
|
169
|
+
|
|
170
|
+
But it _can_ contain several headers of different types, for example, a title (h1) and subtitle (h2)
|
|
171
|
+
|
|
172
|
+
> Hence, the parsing of the MD file goes as follows:
|
|
173
|
+
> - 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
|
|
174
|
+
> - if a header (of any kind) is encountered
|
|
175
|
+
> - if a header of the same kind or below exists in the current block
|
|
176
|
+
> - finalize the current block
|
|
177
|
+
> - start a new block
|
|
178
|
+
> - and copy the metadata from the current block to the new one
|
|
179
|
+
> - otherwise
|
|
180
|
+
> - add the corresponding header to the current block
|
|
181
|
+
|
|
182
|
+
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.
|
|
183
|
+
|
|
184
|
+
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.
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
## Nodoku skin
|
|
188
|
+
|
|
189
|
+
Nodoku skin is a Yaml file which configures the visual representation of the content defined in a markdown file.
|
|
190
|
+
|
|
191
|
+
The Nodoku page layout is organized as a set of rows, each row having its configured set of components.
|
|
192
|
+
|
|
193
|
+
Each layout row can have one or more visual components.
|
|
194
|
+
|
|
195
|
+
Here is an example of a typical Nodoku skin file:
|
|
196
|
+
|
|
197
|
+
```yaml
|
|
198
|
+
rows:
|
|
199
|
+
- row:
|
|
200
|
+
components:
|
|
201
|
+
- mambaui/card:
|
|
202
|
+
selector:
|
|
203
|
+
attributes:
|
|
204
|
+
sectionName: nodoku-way
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
In this example, we define a row containing components of type _mambaui/card_
|
|
208
|
+
|
|
209
|
+
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`.
|
|
210
|
+
|
|
211
|
+
Recall, that according to our MD file we are actually having 3 content blocks matching this criteria:
|
|
212
|
+
- Step 1: _Think_
|
|
213
|
+
- Step 2: _Skin_
|
|
214
|
+
- Step 3: _Fine tune_
|
|
215
|
+
|
|
216
|
+
Naturally, a single card component cannot display more than one content block.
|
|
217
|
+
|
|
218
|
+
Consequently, according to the skin Yaml file, the Nodoku engine will apply the same visual component definition to all the three matching content blocks.
|
|
219
|
+
|
|
220
|
+
And this process will end up rendering the screenshot presented on Figure 1.
|
|
221
|
+
|
|
222
|
+
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.
|
|
223
|
+
|
|
224
|
+
Consequently, if the skin Yaml file had the following configuration:
|
|
225
|
+
```yaml
|
|
226
|
+
rows:
|
|
227
|
+
- row:
|
|
228
|
+
components:
|
|
229
|
+
- flowbite/carousel:
|
|
230
|
+
selector:
|
|
231
|
+
attributes:
|
|
232
|
+
sectionName: nodoku-way
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
it would have had the following visual rendering:
|
|
236
|
+
|
|
237
|
+
<figure>
|
|
238
|
+
<img
|
|
239
|
+
src="./docs/nodoku-way-carousel-screenshot.png"
|
|
240
|
+
alt="Nodoku landing page part with carousel"
|
|
241
|
+
title="Nodoku landing page part with carousel"
|
|
242
|
+
/>
|
|
243
|
+
<figcaption>
|
|
244
|
+
<b>Figure 2</b>: Three content blocks, rendered as the carousel component.
|
|
245
|
+
</figcaption>
|
|
246
|
+
</figure>
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
# Getting started
|
|
251
|
+
|
|
252
|
+
## Prerequisites
|
|
253
|
+
|
|
254
|
+
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.
|
|
255
|
+
|
|
256
|
+
We assume that the user is already familiar with the following concepts:
|
|
257
|
+
- **_NextJS_**:
|
|
258
|
+
- Nodoku is written to be used in server side rendering in NextJS
|
|
259
|
+
- **_Typescript_**:
|
|
260
|
+
- 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.
|
|
261
|
+
- **_Tailwind CSS_**:
|
|
262
|
+
- 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.
|
|
263
|
+
- **_React and JSX_**:
|
|
264
|
+
- 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_).
|
|
265
|
+
- **_Webpack config_**:
|
|
266
|
+
- 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
|
|
267
|
+
|
|
268
|
+
## Installation
|
|
269
|
+
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)
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
```shell
|
|
273
|
+
npm install nodoku-core nodoku-flowbite
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
## Integrating Nodoku into a project
|
|
277
|
+
|
|
278
|
+
The entry point of a Nodoku library is the **_RenderingPage_** component.
|
|
279
|
+
|
|
280
|
+
This component receives as properties the flow of content blocks and the skin, and renders accordingly.
|
|
281
|
+
|
|
282
|
+
Here is a typical example of the usage of the RenderingPage TSX component:
|
|
283
|
+
|
|
284
|
+
```tsx
|
|
285
|
+
|
|
286
|
+
// load and parse the content MD file
|
|
287
|
+
const content: NdContentBlock[] = await contentMarkdownProvider("<url location of the content file>.md", "en", "nodoku-landing")
|
|
288
|
+
|
|
289
|
+
// load the Yaml skin file
|
|
290
|
+
const skin: NdPageSkin = await skinYamlProvider("<url location of the skin file>.yaml")
|
|
291
|
+
|
|
292
|
+
...
|
|
293
|
+
|
|
294
|
+
<RenderingPage
|
|
295
|
+
lng={lng}
|
|
296
|
+
renderingPriority={RenderingPriority.skin_first}
|
|
297
|
+
skin={skin}
|
|
298
|
+
content={content}
|
|
299
|
+
componentResolver={defaultComponentResolver}
|
|
300
|
+
/>
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
### Content parsing
|
|
304
|
+
|
|
305
|
+
First, we parse the content MD file, using the predefined function _contentMarkdownProvider_.
|
|
306
|
+
|
|
307
|
+
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
|
|
308
|
+
|
|
309
|
+
```ts
|
|
310
|
+
async function contentMarkdownProvider(
|
|
311
|
+
mdFileUrl: string,
|
|
312
|
+
contentLng: string,
|
|
313
|
+
ns: string): Promise<NdContentBlock[]> {
|
|
314
|
+
|
|
315
|
+
return await fetch(mdFileUrl)
|
|
316
|
+
.then(response => response.text())
|
|
317
|
+
.then(fileContent => {
|
|
318
|
+
return parseMarkdownAsContent(fileContent, contentLng, ns)
|
|
319
|
+
})
|
|
320
|
+
}
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
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.
|
|
324
|
+
|
|
325
|
+
The result of this phase is the set of content blocks, represented as an array of _NdContentBlock_ items.
|
|
326
|
+
|
|
327
|
+
### Loading of the skin Yaml file
|
|
328
|
+
|
|
329
|
+
Likewise, there is a readily available parser for Yaml files, used as Nodoku skin. Recall, that _skin_ is a configuration for visual page rendering.
|
|
330
|
+
|
|
331
|
+
```ts
|
|
332
|
+
async function skinYamlProvider(yamlFileUrl: string): Promise<NdPageSkin> {
|
|
333
|
+
return await fetch(yamlFileUrl)
|
|
334
|
+
.then(response => response.text())
|
|
335
|
+
.then(parseYamlContentAsSkin);
|
|
336
|
+
}
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
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.
|
|
340
|
+
|
|
341
|
+
The result of this parsing is an instance of _NdPageSkin_, which conveys the necessary information regarding the Nodoku skin.
|
|
342
|
+
|
|
343
|
+
### Rendering Nodoku
|
|
344
|
+
|
|
345
|
+
Finally, when the skin and content are loaded, we can invoke the actual rendering using the provided component _RenderingPage_.
|
|
346
|
+
|
|
347
|
+
RenderingPage is an async JSX function, which is suitable for usage in the NextJS environment.
|
|
348
|
+
|
|
349
|
+
Let's have a closer look at its properties:
|
|
350
|
+
|
|
351
|
+
```ts
|
|
352
|
+
class RenderingPageProps {
|
|
353
|
+
lng: string;
|
|
354
|
+
content: NdContentBlock[];
|
|
355
|
+
skin: NdPageSkin | undefined = undefined;
|
|
356
|
+
renderingPriority: RenderingPriority = RenderingPriority.content_first;
|
|
357
|
+
componentResolver: ComponentResolver | undefined = undefined;
|
|
358
|
+
imageUrlProvider: ImageUrlProvider | undefined = undefined;
|
|
359
|
+
i18nextProvider: I18nextProvider | undefined = undefined;
|
|
360
|
+
}
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
- **_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))
|
|
364
|
+
|
|
365
|
+
|
|
366
|
+
- **_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_.
|
|
367
|
+
|
|
368
|
+
|
|
369
|
+
- **_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_.
|
|
370
|
+
|
|
371
|
+
|
|
372
|
+
- **_renderingPriority_**: this parameter is an enum that can have two values:
|
|
373
|
+
- > **_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
|
|
374
|
+
- > **_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
|
|
375
|
+
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.
|
|
376
|
+
|
|
377
|
+
|
|
378
|
+
- **_componentProvider_**: the function returning an actual implementation of the component, given its name, as specified in the skin. The signature is as follows:
|
|
379
|
+
> ```(componentName: string) => Promise<AsyncFunctionComponent>```
|
|
380
|
+
>
|
|
381
|
+
where AsyncFunctionComponent is the following function:
|
|
382
|
+
> ```(props: NdSkinComponentProps) => Promise<JSX.Element>```
|
|
383
|
+
|
|
384
|
+
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)_**
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
- **_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):
|
|
388
|
+
> **_../images/my-image-123.png_** will be converted to **_/images/my-image-123.png_**
|
|
389
|
+
|
|
390
|
+
|
|
391
|
+
- **_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.
|
|
392
|
+
> type I18nextProvider = (lng: string) => Promise<{t: (text: NdTranslatedText) => string}>
|
|
393
|
+
|
|
394
|
+
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.
|
|
395
|
+
|
|
396
|
+
For more details see [nodoku-i18n](https://github.com/nodoku/nodoku-i18n)
|
|
397
|
+
|
|
398
|
+
## Nodoku component resolver
|
|
399
|
+
|
|
400
|
+
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.
|
|
401
|
+
|
|
402
|
+
> 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.
|
|
403
|
+
|
|
404
|
+
Here is the typical example of the generated component resolver, that is crucial for successful functioning of Nodoku:
|
|
405
|
+
|
|
406
|
+
```ts
|
|
407
|
+
|
|
408
|
+
import {AsyncFunctionComponent, DummyComp, NdComponentDefinition} from "nodoku-core";
|
|
409
|
+
|
|
410
|
+
import { NodokuFlowbite } from "nodoku-flowbite";
|
|
411
|
+
|
|
412
|
+
const components: Map<string, {compo: AsyncFunctionComponent, compoDef: NdComponentDefinition}> =
|
|
413
|
+
new Map<string, {compo: AsyncFunctionComponent, compoDef: NdComponentDefinition}>();
|
|
414
|
+
|
|
415
|
+
components.set("flowbite/card", {
|
|
416
|
+
compo: NodokuFlowbite.Card,
|
|
417
|
+
compoDef: new NdComponentDefinition(1,
|
|
418
|
+
"./schemas/nodoku-flowbite/dist/schemas/components/card/default-theme.yml")
|
|
419
|
+
});
|
|
420
|
+
|
|
421
|
+
// other component definitions go here
|
|
422
|
+
|
|
423
|
+
export function nodokuComponentResolver(componentName: string): Promise<{compo: AsyncFunctionComponent, compoDef: NdComponentDefinition}> {
|
|
424
|
+
const f: {compo: AsyncFunctionComponent, compoDef: NdComponentDefinition} | undefined =
|
|
425
|
+
components.get(componentName);
|
|
426
|
+
return Promise.resolve(f ? f : {compo: DummyComp, compoDef: new NdComponentDefinition(1)});
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
```
|
|
430
|
+
|
|
431
|
+
Recall that the _componentResolver_ is one of the properties of the _RenderingPage_ component.
|
|
432
|
+
|
|
433
|
+
Thanks to this function Nodoku can find the correspondence between the component name specified in the skin Yaml file, and the actual component implementation.
|
|
434
|
+
|
|
435
|
+
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.
|
|
436
|
+
|
|
437
|
+
The visual components are supposed to be supplied as external library dependency, such as _nodoku-flowbite_ and _nodoku-mambaui_.
|
|
438
|
+
|
|
439
|
+
The static map, that is generated by the scirpt _nodoku-gen-component-resolver_, associates with each component name two attributes:
|
|
440
|
+
- **_compo_**: the function that is to be called to render the component
|
|
441
|
+
- **_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:
|
|
442
|
+
- **_numBlocks_**: the maximum number of blocks this component supports
|
|
443
|
+
- **_defaultThemeYaml_**: the Yaml file defining the default component visual configuration (usually uses Tailwind class names)
|
|
444
|
+
|
|
445
|
+
|
|
446
|
+
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.
|
|
447
|
+
|
|
448
|
+
# Nodoku component bundle
|
|
449
|
+
|
|
450
|
+
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
|
|
451
|
+
> ```npm install <nodoku component bundle>```
|
|
452
|
+
|
|
453
|
+
for example:
|
|
454
|
+
> ```npm install nodoku-flowbite```
|
|
455
|
+
|
|
456
|
+
## Nodoku manifest
|
|
457
|
+
|
|
458
|
+
Each component bundle should be shipped with a special file called **_nodoku.manifest.json_**.
|
|
459
|
+
|
|
460
|
+
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.
|
|
461
|
+
|
|
462
|
+
Here is an excerpt from such file for nodoku-flowbite:
|
|
463
|
+
|
|
464
|
+
```json
|
|
465
|
+
{
|
|
466
|
+
"namespace": "NodokuFlowbite",
|
|
467
|
+
"components": {
|
|
468
|
+
..
|
|
469
|
+
"flowbite/carousel": {
|
|
470
|
+
"schemaFile": "./dist/schemas/components/carousel/visual-schema.json",
|
|
471
|
+
"optionsFile": "./dist/schemas/components/carousel/options-schema.json",
|
|
472
|
+
"defaultThemeFile": "./dist/schemas/components/carousel/default-theme.yml",
|
|
473
|
+
"implementation": "Carousel",
|
|
474
|
+
"numBlocks": "unlimited"
|
|
475
|
+
},
|
|
476
|
+
...
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
```
|
|
480
|
+
|
|
481
|
+
Let's have a closer look at the attributes of each Nodoku visual component:
|
|
482
|
+
|
|
483
|
+
- **_namespace_**: the Javascript namespace where out of which the component is being exported.
|
|
484
|
+
|
|
485
|
+
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.
|
|
486
|
+
```ts
|
|
487
|
+
import { NodokuFlowbite } from "nodoku-flowbite";
|
|
488
|
+
components.set("flowbite/carousel", {compo: NodokuFlowbite.Carousel, ...});
|
|
489
|
+
```
|
|
490
|
+
The Nodoku manifest cannot have more than one namespace.
|
|
491
|
+
|
|
492
|
+
|
|
493
|
+
- **_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:
|
|
494
|
+
|
|
495
|
+
|
|
496
|
+
- **_schemaFile_**: is a Json schema file representing the data structure of the visual theme of the component (see [Nodoku skin schema](#nodoku-skin-schema))
|
|
497
|
+
|
|
498
|
+
|
|
499
|
+
- **_optionsFile_**: is a Json schema file representing the data structure of the functional options of the component (see [Nodoku skin schema](#nodoku-skin-schema))
|
|
500
|
+
|
|
501
|
+
|
|
502
|
+
- **_defaultThemeFile_**: a Yaml file containing the default Tailwind configuration of the component
|
|
503
|
+
|
|
504
|
+
|
|
505
|
+
- **_implementation_**: the actual Javascript function rendering this compnent. (the signature should correspond to _AsyncFunctionComponent_)
|
|
506
|
+
|
|
507
|
+
|
|
508
|
+
- **_numBlocks_**: number of content blocks this component can accept for rendering. This parameter can either be a positive number of the predefined value '_unlimited_'
|
|
509
|
+
|
|
510
|
+
|
|
511
|
+
|
|
512
|
+
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'_**.
|
|
513
|
+
|
|
514
|
+
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.
|
|
515
|
+
|
|
516
|
+
# Nodoku skin
|
|
517
|
+
|
|
518
|
+
|
|
519
|
+
The Nodoku skin is a Yaml file which configures the Nodoku rendering.
|
|
520
|
+
|
|
521
|
+
Recall, that in Nodoku there is a strict separation between the content and the visual representation.
|
|
522
|
+
|
|
523
|
+
The content is provided via an MD file, whereas the mapping between the content blocks and visual components are defined in the _skin_.
|
|
524
|
+
|
|
525
|
+
The skin also defines the necessary customizations and fine-tuning of the page visual representation, if required.
|
|
526
|
+
|
|
527
|
+
## Nodoku visual component theme
|
|
528
|
+
|
|
529
|
+
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_.
|
|
530
|
+
|
|
531
|
+
Consider the following example:
|
|
532
|
+
|
|
533
|
+
```tsx
|
|
534
|
+
<h3 className={`${effectiveTheme.titleStyle?.base} ${effectiveTheme.titleStyle?.decoration}`}>
|
|
535
|
+
{t(block.title)}
|
|
536
|
+
</h3>
|
|
537
|
+
|
|
538
|
+
<h4 className={`${effectiveTheme.subTitleStyle?.base} ${effectiveTheme.subTitleStyle?.decoration}`}>
|
|
539
|
+
{t(block.subTitle)}
|
|
540
|
+
</h4>
|
|
541
|
+
```
|
|
542
|
+
|
|
543
|
+
The component theme is supplied to the component by the Nodoku engine, and comes in as a data structure containing two elements:
|
|
544
|
+
- one for title styling _effectiveTheme.**titleStyle**_
|
|
545
|
+
- and one for subtitle styling _effectiveTheme.**subTitleStyle**_
|
|
546
|
+
|
|
547
|
+
Each such element is called _ThemeStyle_, and is composed of two string attributes: _base_ and _decoration_
|
|
548
|
+
|
|
549
|
+
The component theme consists of several attributes of type _ThemeStyle_.
|
|
550
|
+
|
|
551
|
+
Here is an excerpt from the component theme _flowbite/card_
|
|
552
|
+
|
|
553
|
+
```ts
|
|
554
|
+
export class CardTheme {
|
|
555
|
+
...
|
|
556
|
+
titleStyle?: ThemeStyle;
|
|
557
|
+
subTitleStyle?: ThemeStyle;
|
|
558
|
+
...
|
|
559
|
+
}
|
|
560
|
+
```
|
|
561
|
+
where ThemeStyle is defined as follows:
|
|
562
|
+
```ts
|
|
563
|
+
export class ThemeStyle {
|
|
564
|
+
base: string;
|
|
565
|
+
decoration: string;
|
|
566
|
+
}
|
|
567
|
+
```
|
|
568
|
+
|
|
569
|
+
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.
|
|
570
|
+
|
|
571
|
+
In addition, the theme of each component can further be customized in the skin Yaml file.
|
|
572
|
+
|
|
573
|
+
|
|
574
|
+
# The Nodoku skin Yaml file
|
|
575
|
+
|
|
576
|
+
|
|
577
|
+
|
|
578
|
+
|
|
579
|
+
The skin Yaml file has a predefined structure, which can be summarized as follows:
|
|
580
|
+
|
|
581
|
+
```yaml
|
|
582
|
+
global:
|
|
583
|
+
renderingPage:
|
|
584
|
+
# styles applied to the whole page
|
|
585
|
+
theme:
|
|
586
|
+
# attributes defined on the global level for all the component themes
|
|
587
|
+
themes:
|
|
588
|
+
# 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
|
|
589
|
+
components:
|
|
590
|
+
<component-name>:
|
|
591
|
+
theme:
|
|
592
|
+
# defines a theme customization for a particular component
|
|
593
|
+
themes:
|
|
594
|
+
# 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
|
|
595
|
+
|
|
596
|
+
rows:
|
|
597
|
+
# list of rows
|
|
598
|
+
- row:
|
|
599
|
+
theme:
|
|
600
|
+
# styling classes applied on the row level
|
|
601
|
+
maxCols:
|
|
602
|
+
# 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
|
|
603
|
+
components:
|
|
604
|
+
<component-name>:
|
|
605
|
+
selector:
|
|
606
|
+
# 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
|
|
607
|
+
options:
|
|
608
|
+
# a component may accept an options object, which can be defined here
|
|
609
|
+
theme:
|
|
610
|
+
# the customization of the component's scheme
|
|
611
|
+
themes:
|
|
612
|
+
# 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
|
|
613
|
+
```
|
|
614
|
+
|
|
615
|
+
The customization is applied progressively, from the least specific theme to the most specific, starting from the default theme of the component.
|
|
616
|
+
|
|
617
|
+
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.
|
|
618
|
+
|
|
619
|
+
## Schema for Nodoku skin Yaml file
|
|
620
|
+
|
|
621
|
+
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).
|
|
622
|
+
|
|
623
|
+
Similar to the generation script for Nodoku component resolver, there is a script for generation of the Nodoku skin schema: **_nodoku-gen-skin-schema_**
|
|
624
|
+
|
|
625
|
+
One can run this script to automatically generate a Nodoku skin schema file.
|
|
626
|
+
|
|
627
|
+
The schema file by default is generated in the folder
|
|
628
|
+
> <project folder>/schemas
|
|
629
|
+
|
|
630
|
+
After the schema generation script completes, the **_./schemas_** folder should look as follows:
|
|
631
|
+
|
|
632
|
+
<figure>
|
|
633
|
+
<img
|
|
634
|
+
src="./docs/schemas-folder-expanded.png"
|
|
635
|
+
alt="project schemas folder after schema generation"
|
|
636
|
+
title="project schemas folder after schema generation"
|
|
637
|
+
/>
|
|
638
|
+
<figcaption>
|
|
639
|
+
<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
|
|
640
|
+
</figcaption>
|
|
641
|
+
</figure>
|
|
642
|
+
|
|
643
|
+
The generated schema file - ./schemas/visual-schema.json - can be applied to the skin Yaml file in several ways:
|
|
644
|
+
- use [the IDE mechanism of schema application](https://www.jetbrains.com/help/idea/yaml.html#json_schema)
|
|
645
|
+
- use the **_yaml-language-server_** header (the first row) for the Yaml file as follows:
|
|
646
|
+
|
|
647
|
+
```yaml
|
|
648
|
+
# yaml-language-server: $schema=../../../schemas/visual-schema.json
|
|
649
|
+
|
|
650
|
+
global:
|
|
651
|
+
renderingPage:
|
|
652
|
+
base: dark:text-gray-200 text-gray-700
|
|
653
|
+
|
|
654
|
+
rows:
|
|
655
|
+
- row:
|
|
656
|
+
theme:
|
|
657
|
+
decoration: mb-10
|
|
658
|
+
|
|
659
|
+
```
|
|
660
|
+
|
|
661
|
+
## Customizing Nodoku page appearance
|
|
662
|
+
|
|
663
|
+
The main principle of component customization in Nodoku consists of cascading application of themes, defined on different levels:
|
|
664
|
+
- **_global level_**: the section **_global_** in the Yaml file. This level can further be divided to
|
|
665
|
+
- **_theme level_**: where any attribute for any component can be defined
|
|
666
|
+
- **_component level_**: where attributes for a given component can be defined
|
|
667
|
+
- **_rows level_**: where the list of rows defines each its set of components
|
|
668
|
+
- **_component in a row level_**: the most specific customization, where a particular component can be customized
|
|
669
|
+
|
|
670
|
+
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.
|
|
671
|
+
|
|
672
|
+
|
|
673
|
+
|
|
674
|
+
|
|
675
|
+
# Nodoku generation scripts
|
|
676
|
+
|
|
677
|
+
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
|
|
678
|
+
|
|
679
|
+
|
|
680
|
+
- **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
|
|
681
|
+
|
|
682
|
+
|
|
683
|
+
- **nodoku-gen-visual-schema**: generates the json schema file thate can be used to validate the Nodoku skin schema file
|
|
684
|
+
|
|
685
|
+
To simplify the use of these script it is recommended to add them in the project's package.json file as follows:
|
|
686
|
+
|
|
687
|
+
```json
|
|
688
|
+
{
|
|
689
|
+
...
|
|
690
|
+
"scripts": {
|
|
691
|
+
"gen-component-resolver": "nodoku-gen-component-resolver",
|
|
692
|
+
"gen-skin-schema": "nodoku-gen-skin-schema"
|
|
693
|
+
},
|
|
694
|
+
...
|
|
695
|
+
}
|
|
696
|
+
```
|
|
697
|
+
|