@nera-static/plugin-navigation 2.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) [2025] [Michael Becker]
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.
package/README.md ADDED
@@ -0,0 +1,115 @@
1
+ # @nera-static/plugin-navigation
2
+
3
+ A plugin for the [Nera](https://github.com/seebaermichi/nera) static site generator to create navigations from config files. Supports mixins and templates for easy rendering.
4
+
5
+ ## 🚀 Installation
6
+
7
+ You can install this plugin by running the following in the root folder of your Nera project:
8
+
9
+ ```bash
10
+ npm install @nera-static/plugin-navigation
11
+ ```
12
+
13
+ Then create a `navigation.yaml` file inside your project’s `config/` directory:
14
+
15
+ ```
16
+ config/
17
+ └── navigation.yaml
18
+ ```
19
+
20
+ Nera will automatically detect the plugin and load your navigation configuration. No additional setup or imports are required.
21
+
22
+ ## ⚙️ Configuration
23
+
24
+ ### Single Navigation
25
+
26
+ Example `navigation/config/navigation.yaml`:
27
+
28
+ ```yaml
29
+ elements:
30
+ - href: /index.html
31
+ name: Home
32
+ - href: /service/service.html
33
+ name: Service
34
+ - href: /prices.html
35
+ name: Prices
36
+ - href: /contact.html
37
+ name: Contact
38
+ - href: /about-us/index.html
39
+ name: About us
40
+ ```
41
+
42
+ Access it in your templates via:
43
+
44
+ ```pug
45
+ app.nav.elements
46
+ ```
47
+
48
+ ### Multiple Navigations
49
+
50
+ ```yaml
51
+ elements:
52
+ main:
53
+ - href: /index.html
54
+ name: Home
55
+ - href: /service/service.html
56
+ name: Service
57
+ footer:
58
+ - href: /imprint.html
59
+ name: Imprint
60
+ ```
61
+
62
+ Use:
63
+
64
+ ```pug
65
+ app.nav.main.elements
66
+ app.nav.footer.elements
67
+ ```
68
+
69
+ Each element has: `href`, `name`, `path`.
70
+
71
+ ## 🧩 Rendering Options
72
+
73
+ ### Custom Rendering
74
+
75
+ Use the `app.nav.*.elements` arrays in your templates manually or via your own loops.
76
+
77
+ ### Built-in Templates
78
+
79
+ If you like to, include one of the built-in templates in `views/`:
80
+
81
+ ```pug
82
+ include ../../src/plugins/navigation/views/simple-navigation
83
+ ```
84
+
85
+ Other available templates:
86
+ - `pipe-separated-navigation.pug`
87
+ - `link-list-navigation.pug`
88
+
89
+ ### Built-in Mixins
90
+
91
+ If using multiple navigations, use the mixins in `views/mixins/`:
92
+
93
+ ```pug
94
+ include ../../src/plugins/navigation/views/mixins/pipe-separated-navigation
95
+
96
+ +pipeSeparatedNav(app.nav.main.elements, app.nav.main.className)
97
+ ```
98
+
99
+ > The optional `nav_class` value can be set in the YAML config.
100
+
101
+ ## 🧪 Development
102
+
103
+ ```bash
104
+ npm install
105
+ npm run test
106
+ ```
107
+
108
+ ## 🧑‍💻 Author
109
+
110
+ Michael Becker
111
+ [GitHub](https://github.com/seebaermichi)
112
+
113
+ ## 📦 License
114
+
115
+ MIT
package/index.js ADDED
@@ -0,0 +1,44 @@
1
+ import path from 'path';
2
+ import { getConfig } from '@nera-static/plugin-utils';
3
+
4
+ // Default location to look for navigation.yaml in host project
5
+ const HOST_CONFIG_PATH = path.resolve(process.cwd(), 'config/navigation.yaml');
6
+
7
+ function getNavElements(elements) {
8
+ return elements.map((element) => ({
9
+ ...element,
10
+ path: path.posix.dirname(element.href),
11
+ }));
12
+ }
13
+
14
+ function getMainNav() {
15
+ const navConfig = getConfig(HOST_CONFIG_PATH);
16
+
17
+ navConfig.activeClass = navConfig.active_class || 'active';
18
+ navConfig.activePathClass = navConfig.active_path_class || 'active-path';
19
+ navConfig.navClass = navConfig.nav_class || 'nav';
20
+
21
+ if (Array.isArray(navConfig.elements)) {
22
+ navConfig.elements = getNavElements(navConfig.elements);
23
+ } else {
24
+ for (const key in navConfig.elements) {
25
+ navConfig[key] = {
26
+ className: `${key}-${navConfig.navClass}`,
27
+ elements: getNavElements(navConfig.elements[key]),
28
+ };
29
+ }
30
+ }
31
+
32
+ return navConfig;
33
+ }
34
+
35
+ export function getAppData(data) {
36
+ if (data.app && typeof data.app === 'object') {
37
+ return {
38
+ ...data.app,
39
+ nav: getMainNav(),
40
+ };
41
+ }
42
+
43
+ return data.app;
44
+ }
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@nera-static/plugin-navigation",
3
+ "version": "2.0.0",
4
+ "description": "A plugin for Nera static site generator to generate navigations with optional templates and mixins.",
5
+ "main": "index.js",
6
+ "type": "module",
7
+ "exports": {
8
+ ".": "./index.js"
9
+ },
10
+ "files": [
11
+ "config",
12
+ "index.js",
13
+ "views"
14
+ ],
15
+ "keywords": [
16
+ "nera",
17
+ "plugin",
18
+ "navigation",
19
+ "static-site",
20
+ "mixin",
21
+ "template"
22
+ ],
23
+ "author": "Michael Becker",
24
+ "license": "MIT",
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "https://github.com/seebaermichi/nera-plugin-navigation.git"
28
+ },
29
+ "bugs": {
30
+ "url": "https://github.com/seebaermichi/nera-plugin-navigation/issues"
31
+ },
32
+ "homepage": "https://github.com/seebaermichi/nera-plugin-navigation#readme",
33
+ "dependencies": {
34
+ "@nera-static/plugin-utils": "^1.0.3"
35
+ },
36
+ "engines": {
37
+ "node": ">=18"
38
+ },
39
+ "devDependencies": {
40
+ "cheerio": "^1.1.0",
41
+ "pug": "^3.0.3",
42
+ "vitest": "^3.2.4"
43
+ },
44
+ "scripts": {
45
+ "test": "vitest"
46
+ },
47
+ "sideEffects": false
48
+ }
@@ -0,0 +1,2 @@
1
+ mixin link(item, activeClass, activePathClass)
2
+ a(href=item.href, class=`${activeClass}${activePathClass}`) #{ item.name }
@@ -0,0 +1,6 @@
1
+ each item, index in elements || app.nav.elements
2
+ - const isActive = item.href === meta.fullPath
3
+ - const activeClass = isActive ? app.nav.activeClass : ''
4
+ - const isNotHome = meta.dirname !== '/'
5
+ - const isParent = isNotHome && item.href.indexOf(meta.dirname) === 0
6
+ - const activePathClass = !isActive && isParent ? app.nav.activePathClass : ''
@@ -0,0 +1,3 @@
1
+ include partials/link-list-navigation
2
+
3
+ +linkListNav
@@ -0,0 +1,7 @@
1
+ include ../helper/mixins
2
+
3
+ mixin linkListNav(elements=app.nav.elements, className='')
4
+ ul.nav(class=`${className}`)
5
+ include ../helper/setup
6
+ li.nav-item
7
+ +link(item, activeClass, activePathClass)
@@ -0,0 +1,8 @@
1
+ include ../helper/mixins
2
+
3
+ mixin pipeSeparatedNav(elements=app.nav.elements, className='')
4
+ nav(class=`${className}`)
5
+ include ../helper/setup
6
+ if index !== 0
7
+ |  | 
8
+ +link(item, activeClass, activePathClass)
@@ -0,0 +1,6 @@
1
+ include ../helper/mixins
2
+
3
+ mixin simpleNav(elements=app.nav.elements, className='')
4
+ nav(class=`${className}`)
5
+ include ../helper/setup
6
+ +link(item, activeClass, activePathClass)
@@ -0,0 +1,3 @@
1
+ include partials/pipe-separated-navigation
2
+
3
+ +pipeSeparatedNav
@@ -0,0 +1,3 @@
1
+ include partials/simple-navigation
2
+
3
+ +simpleNav