cec-nuxt-lib 0.3.13 → 0.4.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/dist/module.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "cec-nuxt-lib",
3
3
  "configKey": "cec-nuxt-lib",
4
- "version": "0.3.13"
4
+ "version": "0.4.0"
5
5
  }
@@ -1,21 +1,22 @@
1
1
  <script setup lang="ts">
2
2
  import { useState } from '#app';
3
- import { useRuntimeConfig } from '#app';
4
3
  import { useRoute } from 'vue-router';
5
4
 
6
5
  const classicPath = useState('classicPath');
7
- const config = useRuntimeConfig();
8
- const path = useState('path');
9
6
  const route = useRoute();
10
- const baseUrl = config.app.baseURL;
11
7
 
12
- const trimPath = (str) => str && str.replace(/\/$/, '');
13
- let baseLength = baseUrl ? trimPath(baseUrl).split('/').length : 0;
8
+ const trimPath = (str) => {
9
+ if (str === '/' || !str) {
10
+ return str;
11
+ }
12
+ return str.replace(/\/$/, '');
13
+ };
14
14
 
15
15
  const makeLink = (i, routes) => {
16
- i = baseUrl ? baseLength - i : i + 1;
17
- let l = routes.slice(0, i).join('/');
18
- return l === '' ? '/' : l;
16
+ if (!i) {
17
+ return '/';
18
+ }
19
+ return '/' + routes.slice(0, i).join('/');
19
20
  };
20
21
 
21
22
  const toTitleCase = (str) => {
@@ -25,8 +26,8 @@ const toTitleCase = (str) => {
25
26
  };
26
27
 
27
28
  const makeArr = (str) => {
28
- return str.split('/').reduce((acc, e, i) => {
29
- if (!i || (i && e.length)) {
29
+ return str.split('/').reduce((acc, e) => {
30
+ if (e.length) {
30
31
  return [...acc, e];
31
32
  }
32
33
  return acc;
@@ -35,25 +36,15 @@ const makeArr = (str) => {
35
36
 
36
37
  // Make arrays of the items in the paths
37
38
  let routeTrim = trimPath(route.path);
38
- let pathTrim = trimPath(path.value);
39
39
  let routes = makeArr(routeTrim);
40
- let paths = makeArr(pathTrim);
41
- //console.log(routes)
42
-
43
- // Use the route path if it includes the node's path
44
- if (!routeTrim.toLowerCase().startsWith(pathTrim.toLowerCase())) {
45
- routes = [...paths, ...routes.filter((e) => e.length)];
46
- }
47
40
 
48
41
  // Get the classic path for legacy links
49
42
  let classic = trimPath(classicPath.value).split('/');
50
43
  const length = classic.length;
51
- let hrefs =
52
- baseUrl.length > 1 && route.path !== '/'
53
- ? `${classicPath.value}${routeTrim}`.split('/')
54
- : routes.reduce((acc, e, i) => {
55
- return classic[i] ? [...acc, classic[i]] : [...acc, e];
56
- }, []);
44
+
45
+ let hrefs = `${classicPath.value}${routeTrim === '/' ? '' : routeTrim}`.split(
46
+ '/'
47
+ );
57
48
  const links = hrefs.map((e, i) => (!i ? 'Home' : toTitleCase(e)));
58
49
  </script>
59
50
  <template>
@@ -66,7 +57,9 @@ const links = hrefs.map((e, i) => (!i ? 'Home' : toTitleCase(e)));
66
57
  <li class="breadcrumb-item" v-for="(l, i) in links" :key="i">
67
58
  <span v-if="i === links.length - 1">{{ l }}</span>
68
59
  <template v-else-if="i + 1 >= length">
69
- <NuxtLink :to="makeLink(i, routes)">{{ l }}</NuxtLink>
60
+ <NuxtLink :to="makeLink(i - length + 1, routes)">{{
61
+ l
62
+ }}</NuxtLink>
70
63
  </template>
71
64
  <a v-else :href="'/' + hrefs.slice(1, i + 1).join('/')">
72
65
  {{ l }}</a
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.3.13",
2
+ "version": "0.4.0",
3
3
  "name": "cec-nuxt-lib",
4
4
  "description": "Nuxt components and assets",
5
5
  "license": "MIT",