eleventy-plugin-nav 0.0.4 → 0.0.6
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 +0 -2
- package/package.json +6 -6
- package/src/data/ancestors.js +2 -2
- package/src/data/areas.js +6 -5
- package/src/data/children.js +3 -1
- package/src/data/parent.js +7 -7
- package/src/data/siblings.js +17 -58
- package/src/data/visible.js +3 -1
- package/.editorconfig +0 -8
- package/.prettierrc.json +0 -17
- package/_includes/previous-next.njk +0 -15
package/README.md
CHANGED
|
@@ -109,8 +109,6 @@ such as indices, navbars, breadcrumbs and the like.
|
|
|
109
109
|
| `trail` | `CollectionItem[]` | Array of a page's ancestors, excluding the root |
|
|
110
110
|
| `siblingIndex` | `number` | The index of the current page among its parent’s children. `-1` if no parent. |
|
|
111
111
|
| `siblings` | `CollectionItem[]` | Other pages by the same parent. Excludes current page. |
|
|
112
|
-
| `nextPage` | `CollectionItem` | The page that comes before the current page in the parent's children |
|
|
113
|
-
| `previousPage` | `CollectionItem` | The page that comes after the current page in the parent's children |
|
|
114
112
|
| `hidden` | `boolean` | Whether the page should be included in listings |
|
|
115
113
|
| `shown` | `boolean` | Whether the page should be included in listings |
|
|
116
114
|
| `rootItem` | `CollectionItem` | The item of the page’s homepage. |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eleventy-plugin-nav",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"description": "Description",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"eleventy-plugin"
|
|
@@ -18,14 +18,14 @@
|
|
|
18
18
|
"type": "module",
|
|
19
19
|
"main": "src/index.js",
|
|
20
20
|
"scripts": {
|
|
21
|
-
"release": "release-it",
|
|
21
|
+
"release": "npm whoami >/dev/null 2>&1 || npm login && release-it",
|
|
22
22
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"prettier-plugin-brace-style": "^0.
|
|
26
|
-
"prettier-plugin-merge": "^0.
|
|
27
|
-
"prettier-plugin-space-before-function-paren": "^0.0
|
|
28
|
-
"release-it": "^
|
|
25
|
+
"prettier-plugin-brace-style": "^0.10.4",
|
|
26
|
+
"prettier-plugin-merge": "^0.10.2",
|
|
27
|
+
"prettier-plugin-space-before-function-paren": "^0.1.0",
|
|
28
|
+
"release-it": "^21.1.3"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
31
|
"@11ty/eleventy": "^3"
|
package/src/data/ancestors.js
CHANGED
|
@@ -7,7 +7,7 @@ import { getCollectionItemFromUrl } from "../util.js";
|
|
|
7
7
|
* @returns {CollectionItem[]}
|
|
8
8
|
*/
|
|
9
9
|
export function lineage (data) {
|
|
10
|
-
let
|
|
10
|
+
let page = data.page;
|
|
11
11
|
let url = page.url;
|
|
12
12
|
let ret = [];
|
|
13
13
|
let currentItem = getCollectionItemFromUrl(url, data);
|
|
@@ -32,7 +32,7 @@ export function lineage (data) {
|
|
|
32
32
|
* @returns {CollectionItem[]}
|
|
33
33
|
*/
|
|
34
34
|
export function trail (data) {
|
|
35
|
-
let
|
|
35
|
+
let page = data.page;
|
|
36
36
|
let url = page.url;
|
|
37
37
|
let ret = data.lineage;
|
|
38
38
|
|
package/src/data/areas.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getCollectionItemFromUrl } from "../util.js";
|
|
2
2
|
import config from "../config.js";
|
|
3
3
|
|
|
4
|
-
export function areaItems(data) {
|
|
4
|
+
export function areaItems (data) {
|
|
5
5
|
if (!data.collections.all?.length) {
|
|
6
6
|
// First pass
|
|
7
7
|
return undefined;
|
|
@@ -14,8 +14,8 @@ export function areaItems(data) {
|
|
|
14
14
|
return config.areas.map(area => getCollectionItemFromUrl(area, data)).filter(Boolean);
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
export function areaUrl(data) {
|
|
18
|
-
let
|
|
17
|
+
export function areaUrl (data) {
|
|
18
|
+
let lineage = data.lineage;
|
|
19
19
|
|
|
20
20
|
if (data.areaUrl) {
|
|
21
21
|
return data.areaUrl;
|
|
@@ -34,8 +34,9 @@ export function areaUrl(data) {
|
|
|
34
34
|
return lineage?.find?.(item => areas.has(item.page.url))?.page.url;
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
export function areaItem(data) {
|
|
38
|
-
let
|
|
37
|
+
export function areaItem (data) {
|
|
38
|
+
let areaUrl = data.areaUrl;
|
|
39
|
+
let rootItem = data.rootItem;
|
|
39
40
|
|
|
40
41
|
return areaUrl ? getCollectionItemFromUrl(areaUrl, data) : rootItem;
|
|
41
42
|
}
|
package/src/data/children.js
CHANGED
|
@@ -8,7 +8,9 @@ import { parentUrl as getParentUrl, parentItem as getParentItem } from "./parent
|
|
|
8
8
|
* @returns {CollectionItem[]} Array of child pages
|
|
9
9
|
*/
|
|
10
10
|
export function children (data) {
|
|
11
|
-
let
|
|
11
|
+
let collections = data.collections;
|
|
12
|
+
let page = data.page;
|
|
13
|
+
let parentOf = data.parentOf;
|
|
12
14
|
|
|
13
15
|
if (parentOf) {
|
|
14
16
|
return collections[parentOf];
|
package/src/data/parent.js
CHANGED
|
@@ -12,7 +12,8 @@ export function rootItem (data) {
|
|
|
12
12
|
* @returns {string | undefined}
|
|
13
13
|
*/
|
|
14
14
|
export function parent (data) {
|
|
15
|
-
let
|
|
15
|
+
let parent = data.parent;
|
|
16
|
+
let page = data.page;
|
|
16
17
|
|
|
17
18
|
if (parent) {
|
|
18
19
|
return parent;
|
|
@@ -30,13 +31,11 @@ export function parent (data) {
|
|
|
30
31
|
* @returns {CollectionItem | null} Parent page item
|
|
31
32
|
*/
|
|
32
33
|
export function parentItem (data) {
|
|
33
|
-
let
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
// Root page
|
|
37
|
-
return null;
|
|
38
|
-
}
|
|
34
|
+
let parent = data.parent;
|
|
35
|
+
let page = data.page;
|
|
36
|
+
let collections = data.collections;
|
|
39
37
|
|
|
38
|
+
// Eleventy waits for collections only if this reads `collections.all` before any return
|
|
40
39
|
if (!collections.all?.length) {
|
|
41
40
|
// First pass, cannot be computed yet
|
|
42
41
|
return undefined;
|
|
@@ -45,6 +44,7 @@ export function parentItem (data) {
|
|
|
45
44
|
let parentUrl = getParentUrl(page.url, parent);
|
|
46
45
|
|
|
47
46
|
if (!parentUrl) {
|
|
47
|
+
// Root page, or a page without a URL
|
|
48
48
|
return null;
|
|
49
49
|
}
|
|
50
50
|
|
package/src/data/siblings.js
CHANGED
|
@@ -7,6 +7,13 @@ import { getCollectionItemFromUrl } from "../util.js";
|
|
|
7
7
|
* @returns {CollectionItem[]}
|
|
8
8
|
**/
|
|
9
9
|
export function allSiblings (data) {
|
|
10
|
+
data.children;
|
|
11
|
+
|
|
12
|
+
if (data.page.url === "/") {
|
|
13
|
+
// `/` is the root of the tree, so it has no siblings. `roots` lists its children
|
|
14
|
+
return [];
|
|
15
|
+
}
|
|
16
|
+
|
|
10
17
|
return data.parentItem ? data.parentItem.children : data.collections.roots;
|
|
11
18
|
}
|
|
12
19
|
|
|
@@ -15,19 +22,22 @@ export function allSiblings (data) {
|
|
|
15
22
|
* @returns { number }
|
|
16
23
|
**/
|
|
17
24
|
export function siblingIndex (data) {
|
|
18
|
-
|
|
19
|
-
|
|
25
|
+
data.children;
|
|
26
|
+
data.allSiblings ||= data.parentItem?.data?.children;
|
|
20
27
|
|
|
21
|
-
|
|
28
|
+
let page = data.page;
|
|
29
|
+
let url = page.url;
|
|
30
|
+
|
|
31
|
+
if (!data.allSiblings) {
|
|
22
32
|
return -1;
|
|
23
33
|
}
|
|
24
34
|
|
|
25
35
|
let currentItem = getCollectionItemFromUrl(url, data);
|
|
26
|
-
let index = allSiblings.indexOf(currentItem);
|
|
36
|
+
let index = data.allSiblings.indexOf(currentItem);
|
|
27
37
|
|
|
28
38
|
if (index === -1) {
|
|
29
39
|
// Try another way
|
|
30
|
-
index = allSiblings.findIndex(
|
|
40
|
+
index = data.allSiblings.findIndex(
|
|
31
41
|
item =>
|
|
32
42
|
(url && item.url === url) ||
|
|
33
43
|
(page.inputPath && item.page.inputPath === page.inputPath),
|
|
@@ -37,48 +47,13 @@ export function siblingIndex (data) {
|
|
|
37
47
|
return index;
|
|
38
48
|
}
|
|
39
49
|
|
|
40
|
-
/**
|
|
41
|
-
* Other pages by the same parent that come before the current page.
|
|
42
|
-
* @returns {CollectionItem[]}
|
|
43
|
-
**/
|
|
44
|
-
export function siblingsBefore (data) {
|
|
45
|
-
let { allSiblings, siblingIndex } = data;
|
|
46
|
-
|
|
47
|
-
if (siblingIndex > -1) {
|
|
48
|
-
return allSiblings.slice(0, siblingIndex);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
if (allSiblings) {
|
|
52
|
-
return [...allSiblings];
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return [];
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Other pages by the same parent that come after the current page.
|
|
60
|
-
* @returns {CollectionItem[]}
|
|
61
|
-
**/
|
|
62
|
-
export function siblingsAfter (data) {
|
|
63
|
-
let { allSiblings, siblingIndex } = data;
|
|
64
|
-
|
|
65
|
-
if (siblingIndex > -1) {
|
|
66
|
-
return allSiblings.slice(siblingIndex + 1);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
if (allSiblings) {
|
|
70
|
-
return [...allSiblings];
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
return [];
|
|
74
|
-
}
|
|
75
|
-
|
|
76
50
|
/**
|
|
77
51
|
* Other pages by the same parent. Excludes current page.
|
|
78
52
|
* @returns {CollectionItem[]}
|
|
79
53
|
**/
|
|
80
54
|
export function siblings (data) {
|
|
81
|
-
let
|
|
55
|
+
let siblingIndex = data.siblingIndex;
|
|
56
|
+
let allSiblings = data.allSiblings;
|
|
82
57
|
|
|
83
58
|
if (!allSiblings) {
|
|
84
59
|
return [];
|
|
@@ -92,19 +67,3 @@ export function siblings (data) {
|
|
|
92
67
|
|
|
93
68
|
return ret;
|
|
94
69
|
}
|
|
95
|
-
|
|
96
|
-
export function nextPage (data) {
|
|
97
|
-
while (data && data.parentItem && !data.siblingsAfter[0]) {
|
|
98
|
-
data = data.parentItem.data;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
return data?.siblingsAfter[0];
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
export function previousPage (data) {
|
|
105
|
-
while (data && data.parentItem && !data.siblingsBefore.at(-1)) {
|
|
106
|
-
data = data.parentItem.data;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
return data?.siblingsBefore.at(-1);
|
|
110
|
-
}
|
package/src/data/visible.js
CHANGED
|
@@ -5,7 +5,9 @@ export function hidden (data) {
|
|
|
5
5
|
let ret = true;
|
|
6
6
|
|
|
7
7
|
if (config.hidden) {
|
|
8
|
-
|
|
8
|
+
// `hidden` expects a collection item, but computed data has only `page` and `data`
|
|
9
|
+
let item = { ...data.page, page: data.page, data };
|
|
10
|
+
ret = toArray(config.hidden).some(hidden => hidden.call(this, item));
|
|
9
11
|
}
|
|
10
12
|
|
|
11
13
|
return ret;
|
package/.editorconfig
DELETED
package/.prettierrc.json
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"plugins": [
|
|
3
|
-
"prettier-plugin-brace-style",
|
|
4
|
-
"prettier-plugin-space-before-function-paren",
|
|
5
|
-
"prettier-plugin-merge"
|
|
6
|
-
],
|
|
7
|
-
"braceStyle": "stroustrup",
|
|
8
|
-
"arrowParens": "avoid",
|
|
9
|
-
"bracketSpacing": true,
|
|
10
|
-
"endOfLine": "auto",
|
|
11
|
-
"semi": true,
|
|
12
|
-
"singleQuote": false,
|
|
13
|
-
"tabWidth": 4,
|
|
14
|
-
"useTabs": true,
|
|
15
|
-
"trailingComma": "all",
|
|
16
|
-
"printWidth": 100
|
|
17
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
<nav class="prev-next">
|
|
2
|
-
{% if previousPage -%}
|
|
3
|
-
<a class="previous" href="{{ previousPage.url }}">
|
|
4
|
-
<span class="desc">Previous page</span>
|
|
5
|
-
<span class="title">{{ previousPage.data.title }}</span>
|
|
6
|
-
</a>
|
|
7
|
-
{%- endif %}
|
|
8
|
-
|
|
9
|
-
{% if nextPage -%}
|
|
10
|
-
<a class="next" href="{{ nextPage.url }}">
|
|
11
|
-
<span class="desc">Previous page</span>
|
|
12
|
-
<span class="title">{{ nextPage.data.title }}</span>
|
|
13
|
-
</a>
|
|
14
|
-
{%- endif %}
|
|
15
|
-
</nav>
|