astro-better-cards 0.2.4 → 0.2.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.
Files changed (2) hide show
  1. package/ChildCards.astro +14 -9
  2. package/package.json +1 -1
package/ChildCards.astro CHANGED
@@ -20,9 +20,9 @@ if (folder !== undefined) {
20
20
  const noSlash = folder.replace(/^\/+/, '');
21
21
  prefix = noSlash.startsWith(`${collection}/`) ? noSlash.slice(collection.length + 1) : noSlash;
22
22
  } else if (folder.startsWith('./') || folder.startsWith('../')) {
23
- const pathname = Astro.url.pathname.replace(/^\/+|\/+$/g, '').replace(/\.html$/, '');
23
+ const pathname = Astro.url.pathname.replace(/^\/+|\/+\(/g, '').replace(/\.html\)/, '');
24
24
  const pagePrefix = pathname.startsWith(`${collection}/`) ? pathname.slice(collection.length + 1) : pathname;
25
- const pageFolder = pagePrefix.includes('/') ? pagePrefix.replace(/\/[^/]+$/, '') : '';
25
+ const pageFolder = pagePrefix.includes('/') ? pagePrefix.replace(/\/[^/]+\$/, '') : '';
26
26
  const parts = pageFolder ? pageFolder.split('/') : [];
27
27
  for (const seg of folder.split('/')) {
28
28
  if (seg === '..') parts.pop();
@@ -33,17 +33,17 @@ if (folder !== undefined) {
33
33
  prefix = folder;
34
34
  }
35
35
  } else {
36
- const pathname = Astro.url.pathname.replace(/^\/+|\/+$/g, '').replace(/\.html$/, '');
36
+ const pathname = Astro.url.pathname.replace(/^\/+|\/+\(/g, '').replace(/\.html\)/, '');
37
37
  if (pathname === '' || pathname === collection) {
38
38
  prefix = '';
39
39
  } else {
40
40
  prefix = pathname.startsWith(`${collection}/`) ? pathname.slice(collection.length + 1) : pathname;
41
41
  }
42
42
  }
43
- prefix = prefix.replace(/^\/+|\/+$/g, '');
43
+ prefix = prefix.replace(/^\/+|\/+\$/g, '');
44
44
 
45
45
  function stripExt(id: string): string {
46
- return id.replace(/\.(md|mdx)$/i, '');
46
+ return id.replace(/\.(md|mdx)\$/i, '');
47
47
  }
48
48
 
49
49
  function isDirectChild(id: string): boolean {
@@ -96,7 +96,8 @@ if (depth === 1) {
96
96
  const children = valid.filter(p => isDirectChild(p.id));
97
97
  children.sort((a, b) => (a.data.order ?? 1000) - (b.data.order ?? 1000) || a.data.title.localeCompare(b.data.title));
98
98
  items = await Promise.all(children.map(async p => ({
99
- href: `/${collection}/${stripExt(p.id).replace(/\/index$/, '')}`,
99
+ // FIX: Replaced `/${collection}/` with a single `/`
100
+ href: `/${stripExt(p.id).replace(/\/index$/, '')}`,
100
101
  title: await md(p.data.title),
101
102
  description: p.data.description,
102
103
  icon: p.data.icon ?? null,
@@ -110,8 +111,11 @@ if (depth === 1) {
110
111
  const subfolderNames = [...new Set(grandchildren.map(p => getSubfolder(p.id)))];
111
112
 
112
113
  groups = await Promise.all(subfolderNames.map(async sf => {
113
- const indexPath = prefix ? `${prefix}/${sf}/index` : `${sf}/index`;
114
- const indexEntry = (pages as any[]).find(p => stripExt(p.id) === indexPath);
114
+ const indexId = prefix ? `${prefix}/${sf}` : sf;
115
+ const indexEntry = (pages as any[]).find(p => {
116
+ const cid = stripExt(p.id);
117
+ return cid === indexId || cid === `${indexId}/index`;
118
+ });
115
119
  const sectionTitle: string = indexEntry
116
120
  ? await md(indexEntry.data.title)
117
121
  : sf.replace(/-/g, ' ').replace(/\b\w/g, (c: string) => c.toUpperCase());
@@ -124,7 +128,8 @@ if (depth === 1) {
124
128
  title: sectionTitle,
125
129
  order: sectionOrder,
126
130
  items: await Promise.all(sfItems.map(async p => ({
127
- href: `/${collection}/${stripExt(p.id)}`,
131
+ // FIX: Replaced `/${collection}/` with a single `/`
132
+ href: `/${stripExt(p.id)}`,
128
133
  title: await md(p.data.title),
129
134
  description: p.data.description,
130
135
  icon: p.data.icon ?? null,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro-better-cards",
3
- "version": "0.2.4",
3
+ "version": "0.2.6",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  "./Card.astro": "./Card.astro",