@lumeland/plugin-modules 0.0.0-stage → 1.0.0-beta-2
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/CHANGELOG.md +10 -0
- package/LICENSE +21 -0
- package/build/src/mod.d.ts +33 -0
- package/build/src/mod.js +46 -0
- package/package.json +25 -3
- package/README.md +0 -3
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/)
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/).
|
|
7
|
+
|
|
8
|
+
## 1.0.0 - Unreleased
|
|
9
|
+
|
|
10
|
+
First version
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 - Oscar Otero
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type Site from "@lumeland/core/site.ts";
|
|
2
|
+
import type { Engine, Helper } from "@lumeland/core/renderer.ts";
|
|
3
|
+
export interface Options {
|
|
4
|
+
/** File extensions to load */
|
|
5
|
+
extensions?: string[];
|
|
6
|
+
/** Optional sub-extension for page files */
|
|
7
|
+
pageSubExtension?: string;
|
|
8
|
+
/**
|
|
9
|
+
* Custom includes path
|
|
10
|
+
* @default `site.options.includes`
|
|
11
|
+
*/
|
|
12
|
+
includes?: string;
|
|
13
|
+
}
|
|
14
|
+
export declare const defaults: {
|
|
15
|
+
extensions: string[];
|
|
16
|
+
pageSubExtension: string;
|
|
17
|
+
};
|
|
18
|
+
/** Template engine to render js/ts files */
|
|
19
|
+
export declare class ModuleEngine implements Engine {
|
|
20
|
+
helpers: Record<string, Helper>;
|
|
21
|
+
includes: string;
|
|
22
|
+
constructor(includes: string);
|
|
23
|
+
deleteCache(): void;
|
|
24
|
+
render(content: unknown, data: Record<string, unknown>): Promise<unknown>;
|
|
25
|
+
addHelper(name: string, fn: Helper): void;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* A plugin to load js/ts files as data and pages
|
|
29
|
+
* Installed by default
|
|
30
|
+
* @see https://lume.land/plugins/modules/
|
|
31
|
+
*/
|
|
32
|
+
export declare function modules(userOptions?: Options): (site: Site) => void;
|
|
33
|
+
export default modules;
|
package/build/src/mod.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import loader from "@lumeland/core/loaders/module.ts";
|
|
2
|
+
import { merge } from "@lumeland/core/utils/object.ts";
|
|
3
|
+
// Default options
|
|
4
|
+
export const defaults = {
|
|
5
|
+
extensions: [".js", ".ts"],
|
|
6
|
+
pageSubExtension: ".page",
|
|
7
|
+
};
|
|
8
|
+
/** Template engine to render js/ts files */
|
|
9
|
+
export class ModuleEngine {
|
|
10
|
+
helpers = {};
|
|
11
|
+
includes;
|
|
12
|
+
constructor(includes) {
|
|
13
|
+
this.includes = includes;
|
|
14
|
+
}
|
|
15
|
+
deleteCache() { }
|
|
16
|
+
async render(content, data) {
|
|
17
|
+
return typeof content === "function" ? await content(data, this.helpers) : content;
|
|
18
|
+
}
|
|
19
|
+
addHelper(name, fn) {
|
|
20
|
+
this.helpers[name] = fn;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* A plugin to load js/ts files as data and pages
|
|
25
|
+
* Installed by default
|
|
26
|
+
* @see https://lume.land/plugins/modules/
|
|
27
|
+
*/
|
|
28
|
+
export function modules(userOptions) {
|
|
29
|
+
return (site) => {
|
|
30
|
+
const options = merge({ ...defaults, includes: site.options.includes }, userOptions);
|
|
31
|
+
const engine = new ModuleEngine(options.includes);
|
|
32
|
+
// Ignore includes folder
|
|
33
|
+
if (options.includes) {
|
|
34
|
+
site.ignore(options.includes);
|
|
35
|
+
}
|
|
36
|
+
// Load the _data files
|
|
37
|
+
site.loadData(options.extensions, loader);
|
|
38
|
+
// Load the pages and register the engine
|
|
39
|
+
site.loadPages(options.extensions, {
|
|
40
|
+
loader,
|
|
41
|
+
engine,
|
|
42
|
+
pageSubExtension: options.pageSubExtension,
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
export default modules;
|
package/package.json
CHANGED
|
@@ -1,6 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lumeland/plugin-modules",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "1.0.0-beta-2",
|
|
4
|
+
"description": "Plugin to use ESM and TypeScript modules to create pages, layouts, and store data",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"files": [
|
|
7
|
+
"build",
|
|
8
|
+
"CHANGELOG.md"
|
|
9
|
+
],
|
|
10
|
+
"type": "module",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./build/src/mod.d.ts",
|
|
14
|
+
"import": "./build/src/mod.js"
|
|
15
|
+
},
|
|
16
|
+
"./*.ts": {
|
|
17
|
+
"types": "./build/src/*.d.ts",
|
|
18
|
+
"import": "./build/src/*.js"
|
|
19
|
+
},
|
|
20
|
+
"./*.js": {
|
|
21
|
+
"types": "./build/src/*.d.ts",
|
|
22
|
+
"import": "./build/src/*.js"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"@lumeland/core": "1.0.0-beta-4"
|
|
27
|
+
}
|
|
6
28
|
}
|
package/README.md
DELETED