nibula 1.2.5 → 1.3.0
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/.eleventy.js +1 -1
- package/CHANGELOG.md +33 -0
- package/bin/create.js +1 -1
- package/docs/Javascript.md +74 -0
- package/package.json +1 -1
- package/src/frontend/js/modules/global.js +10 -0
- package/src/frontend/js/pages/404.js +2 -1
- package/src/frontend/js/pages/homepage.js +2 -1
- package/src/frontend/ts/modules/global.ts +10 -0
- package/src/frontend/ts/pages/404.ts +1 -0
- package/src/frontend/ts/pages/homepage.ts +1 -0
- package/tools/res/templates/template.js +2 -1
- package/tools/res/templates/template.ts +1 -0
package/.eleventy.js
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,39 @@ All notable changes to Nibula are documented here.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [1.3.0] - 2026-08-01
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- A `global.js` module in `src/frontend/js/modules/`, for code that has to run
|
|
12
|
+
on every page — a header menu, a theme toggle, a cookie banner. Page entry
|
|
13
|
+
points import it once and it takes care of running the shared modules, so
|
|
14
|
+
there's no longer a line to remember in every single page.
|
|
15
|
+
- `docs/Javascript.md` now covers the global module, with the header burger
|
|
16
|
+
menu as a worked example and a note on when a behaviour belongs in
|
|
17
|
+
`global.js` rather than in a page.
|
|
18
|
+
|
|
19
|
+
### Changed
|
|
20
|
+
- Page entry points, and the template new pages are created from, now start
|
|
21
|
+
with `import '../modules/global.js';`.
|
|
22
|
+
|
|
23
|
+
### Notes
|
|
24
|
+
- Existing projects keep working as they are. To adopt the global module, add
|
|
25
|
+
`src/frontend/js/modules/global.js` and the import line at the top of each
|
|
26
|
+
page entry point.
|
|
27
|
+
|
|
28
|
+
## [1.2.6] - 2026-08-01
|
|
29
|
+
|
|
30
|
+
### Fixed
|
|
31
|
+
- The scaffolder created the routes folder as `src/frontend/_routes` instead of
|
|
32
|
+
`src/frontend/routes`. The CLI writes and looks for page templates in
|
|
33
|
+
`routes`, so on a freshly created project every page ended up outside the
|
|
34
|
+
folder Eleventy and the assistant expect.
|
|
35
|
+
|
|
36
|
+
### Notes
|
|
37
|
+
- Projects created with 1.2.5 have an empty `src/frontend/_routes` folder that
|
|
38
|
+
can be deleted. Pages created before this fix should be moved to
|
|
39
|
+
`src/frontend/routes`.
|
|
40
|
+
|
|
8
41
|
## [1.2.5] - 2026-08-01
|
|
9
42
|
|
|
10
43
|
### Added
|
package/bin/create.js
CHANGED
package/docs/Javascript.md
CHANGED
|
@@ -11,6 +11,7 @@ Import only what the page needs.
|
|
|
11
11
|
### examplePage.js <small>(`src/frontend/js/pages/`)</small>
|
|
12
12
|
|
|
13
13
|
```js
|
|
14
|
+
import '../modules/global.js';
|
|
14
15
|
// import { initExampleModule } from '../modules/exampleModule.js';
|
|
15
16
|
|
|
16
17
|
document.addEventListener("DOMContentLoaded", () => {
|
|
@@ -20,6 +21,79 @@ document.addEventListener("DOMContentLoaded", () => {
|
|
|
20
21
|
// Page logic here
|
|
21
22
|
```
|
|
22
23
|
|
|
24
|
+
## Global JS
|
|
25
|
+
|
|
26
|
+
Some code has to run on every page: a header menu, a theme toggle, a cookie banner. Repeating it in every page entry point means you'll eventually forget it on one of them, and the bug only shows up on that single page.
|
|
27
|
+
|
|
28
|
+
That's what `global.js` is for. It lives in `src/frontend/js/modules/`, every page entry point imports it, and it takes care of running the shared modules.
|
|
29
|
+
|
|
30
|
+
### global.js <small>(`src/frontend/js/modules/`)</small>
|
|
31
|
+
|
|
32
|
+
```js
|
|
33
|
+
// import { initExampleModule } from './exampleModule.js';
|
|
34
|
+
|
|
35
|
+
function initGlobal() {
|
|
36
|
+
// initExampleModule();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Global logic here
|
|
40
|
+
|
|
41
|
+
// Do not touch this line
|
|
42
|
+
document.addEventListener('DOMContentLoaded', initGlobal);
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Pages import it without curly braces, since there is nothing to export — the module runs on its own as soon as it's part of the bundle:
|
|
46
|
+
|
|
47
|
+
```js
|
|
48
|
+
import '../modules/global.js';
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Note that the import path inside `global.js` is `'./exampleModule.js'` and not `'../modules/exampleModule.js'`: `global.js` already sits in the modules folder, next to the modules it imports.
|
|
52
|
+
|
|
53
|
+
### A concrete example: the header menu
|
|
54
|
+
|
|
55
|
+
A responsive header has a burger button that opens the navigation on small screens. The header is included in `base.njk`, so it's on every page — a textbook case for `global.js`.
|
|
56
|
+
|
|
57
|
+
Write the behaviour as a normal module:
|
|
58
|
+
|
|
59
|
+
```js
|
|
60
|
+
// src/frontend/js/modules/header.js
|
|
61
|
+
|
|
62
|
+
export function initHeader() {
|
|
63
|
+
const toggle = document.querySelector('.menu-toggle');
|
|
64
|
+
const menu = document.querySelector('.menu');
|
|
65
|
+
|
|
66
|
+
if (!toggle || !menu) return;
|
|
67
|
+
|
|
68
|
+
toggle.addEventListener('click', () => {
|
|
69
|
+
menu.classList.toggle('is-open');
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Then wire it up once, in `global.js`:
|
|
75
|
+
|
|
76
|
+
```js
|
|
77
|
+
import { initHeader } from './header.js';
|
|
78
|
+
|
|
79
|
+
function initGlobal() {
|
|
80
|
+
initHeader();
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Do not touch this line
|
|
84
|
+
document.addEventListener('DOMContentLoaded', initGlobal);
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
The burger now works on every page, and no page entry point had to change. Adding another global behaviour later is two lines: one import, one call inside `initGlobal()`.
|
|
88
|
+
|
|
89
|
+
The early `return` matters: if a page has no header, the module does nothing instead of throwing an error that would stop your other scripts.
|
|
90
|
+
|
|
91
|
+
### Global or page module?
|
|
92
|
+
|
|
93
|
+
Use `global.js` for behaviour tied to something present on every page — anything included in `base.njk`, essentially.
|
|
94
|
+
|
|
95
|
+
Keep it in the page entry point when only one or two pages need it. Everything imported by `global.js` ends up in *every* page bundle, so a heavy module used by a single page belongs in that page instead.
|
|
96
|
+
|
|
23
97
|
## Modules
|
|
24
98
|
|
|
25
99
|
Modules live in `src/frontend/js/modules/`. Modules that interact with the DOM must be called inside `DOMContentLoaded`; others can be called anywhere.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nibula",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "A beginner-friendly static site generator built on Eleventy that stays close to vanilla HTML, CSS and JS — with a page-management CLI, an optional PHP backend, and SEO files generated for you.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"static-site-generator",
|