rehype-og-card 0.4.2 → 1.0.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/README.md CHANGED
@@ -150,6 +150,13 @@ Domains to exclude from conversion.
150
150
  - Type: `"eager" | "lazy"`
151
151
  - Default: `"lazy"`
152
152
 
153
+ ### `openInNewTab`
154
+
155
+ Whether to open the link in a new tab.
156
+
157
+ - Type: `boolean`
158
+ - Default: `false`
159
+
153
160
  ### `serverCache`
154
161
 
155
162
  Whether to cache the OG data on the server.
package/dist/index.js CHANGED
@@ -24,6 +24,7 @@ const DEFAULT_OPTIONS = {
24
24
  enableSameTextURLConversion: false,
25
25
  excludeDomains: [],
26
26
  loading: "lazy",
27
+ openInNewTab: false,
27
28
  serverCache: true,
28
29
  serverCachePath: "./public",
29
30
  shortenURL: true
package/dist/types.d.ts CHANGED
@@ -18,6 +18,11 @@ interface RehypeOGCardOptions {
18
18
  * @default true
19
19
  */
20
20
  shortenURL?: boolean;
21
+ /**
22
+ * Whether to open the link in a new tab.
23
+ * @default false
24
+ */
25
+ openInNewTab?: boolean;
21
26
  /**
22
27
  * Whether to enable converting the links
23
28
  * that have the same URL and text (e.g., `[https://example.com](https://example.com)`).
@@ -33,5 +33,6 @@ declare const convertTextToAnchorElement: (text: Text) => AnchorElement;
33
33
  declare const createOGCard: (data: OGCardData, options: Required<{
34
34
  loading: RehypeOGCardOptions["loading"];
35
35
  decoding: RehypeOGCardOptions["decoding"];
36
+ openInNewTab: RehypeOGCardOptions["openInNewTab"];
36
37
  }>) => Element;
37
38
  export { AnchorElement, isTextNode, isAnchorElement, convertTextToAnchorElement, createOGCard };
package/dist/util/hast.js CHANGED
@@ -32,8 +32,13 @@ const convertTextToAnchorElement = (text) => ({
32
32
  * @returns OG card element.
33
33
  */
34
34
  const createOGCard = (data, options) => {
35
+ const openInNewTab = {
36
+ rel: "noopener noreferrer",
37
+ target: "_blank"
38
+ };
35
39
  const card = h("div.og-card-container", [
36
- h("a", { href: data.url }, [
40
+ // eslint-disable-next-line no-extra-parens
41
+ h("a", Object.assign({ href: data.url }, (options.openInNewTab ? openInNewTab : {})), [
37
42
  h("div.og-card-info", [
38
43
  h("div.og-card-title", data.title),
39
44
  data.description ? h("div.og-card-description", data.description) : null,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rehype-og-card",
3
- "version": "0.4.2",
3
+ "version": "1.0.0",
4
4
  "description": "Rehype plugin to convert text links to link cards",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",