astro-better-cards 1.0.0 → 1.0.1

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/CardGrid.astro ADDED
@@ -0,0 +1,17 @@
1
+ ---
2
+ interface Props {
3
+ columns?: 1 | 2 | 3 | 4;
4
+ }
5
+
6
+ const { columns = 2 } = Astro.props;
7
+ const colClasses: Record<number, string> = {
8
+ 1: 'grid-cols-1',
9
+ 2: 'grid-cols-1 lg:grid-cols-2',
10
+ 3: 'grid-cols-1 md:grid-cols-2 lg:grid-cols-3',
11
+ 4: 'grid-cols-1 md:grid-cols-2 lg:grid-cols-4',
12
+ };
13
+ const colClass = colClasses[columns] ?? colClasses[2];
14
+ ---
15
+ <div class={`gap-6 mt-6 mb-6 grid ${colClass} not-prose`} xmlns="http://www.w3.org/1999/xhtml">
16
+ <slot />
17
+ </div>
package/ChildCards.astro CHANGED
@@ -117,7 +117,7 @@ const colClass = colClasses[columns] ?? colClasses[2];
117
117
 
118
118
  async function pageToItem(p: any): Promise<NavItem> {
119
119
  return {
120
- href: `/${stripExt(p.id).replace(/\/index$/, '')}`,
120
+ href: `/${collection}/${stripExt(p.id).replace(/\/index$/, '')}`,
121
121
  title: await md(p.data.title) as string,
122
122
  description: p.data.description,
123
123
  icon: p.data.icon ?? null,
package/PageNav.astro CHANGED
@@ -18,11 +18,17 @@ function stripExt(id: string): string {
18
18
  }
19
19
 
20
20
  const pathname = Astro.url.pathname.replace(/^\/+|\/+$/g, '').replace(/\.html$/, '');
21
- const currentFolder = pathname.includes('/') ? pathname.replace(/\/[^/]+$/, '') : '';
21
+ // strip the collection URL prefix so the remainder matches bare entry IDs
22
+ const pathnameRelative = pathname.startsWith(`${collection}/`)
23
+ ? pathname.slice(collection.length + 1)
24
+ : pathname;
25
+ const currentFolder = pathnameRelative.includes('/')
26
+ ? pathnameRelative.replace(/\/[^/]+$/, '')
27
+ : '';
22
28
 
23
29
  const currentEntry = (pages as any[]).find(p => {
24
30
  const cid = stripExt(p.id);
25
- return cid === pathname || cid === `${pathname}/index`;
31
+ return cid === pathnameRelative || cid === `${pathnameRelative}/index`;
26
32
  });
27
33
 
28
34
  const prevPath = prevProp ?? currentEntry?.data.prev;
@@ -40,7 +46,7 @@ function findPage(href: string) {
40
46
 
41
47
  function makeHref(href: string): string {
42
48
  if (href.startsWith('/')) return href;
43
- return `/${currentFolder ? `${currentFolder}/` : ''}${href}`;
49
+ return `/${collection}/${currentFolder ? `${currentFolder}/` : ''}${href}`;
44
50
  }
45
51
 
46
52
  let prevEntry = prevPath ? findPage(prevPath) : null;
@@ -64,11 +70,11 @@ if (!prevEntry || !nextEntry) {
64
70
  const idx = siblings.findIndex(p => stripExt(p.id) === pathname);
65
71
  if (idx > 0 && !prevEntry) {
66
72
  prevEntry = siblings[idx - 1];
67
- prevHref = `/${stripExt(prevEntry.id).replace(/\/index$/, '')}`;
73
+ prevHref = `/${collection}/${stripExt(prevEntry.id).replace(/\/index$/, '')}`;
68
74
  }
69
75
  if (idx >= 0 && idx < siblings.length - 1 && !nextEntry) {
70
76
  nextEntry = siblings[idx + 1];
71
- nextHref = `/${stripExt(nextEntry.id).replace(/\/index$/, '')}`;
77
+ nextHref = `/${collection}/${stripExt(nextEntry.id).replace(/\/index$/, '')}`;
72
78
  }
73
79
  }
74
80
 
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "astro-better-cards",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  "./Card.astro": "./Card.astro",
7
+ "./CardGrid.astro": "./CardGrid.astro",
7
8
  "./ChildCards.astro": "./ChildCards.astro",
8
9
  "./PageNav.astro": "./PageNav.astro"
9
10
  },