eleventy-plugin-nav 0.0.1 → 0.0.3

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.
@@ -1,6 +1,7 @@
1
1
  {% if trail.length > 0 %}
2
2
  <nav class="breadcrumbs">
3
3
  {% for ancestor in trail %}
4
+ <li>
4
5
  <a href="{{ ancestor.page.url }}">{{ ancestor.data.title }}</a>
5
6
  {% if ancestor.data.siblings.length > 1 %}
6
7
  <ul class="siblings">
@@ -9,5 +10,7 @@
9
10
  {% endfor %}
10
11
  </ul>
11
12
  {% endif %}
13
+ </li>
12
14
  {% endfor %}
15
+ </nav>
13
16
  {% endif %}
@@ -1,5 +1,5 @@
1
1
  <ul>
2
2
  {% for page in collection.roots %}
3
- {% include './sidebar-item.njk' %}
3
+ {% include './item.njk' %}
4
4
  {% endfor %}
5
5
  </ul>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eleventy-plugin-nav",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "description": "Description",
5
5
  "keywords": [
6
6
  "eleventy-plugin"
package/src/config.js CHANGED
@@ -2,7 +2,7 @@
2
2
  * Default options
3
3
  */
4
4
  export const defaultConfig = {
5
- hidden: page => page.data.unlisted,
5
+ hidden: page => page.data?.unlisted,
6
6
  sort: { "data.order": 1, "data.title": "" },
7
7
  };
8
8
 
@@ -1,5 +1,4 @@
1
1
  import { getCollectionItemFromUrl } from "./util.js";
2
- import config from "../config.js";
3
2
 
4
3
  /** @typedef {import("@11ty/eleventy").CollectionItem} CollectionItem */
5
4
 
@@ -26,11 +25,6 @@ export function parentUrl (data) {
26
25
  let { parent, page } = data;
27
26
  let ret = getParentUrl(page.url, parent);
28
27
 
29
- if (config.ignoreAncestor?.(ret)) {
30
- let ancestorItem = getCollectionItemFromUrl(ret, data);
31
- return ancestorItem.parentUrl;
32
- }
33
-
34
28
  return ret;
35
29
  }
36
30
 
@@ -7,7 +7,7 @@ import { getCollectionItemFromUrl } from "./util.js";
7
7
  * @returns {CollectionItem[]}
8
8
  **/
9
9
  export function allSiblings (data) {
10
- return data.parentItem?.children ?? data.collections.roots ?? [];
10
+ return data.parentItem ? data.parentItem.children : data.collections.roots;
11
11
  }
12
12
 
13
13
  /**
@@ -15,9 +15,22 @@ export function allSiblings (data) {
15
15
  * @returns { number }
16
16
  **/
17
17
  export function siblingIndex (data) {
18
- let { url, allSiblings } = data;
18
+ let { page, allSiblings } = data;
19
+ let { url } = page;
20
+
21
+ if (!allSiblings) {
22
+ return -1;
23
+ }
24
+
19
25
  let currentItem = getCollectionItemFromUrl(url, data);
20
- return allSiblings.indexOf(currentItem) ?? -1;
26
+ let index = allSiblings.indexOf(currentItem);
27
+
28
+ if (index === -1) {
29
+ // Try another way
30
+ index = allSiblings.findIndex(item => item.url === url);
31
+ }
32
+
33
+ return index;
21
34
  }
22
35
 
23
36
  /**
@@ -26,7 +39,7 @@ export function siblingIndex (data) {
26
39
  **/
27
40
  export function siblingsBefore (data) {
28
41
  let { allSiblings, siblingIndex } = data;
29
- return siblingIndex > -1 ? allSiblings.slice(0, siblingIndex) : [];
42
+ return siblingIndex > -1 ? allSiblings.slice(0, siblingIndex) : allSiblings;
30
43
  }
31
44
 
32
45
  /**
@@ -35,7 +48,7 @@ export function siblingsBefore (data) {
35
48
  **/
36
49
  export function siblingsAfter (data) {
37
50
  let { allSiblings, siblingIndex } = data;
38
- return siblingIndex > -1 ? allSiblings.slice(siblingIndex) : [];
51
+ return siblingIndex > -1 ? allSiblings.slice(siblingIndex + 1) : allSiblings;
39
52
  }
40
53
 
41
54
  /**
@@ -43,8 +56,13 @@ export function siblingsAfter (data) {
43
56
  * @returns {CollectionItem[]}
44
57
  **/
45
58
  export function siblings (data) {
46
- let { siblingsBefore, siblingsAfter } = data;
47
- return [...siblingsBefore, ...siblingsAfter];
59
+ let { siblingIndex, siblingsBefore, siblingsAfter } = data;
60
+
61
+ if (siblingIndex > -1) {
62
+ return [...siblingsBefore, ...siblingsAfter];
63
+ }
64
+
65
+ return allSiblings;
48
66
  }
49
67
 
50
68
  export function nextPage (data) {
@@ -8,7 +8,7 @@ export function hidden (data) {
8
8
  ret = toArray(config.hidden).some(hidden => hidden(data.page));
9
9
  }
10
10
 
11
- return;
11
+ return ret;
12
12
  }
13
13
 
14
14
  export function shown (data) {
package/src/data.js CHANGED
@@ -6,3 +6,4 @@ export * from "./data/parent.js";
6
6
  export * from "./data/children.js";
7
7
  export * from "./data/ancestors.js";
8
8
  export * from "./data/siblings.js";
9
+ export * from "./data/visible.js";