astro-better-cards 0.2.2 → 0.2.4

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/Card.astro CHANGED
@@ -10,6 +10,8 @@ const {
10
10
  comingSoon = false,
11
11
  label,
12
12
  labelFirst = false,
13
+ version,
14
+ badges,
13
15
  } = Astro.props;
14
16
  ---
15
17
  {variant === 'full' && (
@@ -20,6 +22,13 @@ const {
20
22
  {darkIcon && <img class="hidden dark:block w-14 h-14 object-contain shrink-0" src={darkIcon} alt="" aria-hidden="true" />}
21
23
  <div>
22
24
  <p class="font-bold group-hover:text-indigo-500 pb-1 text-xl sm:leading-tight sm:pb-2 sm:text-lg md:text-xl lg:text-2xl 2xl:leading-tight" set:html={title}></p>
25
+ {(version || (badges && badges.length > 0)) && (
26
+ <p class="flex items-center gap-1.5 text-xs text-slate-400 dark:text-slate-500 mb-1.5">
27
+ {version && <span>v{version}</span>}
28
+ {version && badges && badges.length > 0 && <span>&mdash;</span>}
29
+ {badges && badges.map((b: string) => <span class={`badge badge-${b}`}>{b}</span>)}
30
+ </p>
31
+ )}
23
32
  {description && <p class="font-normal lg:leading-4 sm:leading-4 text-sm">{description}</p>}
24
33
  </div>
25
34
  </div>
package/ChildCards.astro CHANGED
@@ -34,7 +34,11 @@ if (folder !== undefined) {
34
34
  }
35
35
  } else {
36
36
  const pathname = Astro.url.pathname.replace(/^\/+|\/+$/g, '').replace(/\.html$/, '');
37
- prefix = pathname.startsWith(`${collection}/`) ? pathname.slice(collection.length + 1) : pathname;
37
+ if (pathname === '' || pathname === collection) {
38
+ prefix = '';
39
+ } else {
40
+ prefix = pathname.startsWith(`${collection}/`) ? pathname.slice(collection.length + 1) : pathname;
41
+ }
38
42
  }
39
43
  prefix = prefix.replace(/^\/+|\/+$/g, '');
40
44
 
@@ -52,6 +56,10 @@ function isDirectChild(id: string): boolean {
52
56
 
53
57
  function isGrandchildPage(id: string): boolean {
54
58
  const cid = stripExt(id);
59
+ if (!prefix) {
60
+ const parts = cid.split('/');
61
+ return parts.length === 2 && parts[1] !== 'index';
62
+ }
55
63
  if (!cid.startsWith(`${prefix}/`)) return false;
56
64
  const rem = cid.slice(prefix.length + 1);
57
65
  const parts = rem.split('/');
@@ -59,6 +67,7 @@ function isGrandchildPage(id: string): boolean {
59
67
  }
60
68
 
61
69
  function getSubfolder(id: string): string {
70
+ if (!prefix) return stripExt(id).split('/')[0];
62
71
  return stripExt(id).slice(prefix.length + 1).split('/')[0];
63
72
  }
64
73
 
@@ -74,6 +83,8 @@ type NavItem = {
74
83
  icon?: string | null;
75
84
  darkIcon?: string;
76
85
  cardImage?: string;
86
+ version?: string;
87
+ badges?: string[];
77
88
  };
78
89
 
79
90
  type NavGroup = { title: string; order: number; items: NavItem[] };
@@ -91,13 +102,16 @@ if (depth === 1) {
91
102
  icon: p.data.icon ?? null,
92
103
  darkIcon: p.data.darkIcon,
93
104
  cardImage: p.data.cardImage,
105
+ version: p.data.version,
106
+ badges: p.data.badges,
94
107
  })));
95
108
  } else {
96
109
  const grandchildren = valid.filter(p => isGrandchildPage(p.id));
97
110
  const subfolderNames = [...new Set(grandchildren.map(p => getSubfolder(p.id)))];
98
111
 
99
112
  groups = await Promise.all(subfolderNames.map(async sf => {
100
- const indexEntry = (pages as any[]).find(p => stripExt(p.id) === `${prefix}/${sf}/index`);
113
+ const indexPath = prefix ? `${prefix}/${sf}/index` : `${sf}/index`;
114
+ const indexEntry = (pages as any[]).find(p => stripExt(p.id) === indexPath);
101
115
  const sectionTitle: string = indexEntry
102
116
  ? await md(indexEntry.data.title)
103
117
  : sf.replace(/-/g, ' ').replace(/\b\w/g, (c: string) => c.toUpperCase());
@@ -116,6 +130,8 @@ if (depth === 1) {
116
130
  icon: p.data.icon ?? null,
117
131
  darkIcon: p.data.darkIcon,
118
132
  cardImage: p.data.cardImage,
133
+ version: p.data.version,
134
+ badges: p.data.badges,
119
135
  }))),
120
136
  };
121
137
  }));
@@ -128,7 +144,8 @@ if (depth === 1) {
128
144
  <div class="gap-6 mt-6 mb-6 grid grid-cols-1 not-prose lg:grid-cols-2" xmlns="http://www.w3.org/1999/xhtml">
129
145
  {items.map(item => (
130
146
  <Card href={item.href} title={item.title} description={item.description}
131
- icon={item.icon} darkIcon={item.darkIcon} cardImage={item.cardImage} variant="full" />
147
+ icon={item.icon} darkIcon={item.darkIcon} cardImage={item.cardImage}
148
+ version={item.version} badges={item.badges} variant="full" />
132
149
  ))}
133
150
  </div>
134
151
  ) : (
@@ -139,7 +156,8 @@ if (depth === 1) {
139
156
  <div class="gap-6 grid grid-cols-1 not-prose lg:grid-cols-2" xmlns="http://www.w3.org/1999/xhtml">
140
157
  {group.items.map(item => (
141
158
  <Card href={item.href} title={item.title} description={item.description}
142
- icon={item.icon} darkIcon={item.darkIcon} cardImage={item.cardImage} variant="full" />
159
+ icon={item.icon} darkIcon={item.darkIcon} cardImage={item.cardImage}
160
+ version={item.version} badges={item.badges} variant="full" />
143
161
  ))}
144
162
  </div>
145
163
  </Fragment>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro-better-cards",
3
- "version": "0.2.2",
3
+ "version": "0.2.4",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  "./Card.astro": "./Card.astro",