@nera-static/plugin-navigation 2.0.0 → 2.0.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 +33 -20
- package/index.js +13 -13
- package/package.json +7 -4
package/README.md
CHANGED
|
@@ -2,6 +2,18 @@
|
|
|
2
2
|
|
|
3
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
4
|
|
|
5
|
+
## ✨ Features
|
|
6
|
+
|
|
7
|
+
- Define one or more navigations via YAML config
|
|
8
|
+
- Access navigation data in your templates (`app.nav`)
|
|
9
|
+
- Support for multi-level navigations (e.g. main, footer)
|
|
10
|
+
- Includes built-in Pug templates and mixins for rendering:
|
|
11
|
+
- Pipe-separated links
|
|
12
|
+
- Link lists
|
|
13
|
+
- Mixin-powered flexible layout
|
|
14
|
+
- Automatic active/path highlighting support
|
|
15
|
+
- Zero-runtime, static navigation structure
|
|
16
|
+
|
|
5
17
|
## 🚀 Installation
|
|
6
18
|
|
|
7
19
|
You can install this plugin by running the following in the root folder of your Nera project:
|
|
@@ -27,16 +39,16 @@ Example `navigation/config/navigation.yaml`:
|
|
|
27
39
|
|
|
28
40
|
```yaml
|
|
29
41
|
elements:
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
42
|
+
- href: /index.html
|
|
43
|
+
name: Home
|
|
44
|
+
- href: /service/service.html
|
|
45
|
+
name: Service
|
|
46
|
+
- href: /prices.html
|
|
47
|
+
name: Prices
|
|
48
|
+
- href: /contact.html
|
|
49
|
+
name: Contact
|
|
50
|
+
- href: /about-us/index.html
|
|
51
|
+
name: About us
|
|
40
52
|
```
|
|
41
53
|
|
|
42
54
|
Access it in your templates via:
|
|
@@ -49,14 +61,14 @@ app.nav.elements
|
|
|
49
61
|
|
|
50
62
|
```yaml
|
|
51
63
|
elements:
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
64
|
+
main:
|
|
65
|
+
- href: /index.html
|
|
66
|
+
name: Home
|
|
67
|
+
- href: /service/service.html
|
|
68
|
+
name: Service
|
|
69
|
+
footer:
|
|
70
|
+
- href: /imprint.html
|
|
71
|
+
name: Imprint
|
|
60
72
|
```
|
|
61
73
|
|
|
62
74
|
Use:
|
|
@@ -83,8 +95,9 @@ include ../../src/plugins/navigation/views/simple-navigation
|
|
|
83
95
|
```
|
|
84
96
|
|
|
85
97
|
Other available templates:
|
|
86
|
-
|
|
87
|
-
-
|
|
98
|
+
|
|
99
|
+
- `pipe-separated-navigation.pug`
|
|
100
|
+
- `link-list-navigation.pug`
|
|
88
101
|
|
|
89
102
|
### Built-in Mixins
|
|
90
103
|
|
package/index.js
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
import path from 'path'
|
|
2
|
-
import { getConfig } from '@nera-static/plugin-utils'
|
|
1
|
+
import path from 'path'
|
|
2
|
+
import { getConfig } from '@nera-static/plugin-utils'
|
|
3
3
|
|
|
4
4
|
// Default location to look for navigation.yaml in host project
|
|
5
|
-
const HOST_CONFIG_PATH = path.resolve(process.cwd(), 'config/navigation.yaml')
|
|
5
|
+
const HOST_CONFIG_PATH = path.resolve(process.cwd(), 'config/navigation.yaml')
|
|
6
6
|
|
|
7
7
|
function getNavElements(elements) {
|
|
8
8
|
return elements.map((element) => ({
|
|
9
9
|
...element,
|
|
10
10
|
path: path.posix.dirname(element.href),
|
|
11
|
-
}))
|
|
11
|
+
}))
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
function getMainNav() {
|
|
15
|
-
const navConfig = getConfig(HOST_CONFIG_PATH)
|
|
15
|
+
const navConfig = getConfig(HOST_CONFIG_PATH)
|
|
16
16
|
|
|
17
|
-
navConfig.activeClass = navConfig.active_class || 'active'
|
|
18
|
-
navConfig.activePathClass = navConfig.active_path_class || 'active-path'
|
|
19
|
-
navConfig.navClass = navConfig.nav_class || 'nav'
|
|
17
|
+
navConfig.activeClass = navConfig.active_class || 'active'
|
|
18
|
+
navConfig.activePathClass = navConfig.active_path_class || 'active-path'
|
|
19
|
+
navConfig.navClass = navConfig.nav_class || 'nav'
|
|
20
20
|
|
|
21
21
|
if (Array.isArray(navConfig.elements)) {
|
|
22
|
-
navConfig.elements = getNavElements(navConfig.elements)
|
|
22
|
+
navConfig.elements = getNavElements(navConfig.elements)
|
|
23
23
|
} else {
|
|
24
24
|
for (const key in navConfig.elements) {
|
|
25
25
|
navConfig[key] = {
|
|
26
26
|
className: `${key}-${navConfig.navClass}`,
|
|
27
27
|
elements: getNavElements(navConfig.elements[key]),
|
|
28
|
-
}
|
|
28
|
+
}
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
return navConfig
|
|
32
|
+
return navConfig
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
export function getAppData(data) {
|
|
@@ -37,8 +37,8 @@ export function getAppData(data) {
|
|
|
37
37
|
return {
|
|
38
38
|
...data.app,
|
|
39
39
|
nav: getMainNav(),
|
|
40
|
-
}
|
|
40
|
+
}
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
return data.app
|
|
43
|
+
return data.app
|
|
44
44
|
}
|
package/package.json
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nera-static/plugin-navigation",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "A plugin for Nera static site generator to generate navigations with optional templates and mixins.",
|
|
5
5
|
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"lint": "eslint .",
|
|
8
|
+
"test": "vitest"
|
|
9
|
+
},
|
|
6
10
|
"type": "module",
|
|
7
11
|
"exports": {
|
|
8
12
|
".": "./index.js"
|
|
@@ -38,11 +42,10 @@
|
|
|
38
42
|
},
|
|
39
43
|
"devDependencies": {
|
|
40
44
|
"cheerio": "^1.1.0",
|
|
45
|
+
"eslint": "^9.31.0",
|
|
46
|
+
"husky": "^9.1.7",
|
|
41
47
|
"pug": "^3.0.3",
|
|
42
48
|
"vitest": "^3.2.4"
|
|
43
49
|
},
|
|
44
|
-
"scripts": {
|
|
45
|
-
"test": "vitest"
|
|
46
|
-
},
|
|
47
50
|
"sideEffects": false
|
|
48
51
|
}
|