nextjs-link-preview 1.0.2 → 1.0.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/bin/setup.js CHANGED
@@ -76,13 +76,18 @@ function setupApiRoute() {
76
76
  process.exit(1);
77
77
  }
78
78
 
79
+ // Detect if project uses src/app or app directory structure
80
+ const hasSrcApp = fs.existsSync(path.join(cwd, "src", "app"));
81
+ const appDir = hasSrcApp ? path.join(cwd, "src", "app") : path.join(cwd, "app");
82
+ const relativePath = hasSrcApp ? "src/app/api/preview/route.ts" : "app/api/preview/route.ts";
83
+
79
84
  // Create the API route directory structure
80
- const apiRoutePath = path.join(cwd, "app", "api", "preview");
85
+ const apiRoutePath = path.join(appDir, "api", "preview");
81
86
  const routeFilePath = path.join(apiRoutePath, "route.ts");
82
87
 
83
88
  // Check if route already exists
84
89
  if (fs.existsSync(routeFilePath)) {
85
- console.log("⚠️ API route already exists at app/api/preview/route.ts");
90
+ console.log(`⚠️ API route already exists at ${relativePath}`);
86
91
  console.log("To reinstall, delete the existing file and run this command again.");
87
92
  process.exit(0);
88
93
  }
@@ -93,7 +98,7 @@ function setupApiRoute() {
93
98
  // Write the route file
94
99
  fs.writeFileSync(routeFilePath, API_ROUTE_CONTENT);
95
100
 
96
- console.log("✅ Successfully created API route at app/api/preview/route.ts");
101
+ console.log(`✅ Successfully created API route at ${relativePath}`);
97
102
  console.log("");
98
103
  console.log("📦 Make sure you have the required dependencies:");
99
104
  console.log(" npm install axios cheerio");
@@ -0,0 +1,37 @@
1
+ import React from 'react';
2
+
3
+ /**
4
+ * Next.js Link Preview Component
5
+ *
6
+ * This component uses the Next.js API route to fetch metadata server-side,
7
+ * avoiding CORS issues entirely.
8
+ *
9
+ * Usage:
10
+ * import { LinkPreview } from './components/LinkPreview';
11
+ *
12
+ * <LinkPreview url="https://github.com" size="medium" />
13
+ */
14
+
15
+ interface LinkPreviewData {
16
+ title: string;
17
+ description: string;
18
+ image: string;
19
+ url: string;
20
+ }
21
+ type LinkPreviewSize = 'small' | 'medium' | 'large';
22
+ type LinkPreviewLayout = 'vertical' | 'horizontal';
23
+ interface LinkPreviewProps {
24
+ url: string;
25
+ size?: LinkPreviewSize;
26
+ layout?: LinkPreviewLayout;
27
+ width?: string | number;
28
+ height?: string | number;
29
+ className?: string;
30
+ onError?: (error: Error) => void;
31
+ onLoad?: (data: LinkPreviewData) => void;
32
+ apiEndpoint?: string;
33
+ }
34
+ declare function LinkPreview({ url, size, layout, width, height, className, onError, onLoad, apiEndpoint }: LinkPreviewProps): React.JSX.Element | null;
35
+
36
+ export { LinkPreview, LinkPreview as default };
37
+ export type { LinkPreviewData, LinkPreviewLayout, LinkPreviewProps, LinkPreviewSize };
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LinkPreview.d.ts","sourceRoot":"","sources":["../../../../src/nextjs/components/LinkPreview.tsx"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AAEH,OAAO,KAA8B,MAAM,OAAO,CAAC;AAEnD,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;CACb;AAED,MAAM,MAAM,eAAe,GAAG,OAAO,GAAG,QAAQ,GAAG,OAAO,CAAC;AAC3D,MAAM,MAAM,iBAAiB,GAAG,UAAU,GAAG,YAAY,CAAC;AAE1D,MAAM,WAAW,gBAAgB;IAC/B,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,eAAe,CAAC;IACvB,MAAM,CAAC,EAAE,iBAAiB,CAAC;IAC3B,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACzB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACjC,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,eAAe,KAAK,IAAI,CAAC;IACzC,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AA6BD,wBAAgB,WAAW,CAAC,EAC1B,GAAG,EACH,IAAe,EACf,MAAmB,EACnB,KAAc,EACd,MAAe,EACf,SAAc,EACd,OAAO,EACP,MAAM,EACN,WAA4B,EAC7B,EAAE,gBAAgB,4BA8IlB;AAED,eAAe,WAAW,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nextjs-link-preview",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "type": "module",
5
5
  "description": "A Next.js component for generating beautiful link preview cards with server-side metadata fetching - No CORS issues!",
6
6
  "keywords": [
@@ -62,6 +62,7 @@
62
62
  "@types/react": "^19.2.2",
63
63
  "@types/react-dom": "^19.2.2",
64
64
  "rollup": "^4.53.1",
65
+ "rollup-plugin-dts": "^6.2.3",
65
66
  "rollup-plugin-peer-deps-external": "^2.2.4",
66
67
  "tslib": "^2.8.1",
67
68
  "typescript": "^5.9.3"
@@ -1 +0,0 @@
1
- {"version":3,"file":"LinkPreview.d.ts","sourceRoot":"","sources":["../../../src/nextjs/components/LinkPreview.tsx"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AAEH,OAAO,KAA8B,MAAM,OAAO,CAAC;AAEnD,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;CACb;AAED,MAAM,MAAM,eAAe,GAAG,OAAO,GAAG,QAAQ,GAAG,OAAO,CAAC;AAC3D,MAAM,MAAM,iBAAiB,GAAG,UAAU,GAAG,YAAY,CAAC;AAE1D,MAAM,WAAW,gBAAgB;IAC/B,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,eAAe,CAAC;IACvB,MAAM,CAAC,EAAE,iBAAiB,CAAC;IAC3B,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACzB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACjC,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,eAAe,KAAK,IAAI,CAAC;IACzC,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AA6BD,wBAAgB,WAAW,CAAC,EAC1B,GAAG,EACH,IAAe,EACf,MAAmB,EACnB,KAAc,EACd,MAAe,EACf,SAAc,EACd,OAAO,EACP,MAAM,EACN,WAA4B,EAC7B,EAAE,gBAAgB,4BA8IlB;AAED,eAAe,WAAW,CAAC"}