mikel-press 0.20.0 → 0.20.1
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 +12 -4
- package/index.js +46 -16
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -121,7 +121,7 @@ Options:
|
|
|
121
121
|
- `options.extensions` (array): Defines the file extensions that should be processed. If not provided, it will use `config.extensions`.
|
|
122
122
|
- `options.basePath` (string): Specifies the base path for the output files.
|
|
123
123
|
|
|
124
|
-
### `press.
|
|
124
|
+
### `press.PartialsPlugin(options)`
|
|
125
125
|
|
|
126
126
|
An alias of `press.SourcePlugin` that will read all files in the `partials` folder and process them as a partials. The **mikel** tag `{{>file}}` can be used to include the partial in `partials/file.html`.
|
|
127
127
|
|
|
@@ -129,13 +129,21 @@ This plugin accepts the following options:
|
|
|
129
129
|
- `options.folder` (string): To change the directory to load the partials files. Default is `./partials`.
|
|
130
130
|
- `options.extensions` (array): Defines the file extensions that should be processed. If not provided, it will use `config.extensions`.
|
|
131
131
|
|
|
132
|
-
### `press.
|
|
132
|
+
### `press.DataPlugin(options)`
|
|
133
133
|
|
|
134
|
-
This plugin loads JSON files from the specified directory and makes them available in the site context.
|
|
134
|
+
This plugin loads JSON files from the specified directory and makes them available in the site context. This plugin accepts the following options:
|
|
135
135
|
|
|
136
|
-
Options:
|
|
137
136
|
- `options.folder` (string): Specifies a custom source directory for data files. If not provided, `./data` is used.
|
|
138
137
|
|
|
138
|
+
### `press.AssetsPlugin(options)`
|
|
139
|
+
|
|
140
|
+
This plugin loads additional files (aka assets) and includes them in the build folder. This plugin accepts the following options:
|
|
141
|
+
|
|
142
|
+
- `options.folder` (string): Specifies a custom source directory for assets files. If not provided, `./assets` is used.
|
|
143
|
+
- `options.extensions` (array): Defines the file extensions that should be processed. If not provided, it will use `"*"`.
|
|
144
|
+
- `options.exclude` (array): Defines the list of file names to exclude.
|
|
145
|
+
- `options.basePath` (string): Allows to specify a base path for the output files.
|
|
146
|
+
|
|
139
147
|
### `press.FrontmatterPlugin()`
|
|
140
148
|
|
|
141
149
|
This plugin processes and parses the frontmatter in each file. The parsed frontmatter content will be available in `page.attributes` field.
|
package/index.js
CHANGED
|
@@ -8,15 +8,16 @@ import mikel from "mikel";
|
|
|
8
8
|
// @param {String} config.destination - destination folder to save the files
|
|
9
9
|
// @param {Array} config.plugins - list of plugins to apply
|
|
10
10
|
const press = (config = {}) => {
|
|
11
|
-
const {source, destination, plugins, extensions, mikelOptions, ...otherConfig} = config;
|
|
11
|
+
const {source, destination, plugins, extensions, exclude, mikelOptions, ...otherConfig} = config;
|
|
12
12
|
const context = Object.freeze({
|
|
13
13
|
config: otherConfig,
|
|
14
14
|
source: path.resolve(source || "."),
|
|
15
15
|
destination: path.resolve(destination || "./www"),
|
|
16
16
|
extensions: extensions || [".html"],
|
|
17
|
+
exclude: exclude || ["node_modules", ".git", ".gitignore", ".github"],
|
|
17
18
|
template: mikel.create("{{>content}}", mikelOptions || {}),
|
|
18
19
|
plugins: [
|
|
19
|
-
SourcePlugin({folder: ".", label: press.LABEL_PAGE}),
|
|
20
|
+
press.SourcePlugin({folder: ".", label: press.LABEL_PAGE}),
|
|
20
21
|
...plugins,
|
|
21
22
|
],
|
|
22
23
|
nodes: [],
|
|
@@ -86,12 +87,12 @@ press.utils = {
|
|
|
86
87
|
fs.copyFileSync(source, target);
|
|
87
88
|
},
|
|
88
89
|
// @description get all files from the given folder and the given extensions
|
|
89
|
-
readdir: (folder, extensions = "*") => {
|
|
90
|
+
readdir: (folder, extensions = "*", exclude = []) => {
|
|
90
91
|
if (!fs.existsSync(folder) || !fs.statSync(folder).isDirectory()) {
|
|
91
92
|
return [];
|
|
92
93
|
}
|
|
93
94
|
return fs.readdirSync(folder, "utf8")
|
|
94
|
-
.filter(file => extensions === "*" || extensions.includes(path.extname(file)))
|
|
95
|
+
.filter(file => (extensions === "*" || extensions.includes(path.extname(file))) && !exclude.includes(file))
|
|
95
96
|
.filter(file => fs.statSync(path.join(folder, file)).isFile());
|
|
96
97
|
},
|
|
97
98
|
// @description frontmatter parser
|
|
@@ -121,7 +122,9 @@ press.SourcePlugin = (options = {}) => {
|
|
|
121
122
|
name: "SourcePlugin",
|
|
122
123
|
load: context => {
|
|
123
124
|
const folder = path.join(context.source, options?.folder || ".");
|
|
124
|
-
|
|
125
|
+
const extensions = options?.extensions || context.extensions;
|
|
126
|
+
const exclude = options?.exclude || context.exclude;
|
|
127
|
+
return press.utils.readdir(folder, extensions, exclude).map(file => ({
|
|
125
128
|
source: path.join(folder, file),
|
|
126
129
|
label: options.label || press.LABEL_PAGE,
|
|
127
130
|
path: path.join(options?.basePath || ".", file),
|
|
@@ -132,12 +135,37 @@ press.SourcePlugin = (options = {}) => {
|
|
|
132
135
|
};
|
|
133
136
|
};
|
|
134
137
|
|
|
135
|
-
// @description
|
|
136
|
-
press.
|
|
137
|
-
return SourcePlugin({folder: "./data", extensions: [".json"], label: press.LABEL_DATA, ...options});
|
|
138
|
+
// @description data plugin
|
|
139
|
+
press.DataPlugin = (options = {}) => {
|
|
140
|
+
return press.SourcePlugin({folder: "./data", extensions: [".json"], label: press.LABEL_DATA, ...options});
|
|
138
141
|
};
|
|
139
|
-
|
|
140
|
-
|
|
142
|
+
|
|
143
|
+
// @description partials plugin
|
|
144
|
+
press.PartialsPlugin = (options = {}) => {
|
|
145
|
+
return press.SourcePlugin({folder: "./partials", extensions: [".html"], label: press.LABEL_PARTIAL, ...options});
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
// @description assets plugin
|
|
149
|
+
press.AssetsPlugin = (options = {}) => {
|
|
150
|
+
return {
|
|
151
|
+
name: "AssetsPlugin",
|
|
152
|
+
load: context => {
|
|
153
|
+
const folder = path.join(context.source, options?.folder || "./assets");
|
|
154
|
+
return press.utils.readdir(folder, options?.extensions || "*", options?.exclude || context.exclude).map(file => ({
|
|
155
|
+
source: path.join(folder, file),
|
|
156
|
+
label: options.label || press.LABEL_ASSET,
|
|
157
|
+
path: path.join(options?.basePath || ".", file),
|
|
158
|
+
}));
|
|
159
|
+
},
|
|
160
|
+
emit: (context, node) => {
|
|
161
|
+
if (node.label === press.LABEL_ASSET && typeof node.content === "string") {
|
|
162
|
+
press.utils.write(path.join(context.destination, node.path), node.content);
|
|
163
|
+
}
|
|
164
|
+
else if (node.label === press.LABEL_ASSET) {
|
|
165
|
+
press.utils.copy(node.source, path.join(context.destination, node.path));
|
|
166
|
+
}
|
|
167
|
+
},
|
|
168
|
+
};
|
|
141
169
|
};
|
|
142
170
|
|
|
143
171
|
// @description frontmatter plugin
|
|
@@ -147,7 +175,7 @@ press.FrontmatterPlugin = () => {
|
|
|
147
175
|
transform: (_, node) => {
|
|
148
176
|
if (typeof node.content === "string") {
|
|
149
177
|
const result = press.utils.frontmatter(node.content, JSON.parse);
|
|
150
|
-
node.content = result.
|
|
178
|
+
node.content = result.body || "";
|
|
151
179
|
node.attributes = result.attributes || {};
|
|
152
180
|
node.title = node.attributes?.title || node.path;
|
|
153
181
|
if (node.attributes.permalink) {
|
|
@@ -164,7 +192,7 @@ press.ContentPagePlugin = (siteData = {}) => {
|
|
|
164
192
|
return {
|
|
165
193
|
name: "ContentPagePlugin",
|
|
166
194
|
shouldEmit: (context, node) => {
|
|
167
|
-
return ![press.
|
|
195
|
+
return ![press.LABEL_DATA, press.LABEL_PARTIAL].includes(node.label);
|
|
168
196
|
},
|
|
169
197
|
beforeEmit: context => {
|
|
170
198
|
const getNodes = label => context.nodes.filter(n => n.label === label);
|
|
@@ -180,7 +208,7 @@ press.ContentPagePlugin = (siteData = {}) => {
|
|
|
180
208
|
// 2. register partials into template
|
|
181
209
|
siteData.partials.forEach(partial => {
|
|
182
210
|
context.template.addPartial(path.basename(partial.path), {
|
|
183
|
-
body: partial.content,
|
|
211
|
+
body: partial.content || "",
|
|
184
212
|
attributes: partial.attributes || {},
|
|
185
213
|
});
|
|
186
214
|
});
|
|
@@ -203,9 +231,11 @@ press.CopyAssetsPlugin = (options = {}) => {
|
|
|
203
231
|
return {
|
|
204
232
|
name: "CopyAssetsPlugin",
|
|
205
233
|
beforeEmit: context => {
|
|
206
|
-
(options.patterns || [])
|
|
207
|
-
|
|
208
|
-
|
|
234
|
+
return (options.patterns || []).forEach(item => {
|
|
235
|
+
if (item.from && fs.existsSync(item.from)) {
|
|
236
|
+
press.utils.copy(item.from, path.join(context.destination, options.basePath || ".", item.to || path.basename(item.from)));
|
|
237
|
+
}
|
|
238
|
+
});
|
|
209
239
|
},
|
|
210
240
|
};
|
|
211
241
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mikel-press",
|
|
3
3
|
"description": "A tiny and fast static site generator based on mikel templating",
|
|
4
|
-
"version": "0.20.
|
|
4
|
+
"version": "0.20.1",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"author": {
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"node": ">=20"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"mikel": "^0.20.
|
|
22
|
+
"mikel": "^0.20.1"
|
|
23
23
|
},
|
|
24
24
|
"files": [
|
|
25
25
|
"README.md",
|