vitepress-linkcard 1.1.3 → 1.2.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
@@ -1,10 +1,12 @@
1
- <h1 align="center">
1
+ <h1 align="center">
2
2
  vitepress-linkcard
3
3
  </h1>
4
4
 
5
5
  <div align="center">
6
6
 
7
- **Slightly more readable README created with this plugin is [here](https://asumoranda.com/posts/10-vitepress-linkcard.html).**
7
+ **A Vitepress plugin to generate a pretty linkcard with OGP.**
8
+
9
+ Slightly more readable README created with this plugin is [here](https://asumoranda.com/posts/10-vitepress-linkcard.html).
8
10
 
9
11
  [![NPM Version](https://img.shields.io/npm/v/vitepress-linkcard?style=flat&logo=npm&logoColor=white&label=npmjs&color=%23CB3837)](https://www.npmjs.com/package/vitepress-linkcard)
10
12
  [![NPM bundle size](https://img.shields.io/bundlephobia/min/vitepress-linkcard)](https://www.npmjs.com/package/vitepress-linkcard)
@@ -19,13 +21,13 @@ vitepress-linkcard
19
21
 
20
22
  <p align="center">
21
23
  <a href="https://github.com/asumo-1xts/vitepress-linkcard/blob/main/image/screen.webp?raw=true">
22
- <img width="85%" src="https://github.com/asumo-1xts/vitepress-linkcard/blob/main/.config/screen.webp?raw=true" />
24
+ <img src="https://github.com/asumo-1xts/vitepress-linkcard/blob/main/.config/screen.webp?raw=true" alt="How it shows"/>
23
25
  </a>
24
26
  </p>
25
27
 
26
28
  <div align="center">
27
29
 
28
- **This plugin was forked from [markdown-it-link-to-card](https://github.com/luckrya/markdown-it-link-to-card).**
30
+ This plugin was forked from [markdown-it-link-to-card](https://github.com/luckrya/markdown-it-link-to-card).
29
31
 
30
32
  </div>
31
33
 
@@ -103,15 +105,15 @@ Specifies the target window in which to open a link.
103
105
 
104
106
  ### `.linkcard_cache.json`
105
107
 
106
- It is generated automatically and cache all the parsed metadata.
108
+ It is generated automatically in root dir and cache all the parsed metadata.
107
109
 
108
- You can edit it as needed, but ignoring it will increase build time.
110
+ You can move it to `.config` directory or edit it if needed.
109
111
 
110
112
  ### Special handling for `github.com`
111
113
 
112
114
  When the domain is `github.com`, trimming is performed as shown in the following example to avoid duplication of the title and description.
115
+
113
116
  | | Title | Description |
114
117
  | - | - | - |
115
118
  | Before | GitHub - asumo-1xts/vitepress-linkcard: A VitePress plugin to generate a pretty linkcard. | A VitePress plugin to generate a pretty linkcard. Contribute to asumo-1xts/vitepress-linkcard development by creating an account on GitHub. |
116
119
  | After | asumo-1xts/vitepress-linkcard | A VitePress plugin to generate a pretty linkcard. |
117
-
package/dist/.cjs.min.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * vitepress-linkcard v1.1.3
2
+ * vitepress-linkcard v1.2.0
3
3
  * (c) 2022 - 2025 luckrya
4
4
  * Released under the MIT License.
5
5
  */
@@ -8,7 +8,7 @@ Object.defineProperty(exports,"__esModule",{value:!0});var e=require("url"),t=re
8
8
  * @luckrya/utility v0.1.0
9
9
  * (c) 2022 - 2022 Y.R
10
10
  * Released under the MIT License.
11
- */(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function m(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:t+""}(c=s||(s={})).Array="[object Array]",c.Object="[object Object]",c.Function="[object Function]",c.Number="[object Number]",c.String="[object String]",c.Boolean="[object Boolean]",c.Undefined="[object Undefined]",c.Null="[object Null]",c.Error="[object Error]";var x=function(e){return Object.prototype.toString.call(e)===s.String},S=function(e){return Object.prototype.toString.call(e)===s.Function},O="undefined"!=typeof window,C=function(){var e="".concat(process.cwd(),"/.linkcard_cache.json");if(!h.default.existsSync(e)){h.default.writeFileSync(e,JSON.stringify({"https://example.com/":{description:"Example Website",logo:"https://example.com/example.png",title:"Example Title"}},null,2))}return e},N=function(){return function(e,t,r){return t&&v(e.prototype,t),r&&v(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}(function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e)},[{key:"setFile",value:function(e){var t=e,r=this.readFile();r&&(t=Object.assign(r,t)),h.default.writeFileSync(C(),JSON.stringify(t)),function(){var e=C(),t=h.default.readFileSync(e,"utf-8").trim();if(t){var r=JSON.parse(t),n=JSON.stringify(r,null,2)+"\n";h.default.writeFileSync(e,n)}}()}},{key:"readFile",value:function(){var e=h.default.readFileSync(C(),"utf-8"),t=JSON.parse(e);if(function(e){return Object.prototype.toString.call(e)===s.Object}(t))return t}},{key:"has",value:function(e){return!!this.get(e)}},{key:"get",value:function(e){var t=this.readFile();return null==t?void 0:t[e]}},{key:"set",value:function(e,t){this.setFile(y({},e,t))}}])}(),k=new N;function T(e){return'style="'.concat(function(e){return Object.entries(e).map(function(e){var t,r=w(e,2),n=r[0],o=r[1];if(n&&o)return"".concat((t=n,t.replace(/\B([A-Z])/g,"-$1").toLowerCase()),": ").concat(o,";")}).filter(Boolean).join(" ")}(e),'"')}var j=function(e){return{"-webkit-box-orient":"vertical","-webkit-line-clamp":e,display:"-webkit-box",hyphens:"auto",lineClamp:e,overflow:"hidden",overflowWrap:"anywhere",textOverflow:"ellipsis",wordBreak:"break-word"}},R=function(e,t){var r,n,o,i,a={rel:'rel="noopener noreferrer"',target:'target="'.concat(t.target,'"'),href:'href="'.concat(t.href,'"'),title:'title="'.concat(t.linkTitle,'"'),borderColor:'borderColor="'.concat(t.borderColor,'"'),bgColor:'bgColor="'.concat(t.bgColor,'"')},s=function(e){return e.replace(/&amp;/g,"&").replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&quot;/g,'"').replace(/&#039;/g,"'")},c=(r=t.borderColor||"#7d7d7dff",n=t.bgColor||"#7d7d7d00",{a:T({color:"unset !important",display:"block",width:"100%",textDecoration:"none"}),container:T({display:"flex",alignItems:"center",flexWrap:"wrap",gap:"10px",borderRadius:"12px",border:"1px solid ".concat(r),backgroundColor:n,boxSizing:"border-box",width:"100%",height:"130px"}),img:T({borderRadius:"0px 12px 12px 0px",maxWidth:"40%",height:"128px",flexShrink:0,objectFit:"contain",overflow:"hidden"}),texts:T({flex:"1 1 0%",minWidth:"0"}),title:T(E(E({},j(2)),{},{opacity:1,fontSize:"16px",lineHeight:"22px",margin:"0 16px 8px 16px",fontWeight:"bold"})),domain:T(E(E({},j(1)),{},{opacity:1,fontSize:"12px",lineHeight:"16px",margin:"8px 16px 8px 16px",textDecoration:"underline"})),description:T(E(E({},j(2)),{},{opacity:.8,fontSize:"12px",lineHeight:"16px",margin:"8px 16px 0px 16px"}))}),l=t.href||"",u=new URL(l).origin.replace(/^https?:\/\//,"").replace(/^www\./,"")||"Unknown domain",d=e.title,f=e.description;"github.com"==u?(d=(null===(o=e.title)||void 0===o?void 0:o.split(":")[0].replace("GitHub - ",""))||"No title",f=(null===(i=f)||void 0===i?void 0:i.replace(" - ".concat(d),"").replace("Contribute to ".concat(d," development by creating an account on GitHub."),""))||""):(d=e.title||"No title",f=e.description||"");return'<span style="display:block;">\n <a '.concat(a.rel," ").concat(a.target," ").concat(a.href," ").concat(a.title," ").concat(c.a,">\n <span ").concat(c.container,">\n <span ").concat(c.texts,">\n <span ").concat(c.title,">\n ").concat(s(d),"\n </span>\n <span ").concat(c.domain,">\n ").concat(s(u),"\n </span>\n <span ").concat(c.description,">\n ").concat(s(f),'\n </span>\n </span>\n <img src="').concat(null==e?void 0:e.logo,'" ').concat(c.img,"/>\n </span>\n </a>\n</span>")};function D(e){return new URL(e)}var A="https://resources.whatwg.org/logo-url.svg",L=/(<[A-Za-z]+\s*[^>]*>(.*)<\/[A-Za-z]+>)/,q=/content=["|']([^>]*)["|']/,P=/href=["|']([^>]*)["|']/,H=/(<title\s*[^>]*>(.*)<\/title>)/g,F=function(e){return new RegExp("<".concat(arguments.length>1&&void 0!==arguments[1]?arguments[1]:"meta","\\s[^>]*\\w+=['|\"]([a-zA-Z]|:|\\s)*").concat(e,"['|\"][^>]*\\/?>"))};function _(e){var t,r=e.match(F("title"));if(null!=r&&r.length){var n=r[0].match(q);n&&x(n[1])&&(t=n[1])}else{var o=e.match(H);if(null!=o&&o.length){var i=o[0].match(L);i&&x(i[2])&&(t=i[2])}}return t}function I(e){var t,r=e.match(F("description"));if(null!=r&&r.length){var n=r[0].match(q);n&&x(n[1])&&(t=n[1])}return t}function U(e){var t,r=e.match(F("image"));if(null!=r&&r.length){var n=r[0].match(q);n&&x(n[1])&&(t=n[1])}else{var o=e.match(F("icon","link"));if(null!=o&&o.length){var i=o[0].match(P);i&&x(i[1])&&(t=i[1])}}return t}function M(e,t){var r,n,o,i={title:_(e),description:I(e),logo:(r=U(e),r?D(r)?r:"".concat(null===(n=D(t))||void 0===n?void 0:n.origin).concat("/".concat(r).replace(/\/\//g,"/")):A)};return o=i,Object.values(o).filter(function(e){return x(e)}).length?i:null}function B(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var J,G={};
11
+ */(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function m(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:t+""}(c=s||(s={})).Array="[object Array]",c.Object="[object Object]",c.Function="[object Function]",c.Number="[object Number]",c.String="[object String]",c.Boolean="[object Boolean]",c.Undefined="[object Undefined]",c.Null="[object Null]",c.Error="[object Error]";var x=function(e){return Object.prototype.toString.call(e)===s.String},S=function(e){return Object.prototype.toString.call(e)===s.Function},O="undefined"!=typeof window,C=function(){var e,t="".concat(process.cwd(),"/.linkcard_cache.json"),r="".concat(process.cwd(),"/.config/.linkcard_cache.json");if(h.default.existsSync(t))e=t;else if(h.default.existsSync(r))e=r;else{e=t;h.default.writeFileSync(e,JSON.stringify({"https://example.com/":{description:"Example Website",logo:"https://example.com/example.png",title:"Example Title"}},null,2))}return e},N=function(){return function(e,t,r){return t&&v(e.prototype,t),r&&v(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}(function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e)},[{key:"setFile",value:function(e){var t=e,r=this.readFile();r&&(t=Object.assign(r,t)),h.default.writeFileSync(C(),JSON.stringify(t)),function(){var e=C(),t=h.default.readFileSync(e,"utf-8").trim();if(t){var r=JSON.parse(t),n=JSON.stringify(r,null,2)+"\n";h.default.writeFileSync(e,n)}}()}},{key:"readFile",value:function(){var e=h.default.readFileSync(C(),"utf-8"),t=JSON.parse(e);if(function(e){return Object.prototype.toString.call(e)===s.Object}(t))return t}},{key:"has",value:function(e){return!!this.get(e)}},{key:"get",value:function(e){var t=this.readFile();return null==t?void 0:t[e]}},{key:"set",value:function(e,t){this.setFile(y({},e,t))}}])}(),k=new N;function T(e){return'style="'.concat(function(e){return Object.entries(e).map(function(e){var t,r=w(e,2),n=r[0],o=r[1];if(n&&o)return"".concat((t=n,t.replace(/\B([A-Z])/g,"-$1").toLowerCase()),": ").concat(o,";")}).filter(Boolean).join(" ")}(e),'"')}var j=function(e){return{"-webkit-box-orient":"vertical","-webkit-line-clamp":e,display:"-webkit-box",hyphens:"auto",lineClamp:e,overflow:"hidden",overflowWrap:"anywhere",textOverflow:"ellipsis",wordBreak:"break-word"}},R=function(e,t){var r,n,o,i,a={rel:'rel="noopener noreferrer"',target:'target="'.concat(t.target,'"'),href:'href="'.concat(t.href,'"'),title:'title="'.concat(t.linkTitle,'"'),borderColor:'borderColor="'.concat(t.borderColor,'"'),bgColor:'bgColor="'.concat(t.bgColor,'"')},s=function(e){return e.replace(/&amp;/g,"&").replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&quot;/g,'"').replace(/&#039;/g,"'")},c=(r=t.borderColor||"#7d7d7dff",n=t.bgColor||"#7d7d7d00",{a:T({color:"unset !important",display:"block",width:"100%",textDecoration:"none"}),container:T({display:"flex",alignItems:"center",flexWrap:"wrap",gap:"10px",borderRadius:"12px",border:"1px solid ".concat(r),backgroundColor:n,boxSizing:"border-box",width:"100%",height:"130px"}),img:T({borderRadius:"0px 12px 12px 0px",maxWidth:"40%",height:"128px",flexShrink:0,objectFit:"contain",overflow:"hidden"}),texts:T({flex:"1 1 0%",minWidth:"0"}),title:T(E(E({},j(2)),{},{opacity:1,fontSize:"16px",lineHeight:"22px",margin:"0 16px 8px 16px",fontWeight:"bold"})),domain:T(E(E({},j(1)),{},{opacity:1,fontSize:"12px",lineHeight:"16px",margin:"8px 16px 8px 16px",textDecoration:"underline"})),description:T(E(E({},j(2)),{},{opacity:.8,fontSize:"12px",lineHeight:"16px",margin:"8px 16px 0px 16px"}))}),l=t.href||"",u=new URL(l).origin.replace(/^https?:\/\//,"").replace(/^www\./,"")||"Unknown domain",d=e.title,f=e.description;"github.com"==u?(d=(null===(o=e.title)||void 0===o?void 0:o.split(":")[0].replace("GitHub - ",""))||"No title",f=(null===(i=f)||void 0===i?void 0:i.replace(" - ".concat(d),"").replace("Contribute to ".concat(d," development by creating an account on GitHub."),""))||""):(d=e.title||"No title",f=e.description||"");return'<span style="display:block;">\n <a '.concat(a.rel," ").concat(a.target," ").concat(a.href," ").concat(a.title," ").concat(c.a,">\n <span ").concat(c.container,">\n <span ").concat(c.texts,">\n <span ").concat(c.title,">\n ").concat(s(d),"\n </span>\n <span ").concat(c.domain,">\n ").concat(s(u),"\n </span>\n <span ").concat(c.description,">\n ").concat(s(f),'\n </span>\n </span>\n <img src="').concat(null==e?void 0:e.logo,'" ').concat(c.img,"/>\n </span>\n </a>\n</span>")};function D(e){return new URL(e)}var A="https://resources.whatwg.org/logo-url.svg",L=/(<[A-Za-z]+\s*[^>]*>(.*)<\/[A-Za-z]+>)/,q=/content=["|']([^>]*)["|']/,P=/href=["|']([^>]*)["|']/,H=/(<title\s*[^>]*>(.*)<\/title>)/g,F=function(e){return new RegExp("<".concat(arguments.length>1&&void 0!==arguments[1]?arguments[1]:"meta","\\s[^>]*\\w+=['|\"]([a-zA-Z]|:|\\s)*").concat(e,"['|\"][^>]*\\/?>"))};function _(e){var t,r=e.match(F("title"));if(null!=r&&r.length){var n=r[0].match(q);n&&x(n[1])&&(t=n[1])}else{var o=e.match(H);if(null!=o&&o.length){var i=o[0].match(L);i&&x(i[2])&&(t=i[2])}}return t}function I(e){var t,r=e.match(F("description"));if(null!=r&&r.length){var n=r[0].match(q);n&&x(n[1])&&(t=n[1])}return t}function U(e){var t,r=e.match(F("image"));if(null!=r&&r.length){var n=r[0].match(q);n&&x(n[1])&&(t=n[1])}else{var o=e.match(F("icon","link"));if(null!=o&&o.length){var i=o[0].match(P);i&&x(i[1])&&(t=i[1])}}return t}function M(e,t){var r,n,o,i={title:_(e),description:I(e),logo:(r=U(e),r?D(r)?r:"".concat(null===(n=D(t))||void 0===n?void 0:n.origin).concat("/".concat(r).replace(/\/\//g,"/")):A)};return o=i,Object.values(o).filter(function(e){return x(e)}).length?i:null}function B(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var J,G={};
12
12
  /**
13
13
  * Wrapper for built-in http.js to emulate the browser XMLHttpRequest object.
14
14
  *
package/dist/.esm.min.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * vitepress-linkcard v1.1.3
2
+ * vitepress-linkcard v1.2.0
3
3
  * (c) 2022 - 2025 luckrya
4
4
  * Released under the MIT License.
5
5
  */
@@ -8,7 +8,7 @@ import e from"url";import t from"child_process";import r from"fs";import n from"
8
8
  * @luckrya/utility v0.1.0
9
9
  * (c) 2022 - 2022 Y.R
10
10
  * Released under the MIT License.
11
- */(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function d(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:t+""}var p,h;(h=p||(p={})).Array="[object Array]",h.Object="[object Object]",h.Function="[object Function]",h.Number="[object Number]",h.String="[object String]",h.Boolean="[object Boolean]",h.Undefined="[object Undefined]",h.Null="[object Null]",h.Error="[object Error]";var g=function(e){return Object.prototype.toString.call(e)===p.String},v=function(e){return Object.prototype.toString.call(e)===p.Function},y="undefined"!=typeof window,b=function(){var e="".concat(process.cwd(),"/.linkcard_cache.json");if(!i.existsSync(e)){i.writeFileSync(e,JSON.stringify({"https://example.com/":{description:"Example Website",logo:"https://example.com/example.png",title:"Example Title"}},null,2))}return e},m=function(){return function(e,t,r){return t&&s(e.prototype,t),r&&s(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}(function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e)},[{key:"setFile",value:function(e){var t=e,r=this.readFile();r&&(t=Object.assign(r,t)),i.writeFileSync(b(),JSON.stringify(t)),function(){var e=b(),t=i.readFileSync(e,"utf-8").trim();if(t){var r=JSON.parse(t),n=JSON.stringify(r,null,2)+"\n";i.writeFileSync(e,n)}}()}},{key:"readFile",value:function(){var e=i.readFileSync(b(),"utf-8"),t=JSON.parse(e);if(function(e){return Object.prototype.toString.call(e)===p.Object}(t))return t}},{key:"has",value:function(e){return!!this.get(e)}},{key:"get",value:function(e){var t=this.readFile();return null==t?void 0:t[e]}},{key:"set",value:function(e,t){this.setFile(c({},e,t))}}])}(),E=new m;function w(e){return'style="'.concat(function(e){return Object.entries(e).map(function(e){var t,r=f(e,2),n=r[0],o=r[1];if(n&&o)return"".concat((t=n,t.replace(/\B([A-Z])/g,"-$1").toLowerCase()),": ").concat(o,";")}).filter(Boolean).join(" ")}(e),'"')}var x=function(e){return{"-webkit-box-orient":"vertical","-webkit-line-clamp":e,display:"-webkit-box",hyphens:"auto",lineClamp:e,overflow:"hidden",overflowWrap:"anywhere",textOverflow:"ellipsis",wordBreak:"break-word"}},S=function(e,t){var r,n,o,i,a={rel:'rel="noopener noreferrer"',target:'target="'.concat(t.target,'"'),href:'href="'.concat(t.href,'"'),title:'title="'.concat(t.linkTitle,'"'),borderColor:'borderColor="'.concat(t.borderColor,'"'),bgColor:'bgColor="'.concat(t.bgColor,'"')},s=function(e){return e.replace(/&amp;/g,"&").replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&quot;/g,'"').replace(/&#039;/g,"'")},c=(r=t.borderColor||"#7d7d7dff",n=t.bgColor||"#7d7d7d00",{a:w({color:"unset !important",display:"block",width:"100%",textDecoration:"none"}),container:w({display:"flex",alignItems:"center",flexWrap:"wrap",gap:"10px",borderRadius:"12px",border:"1px solid ".concat(r),backgroundColor:n,boxSizing:"border-box",width:"100%",height:"130px"}),img:w({borderRadius:"0px 12px 12px 0px",maxWidth:"40%",height:"128px",flexShrink:0,objectFit:"contain",overflow:"hidden"}),texts:w({flex:"1 1 0%",minWidth:"0"}),title:w(u(u({},x(2)),{},{opacity:1,fontSize:"16px",lineHeight:"22px",margin:"0 16px 8px 16px",fontWeight:"bold"})),domain:w(u(u({},x(1)),{},{opacity:1,fontSize:"12px",lineHeight:"16px",margin:"8px 16px 8px 16px",textDecoration:"underline"})),description:w(u(u({},x(2)),{},{opacity:.8,fontSize:"12px",lineHeight:"16px",margin:"8px 16px 0px 16px"}))}),l=t.href||"",f=new URL(l).origin.replace(/^https?:\/\//,"").replace(/^www\./,"")||"Unknown domain",d=e.title,p=e.description;"github.com"==f?(d=(null===(o=e.title)||void 0===o?void 0:o.split(":")[0].replace("GitHub - ",""))||"No title",p=(null===(i=p)||void 0===i?void 0:i.replace(" - ".concat(d),"").replace("Contribute to ".concat(d," development by creating an account on GitHub."),""))||""):(d=e.title||"No title",p=e.description||"");return'<span style="display:block;">\n <a '.concat(a.rel," ").concat(a.target," ").concat(a.href," ").concat(a.title," ").concat(c.a,">\n <span ").concat(c.container,">\n <span ").concat(c.texts,">\n <span ").concat(c.title,">\n ").concat(s(d),"\n </span>\n <span ").concat(c.domain,">\n ").concat(s(f),"\n </span>\n <span ").concat(c.description,">\n ").concat(s(p),'\n </span>\n </span>\n <img src="').concat(null==e?void 0:e.logo,'" ').concat(c.img,"/>\n </span>\n </a>\n</span>")};function O(e){return new URL(e)}var C="https://resources.whatwg.org/logo-url.svg",N=/(<[A-Za-z]+\s*[^>]*>(.*)<\/[A-Za-z]+>)/,k=/content=["|']([^>]*)["|']/,T=/href=["|']([^>]*)["|']/,j=/(<title\s*[^>]*>(.*)<\/title>)/g,R=function(e){return new RegExp("<".concat(arguments.length>1&&void 0!==arguments[1]?arguments[1]:"meta","\\s[^>]*\\w+=['|\"]([a-zA-Z]|:|\\s)*").concat(e,"['|\"][^>]*\\/?>"))};function D(e){var t,r=e.match(R("title"));if(null!=r&&r.length){var n=r[0].match(k);n&&g(n[1])&&(t=n[1])}else{var o=e.match(j);if(null!=o&&o.length){var i=o[0].match(N);i&&g(i[2])&&(t=i[2])}}return t}function A(e){var t,r=e.match(R("description"));if(null!=r&&r.length){var n=r[0].match(k);n&&g(n[1])&&(t=n[1])}return t}function L(e){var t,r=e.match(R("image"));if(null!=r&&r.length){var n=r[0].match(k);n&&g(n[1])&&(t=n[1])}else{var o=e.match(R("icon","link"));if(null!=o&&o.length){var i=o[0].match(T);i&&g(i[1])&&(t=i[1])}}return t}function P(e,t){var r,n,o,i={title:D(e),description:A(e),logo:(r=L(e),r?O(r)?r:"".concat(null===(n=O(t))||void 0===n?void 0:n.origin).concat("/".concat(r).replace(/\/\//g,"/")):C)};return o=i,Object.values(o).filter(function(e){return g(e)}).length?i:null}function q(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var H,F={};
11
+ */(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function d(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:t+""}var p,h;(h=p||(p={})).Array="[object Array]",h.Object="[object Object]",h.Function="[object Function]",h.Number="[object Number]",h.String="[object String]",h.Boolean="[object Boolean]",h.Undefined="[object Undefined]",h.Null="[object Null]",h.Error="[object Error]";var g=function(e){return Object.prototype.toString.call(e)===p.String},v=function(e){return Object.prototype.toString.call(e)===p.Function},y="undefined"!=typeof window,b=function(){var e,t="".concat(process.cwd(),"/.linkcard_cache.json"),r="".concat(process.cwd(),"/.config/.linkcard_cache.json");if(i.existsSync(t))e=t;else if(i.existsSync(r))e=r;else{e=t;i.writeFileSync(e,JSON.stringify({"https://example.com/":{description:"Example Website",logo:"https://example.com/example.png",title:"Example Title"}},null,2))}return e},m=function(){return function(e,t,r){return t&&s(e.prototype,t),r&&s(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}(function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e)},[{key:"setFile",value:function(e){var t=e,r=this.readFile();r&&(t=Object.assign(r,t)),i.writeFileSync(b(),JSON.stringify(t)),function(){var e=b(),t=i.readFileSync(e,"utf-8").trim();if(t){var r=JSON.parse(t),n=JSON.stringify(r,null,2)+"\n";i.writeFileSync(e,n)}}()}},{key:"readFile",value:function(){var e=i.readFileSync(b(),"utf-8"),t=JSON.parse(e);if(function(e){return Object.prototype.toString.call(e)===p.Object}(t))return t}},{key:"has",value:function(e){return!!this.get(e)}},{key:"get",value:function(e){var t=this.readFile();return null==t?void 0:t[e]}},{key:"set",value:function(e,t){this.setFile(c({},e,t))}}])}(),E=new m;function w(e){return'style="'.concat(function(e){return Object.entries(e).map(function(e){var t,r=f(e,2),n=r[0],o=r[1];if(n&&o)return"".concat((t=n,t.replace(/\B([A-Z])/g,"-$1").toLowerCase()),": ").concat(o,";")}).filter(Boolean).join(" ")}(e),'"')}var x=function(e){return{"-webkit-box-orient":"vertical","-webkit-line-clamp":e,display:"-webkit-box",hyphens:"auto",lineClamp:e,overflow:"hidden",overflowWrap:"anywhere",textOverflow:"ellipsis",wordBreak:"break-word"}},S=function(e,t){var r,n,o,i,a={rel:'rel="noopener noreferrer"',target:'target="'.concat(t.target,'"'),href:'href="'.concat(t.href,'"'),title:'title="'.concat(t.linkTitle,'"'),borderColor:'borderColor="'.concat(t.borderColor,'"'),bgColor:'bgColor="'.concat(t.bgColor,'"')},s=function(e){return e.replace(/&amp;/g,"&").replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&quot;/g,'"').replace(/&#039;/g,"'")},c=(r=t.borderColor||"#7d7d7dff",n=t.bgColor||"#7d7d7d00",{a:w({color:"unset !important",display:"block",width:"100%",textDecoration:"none"}),container:w({display:"flex",alignItems:"center",flexWrap:"wrap",gap:"10px",borderRadius:"12px",border:"1px solid ".concat(r),backgroundColor:n,boxSizing:"border-box",width:"100%",height:"130px"}),img:w({borderRadius:"0px 12px 12px 0px",maxWidth:"40%",height:"128px",flexShrink:0,objectFit:"contain",overflow:"hidden"}),texts:w({flex:"1 1 0%",minWidth:"0"}),title:w(u(u({},x(2)),{},{opacity:1,fontSize:"16px",lineHeight:"22px",margin:"0 16px 8px 16px",fontWeight:"bold"})),domain:w(u(u({},x(1)),{},{opacity:1,fontSize:"12px",lineHeight:"16px",margin:"8px 16px 8px 16px",textDecoration:"underline"})),description:w(u(u({},x(2)),{},{opacity:.8,fontSize:"12px",lineHeight:"16px",margin:"8px 16px 0px 16px"}))}),l=t.href||"",f=new URL(l).origin.replace(/^https?:\/\//,"").replace(/^www\./,"")||"Unknown domain",d=e.title,p=e.description;"github.com"==f?(d=(null===(o=e.title)||void 0===o?void 0:o.split(":")[0].replace("GitHub - ",""))||"No title",p=(null===(i=p)||void 0===i?void 0:i.replace(" - ".concat(d),"").replace("Contribute to ".concat(d," development by creating an account on GitHub."),""))||""):(d=e.title||"No title",p=e.description||"");return'<span style="display:block;">\n <a '.concat(a.rel," ").concat(a.target," ").concat(a.href," ").concat(a.title," ").concat(c.a,">\n <span ").concat(c.container,">\n <span ").concat(c.texts,">\n <span ").concat(c.title,">\n ").concat(s(d),"\n </span>\n <span ").concat(c.domain,">\n ").concat(s(f),"\n </span>\n <span ").concat(c.description,">\n ").concat(s(p),'\n </span>\n </span>\n <img src="').concat(null==e?void 0:e.logo,'" ').concat(c.img,"/>\n </span>\n </a>\n</span>")};function O(e){return new URL(e)}var C="https://resources.whatwg.org/logo-url.svg",N=/(<[A-Za-z]+\s*[^>]*>(.*)<\/[A-Za-z]+>)/,k=/content=["|']([^>]*)["|']/,T=/href=["|']([^>]*)["|']/,j=/(<title\s*[^>]*>(.*)<\/title>)/g,R=function(e){return new RegExp("<".concat(arguments.length>1&&void 0!==arguments[1]?arguments[1]:"meta","\\s[^>]*\\w+=['|\"]([a-zA-Z]|:|\\s)*").concat(e,"['|\"][^>]*\\/?>"))};function D(e){var t,r=e.match(R("title"));if(null!=r&&r.length){var n=r[0].match(k);n&&g(n[1])&&(t=n[1])}else{var o=e.match(j);if(null!=o&&o.length){var i=o[0].match(N);i&&g(i[2])&&(t=i[2])}}return t}function A(e){var t,r=e.match(R("description"));if(null!=r&&r.length){var n=r[0].match(k);n&&g(n[1])&&(t=n[1])}return t}function L(e){var t,r=e.match(R("image"));if(null!=r&&r.length){var n=r[0].match(k);n&&g(n[1])&&(t=n[1])}else{var o=e.match(R("icon","link"));if(null!=o&&o.length){var i=o[0].match(T);i&&g(i[1])&&(t=i[1])}}return t}function P(e,t){var r,n,o,i={title:D(e),description:A(e),logo:(r=L(e),r?O(r)?r:"".concat(null===(n=O(t))||void 0===n?void 0:n.origin).concat("/".concat(r).replace(/\/\//g,"/")):C)};return o=i,Object.values(o).filter(function(e){return g(e)}).length?i:null}function q(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var H,F={};
12
12
  /**
13
13
  * Wrapper for built-in http.js to emulate the browser XMLHttpRequest object.
14
14
  *
@@ -20,4 +20,4 @@ import e from"url";import t from"child_process";import r from"fs";import n from"
20
20
  * @author Dan DeFelippi <dan@driverdan.com>
21
21
  * @contributor David Ellis <d.f.ellis@ieee.org>
22
22
  * @license MIT
23
- */var I=function(){if(H)return F;H=1;var i=e,a=t.spawn,s=r;return F.XMLHttpRequest=function(){var e,t,r=this,c=n,l=o,u={},f=!1,d={"User-Agent":"node-XMLHttpRequest",Accept:"*/*"},p={},h={},g=["accept-charset","accept-encoding","access-control-request-headers","access-control-request-method","connection","content-length","content-transfer-encoding","cookie","cookie2","date","expect","host","keep-alive","origin","referer","te","trailer","transfer-encoding","upgrade","via"],v=["TRACE","TRACK","CONNECT"],y=!1,b=!1,m={};this.UNSENT=0,this.OPENED=1,this.HEADERS_RECEIVED=2,this.LOADING=3,this.DONE=4,this.readyState=this.UNSENT,this.onreadystatechange=null,this.responseText="",this.responseXML="",this.status=null,this.statusText=null,this.withCredentials=!1;this.open=function(e,t,r,n,o){if(this.abort(),b=!1,!function(e){return e&&-1===v.indexOf(e)}(e))throw new Error("SecurityError: Request method not allowed");u={method:e,url:t.toString(),async:"boolean"!=typeof r||r,user:n||null,password:o||null},E(this.OPENED)},this.setDisableHeaderCheck=function(e){f=e},this.setRequestHeader=function(e,t){if(this.readyState!==this.OPENED)throw new Error("INVALID_STATE_ERR: setRequestHeader can only be called when state is OPEN");if(function(e){return f||e&&-1===g.indexOf(e.toLowerCase())}(e)){if(y)throw new Error("INVALID_STATE_ERR: send flag is true");e=h[e.toLowerCase()]||e,h[e.toLowerCase()]=e,p[e]=p[e]?p[e]+", "+t:t}else console.warn('Refused to set unsafe header "'+e+'"')},this.getResponseHeader=function(e){return"string"==typeof e&&this.readyState>this.OPENED&&t&&t.headers&&t.headers[e.toLowerCase()]&&!b?t.headers[e.toLowerCase()]:null},this.getAllResponseHeaders=function(){if(this.readyState<this.HEADERS_RECEIVED||b)return"";var e="";for(var r in t.headers)"set-cookie"!==r&&"set-cookie2"!==r&&(e+=r+": "+t.headers[r]+"\r\n");return e.substr(0,e.length-2)},this.getRequestHeader=function(e){return"string"==typeof e&&h[e.toLowerCase()]?p[h[e.toLowerCase()]]:""},this.send=function(n){if(this.readyState!==this.OPENED)throw new Error("INVALID_STATE_ERR: connection must be opened before send() is called");if(y)throw new Error("INVALID_STATE_ERR: send has already been called");var o,f=!1,g=!1,v=i.parse(u.url);switch(v.protocol){case"https:":f=!0;case"http:":o=v.hostname;break;case"file:":g=!0;break;case void 0:case null:case"":o="localhost";break;default:throw new Error("Protocol not supported.")}if(g){if("GET"!==u.method)throw new Error("XMLHttpRequest: Only GET method is supported");if(u.async)s.readFile(v.pathname,"utf8",function(e,t){e?r.handleError(e):(r.status=200,r.responseText=t,E(r.DONE))});else try{this.responseText=s.readFileSync(v.pathname,"utf8"),this.status=200,E(r.DONE)}catch(e){this.handleError(e)}}else{var m=v.port||(f?443:80),w=v.pathname+(v.search?v.search:"");for(var x in d)h[x.toLowerCase()]||(p[x]=d[x]);if(p.Host=o,f&&443===m||80===m||(p.Host+=":"+v.port),u.user){void 0===u.password&&(u.password="");var S=new Buffer(u.user+":"+u.password);p.Authorization="Basic "+S.toString("base64")}"GET"===u.method||"HEAD"===u.method?n=null:n?(p["Content-Length"]=Buffer.isBuffer(n)?n.length:Buffer.byteLength(n),p["Content-Type"]||(p["Content-Type"]="text/plain;charset=UTF-8")):"POST"===u.method&&(p["Content-Length"]=0);var O={host:o,port:m,path:w,method:u.method,headers:p,agent:!1,withCredentials:r.withCredentials};if(b=!1,u.async){var C=f?l.request:c.request;y=!0,r.dispatchEvent("readystatechange");var N=function(e){r.handleError(e)};e=C(O,function n(a){if(301!==(t=a).statusCode&&302!==t.statusCode&&303!==t.statusCode&&307!==t.statusCode)t.setEncoding("utf8"),E(r.HEADERS_RECEIVED),r.status=t.statusCode,t.on("data",function(e){e&&(r.responseText+=e),y&&E(r.LOADING)}),t.on("end",function(){y&&(E(r.DONE),y=!1)}),t.on("error",function(e){r.handleError(e)});else{u.url=t.headers.location;var s=i.parse(u.url);o=s.hostname;var c={hostname:s.hostname,port:s.port,path:s.path,method:303===t.statusCode?"GET":u.method,headers:p,withCredentials:r.withCredentials};(e=C(c,n).on("error",N)).end()}}).on("error",N),n&&e.write(n),e.end(),r.dispatchEvent("loadstart")}else{var k=".node-xmlhttprequest-content-"+process.pid,T=".node-xmlhttprequest-sync-"+process.pid;s.writeFileSync(T,"","utf8");for(var j="var http = require('http'), https = require('https'), fs = require('fs');var doRequest = http"+(f?"s":"")+".request;var options = "+JSON.stringify(O)+";var responseText = '';var req = doRequest(options, function(response) {response.setEncoding('utf8');response.on('data', function(chunk) { responseText += chunk;});response.on('end', function() {fs.writeFileSync('"+k+"', JSON.stringify({err: null, data: {statusCode: response.statusCode, headers: response.headers, text: responseText}}), 'utf8');fs.unlinkSync('"+T+"');});response.on('error', function(error) {fs.writeFileSync('"+k+"', JSON.stringify({err: error}), 'utf8');fs.unlinkSync('"+T+"');});}).on('error', function(error) {fs.writeFileSync('"+k+"', JSON.stringify({err: error}), 'utf8');fs.unlinkSync('"+T+"');});"+(n?"req.write('"+JSON.stringify(n).slice(1,-1).replace(/'/g,"\\'")+"');":"")+"req.end();",R=a(process.argv[0],["-e",j]);s.existsSync(T););var D=JSON.parse(s.readFileSync(k,"utf8"));R.stdin.end(),s.unlinkSync(k),D.err?r.handleError(D.err):(t=D.data,r.status=D.data.statusCode,r.responseText=D.data.text,E(r.DONE))}}},this.handleError=function(e){this.status=0,this.statusText=e,this.responseText=e.stack,b=!0,E(this.DONE),this.dispatchEvent("error")},this.abort=function(){e&&(e.abort(),e=null),p=d,this.status=0,this.responseText="",this.responseXML="",b=!0,this.readyState===this.UNSENT||this.readyState===this.OPENED&&!y||this.readyState===this.DONE||(y=!1,E(this.DONE)),this.readyState=this.UNSENT,this.dispatchEvent("abort")},this.addEventListener=function(e,t){e in m||(m[e]=[]),m[e].push(t)},this.removeEventListener=function(e,t){e in m&&(m[e]=m[e].filter(function(e){return e!==t}))},this.dispatchEvent=function(e){if("function"==typeof r["on"+e]&&r["on"+e](),e in m)for(var t=0,n=m[e].length;t<n;t++)m[e][t].call(r)};var E=function(e){e!=r.LOADING&&r.readyState===e||(r.readyState=e,(u.async||r.readyState<r.OPENED||r.readyState===r.DONE)&&r.dispatchEvent("readystatechange"),r.readyState!==r.DONE||b||(r.dispatchEvent("load"),r.dispatchEvent("loadend")))}},F}(),_=q(I),U=new Map,B=y?window.XMLHttpRequest:_.XMLHttpRequest;function J(e){if(U.has(e))return U.get(e);var t;try{var r=new B;r.open("GET",e,!1),r.setRequestHeader("Content-Type","text/html"),r.send(),200===r.status&&r.responseText&&(t=r.responseText,U.set(e,r.responseText))}catch(e){console.error("【XHR Error】:".concat(e instanceof Error?e.message:"get remote URL resource exception!"))}return t}var M=new Map;function G(e,t){return new Promise(function(r){var n=J(e);if(n){var o=P(n,e);if(o){var i={linkTitle:t.linkTitle,target:t.target||"_blank",classPrefix:t.classPrefix},a=S(o,u(u({},i),{},{href:e})),s={url:e,data:o,options:i,dom:a};M.set(e,s),r(s)}}})}var z=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};function r(e){var r,n=function(e){if(E.has(e))return E.get(e);var t=null,r=J(e);return r&&(t=P(r,e))&&E.set(e,t),t}(e.url);if(n){!function(e,t){e.forEach(function(e,r){r!==t&&(e.hidden=!0)})}(e.tokens,e.i);var o={href:e.url,linkTitle:(r=e.tokens,r.map(function(e){var t=e.hidden,r=e.content;return t?r:""}).filter(Boolean).join("")),target:t.target||"_blank",classPrefix:t.classPrefix,borderColor:t.borderColor,bgColor:t.bgColor};return v(t.render)?t.render(n,o):S(n,o)}}e.renderer.renderInline=function(t,r,n){for(var o="",i=0;i<t.length;i++){var a=t[i],s=e.renderer.rules[a.type];a.hidden?o+="":v(s)?o+=s(t,i,r,n,e.renderer):o+=e.renderer.renderToken(t,i,r)}return o},e.renderer.rules.link_open=function(e,t,n,o,i){var a,s=e[t],c="a"===s.tag&&"link_open"===s.type,l=function(e){var t=new RegExp("^(".concat("@",":)([a-zA-Z0-9]+.*)")),r=null==e?void 0:e.match(t);return{isCardLink:!!r,url:null==r?void 0:r[2]}}(null===(a=s.attrs)||void 0===a||null===(a=a.filter(function(e){return e.includes("href")})[0])||void 0===a?void 0:a[1]),u=l.url,f=l.isCardLink;if(c&&f&&u){var d=r({url:u,tokens:e,i:t});if(d)return d}return i.renderToken(e,t,n)}};export{G as generateCard,z as linkToCardPlugin};
23
+ */var _=function(){if(H)return F;H=1;var i=e,a=t.spawn,s=r;return F.XMLHttpRequest=function(){var e,t,r=this,c=n,l=o,u={},f=!1,d={"User-Agent":"node-XMLHttpRequest",Accept:"*/*"},p={},h={},g=["accept-charset","accept-encoding","access-control-request-headers","access-control-request-method","connection","content-length","content-transfer-encoding","cookie","cookie2","date","expect","host","keep-alive","origin","referer","te","trailer","transfer-encoding","upgrade","via"],v=["TRACE","TRACK","CONNECT"],y=!1,b=!1,m={};this.UNSENT=0,this.OPENED=1,this.HEADERS_RECEIVED=2,this.LOADING=3,this.DONE=4,this.readyState=this.UNSENT,this.onreadystatechange=null,this.responseText="",this.responseXML="",this.status=null,this.statusText=null,this.withCredentials=!1;this.open=function(e,t,r,n,o){if(this.abort(),b=!1,!function(e){return e&&-1===v.indexOf(e)}(e))throw new Error("SecurityError: Request method not allowed");u={method:e,url:t.toString(),async:"boolean"!=typeof r||r,user:n||null,password:o||null},E(this.OPENED)},this.setDisableHeaderCheck=function(e){f=e},this.setRequestHeader=function(e,t){if(this.readyState!==this.OPENED)throw new Error("INVALID_STATE_ERR: setRequestHeader can only be called when state is OPEN");if(function(e){return f||e&&-1===g.indexOf(e.toLowerCase())}(e)){if(y)throw new Error("INVALID_STATE_ERR: send flag is true");e=h[e.toLowerCase()]||e,h[e.toLowerCase()]=e,p[e]=p[e]?p[e]+", "+t:t}else console.warn('Refused to set unsafe header "'+e+'"')},this.getResponseHeader=function(e){return"string"==typeof e&&this.readyState>this.OPENED&&t&&t.headers&&t.headers[e.toLowerCase()]&&!b?t.headers[e.toLowerCase()]:null},this.getAllResponseHeaders=function(){if(this.readyState<this.HEADERS_RECEIVED||b)return"";var e="";for(var r in t.headers)"set-cookie"!==r&&"set-cookie2"!==r&&(e+=r+": "+t.headers[r]+"\r\n");return e.substr(0,e.length-2)},this.getRequestHeader=function(e){return"string"==typeof e&&h[e.toLowerCase()]?p[h[e.toLowerCase()]]:""},this.send=function(n){if(this.readyState!==this.OPENED)throw new Error("INVALID_STATE_ERR: connection must be opened before send() is called");if(y)throw new Error("INVALID_STATE_ERR: send has already been called");var o,f=!1,g=!1,v=i.parse(u.url);switch(v.protocol){case"https:":f=!0;case"http:":o=v.hostname;break;case"file:":g=!0;break;case void 0:case null:case"":o="localhost";break;default:throw new Error("Protocol not supported.")}if(g){if("GET"!==u.method)throw new Error("XMLHttpRequest: Only GET method is supported");if(u.async)s.readFile(v.pathname,"utf8",function(e,t){e?r.handleError(e):(r.status=200,r.responseText=t,E(r.DONE))});else try{this.responseText=s.readFileSync(v.pathname,"utf8"),this.status=200,E(r.DONE)}catch(e){this.handleError(e)}}else{var m=v.port||(f?443:80),w=v.pathname+(v.search?v.search:"");for(var x in d)h[x.toLowerCase()]||(p[x]=d[x]);if(p.Host=o,f&&443===m||80===m||(p.Host+=":"+v.port),u.user){void 0===u.password&&(u.password="");var S=new Buffer(u.user+":"+u.password);p.Authorization="Basic "+S.toString("base64")}"GET"===u.method||"HEAD"===u.method?n=null:n?(p["Content-Length"]=Buffer.isBuffer(n)?n.length:Buffer.byteLength(n),p["Content-Type"]||(p["Content-Type"]="text/plain;charset=UTF-8")):"POST"===u.method&&(p["Content-Length"]=0);var O={host:o,port:m,path:w,method:u.method,headers:p,agent:!1,withCredentials:r.withCredentials};if(b=!1,u.async){var C=f?l.request:c.request;y=!0,r.dispatchEvent("readystatechange");var N=function(e){r.handleError(e)};e=C(O,function n(a){if(301!==(t=a).statusCode&&302!==t.statusCode&&303!==t.statusCode&&307!==t.statusCode)t.setEncoding("utf8"),E(r.HEADERS_RECEIVED),r.status=t.statusCode,t.on("data",function(e){e&&(r.responseText+=e),y&&E(r.LOADING)}),t.on("end",function(){y&&(E(r.DONE),y=!1)}),t.on("error",function(e){r.handleError(e)});else{u.url=t.headers.location;var s=i.parse(u.url);o=s.hostname;var c={hostname:s.hostname,port:s.port,path:s.path,method:303===t.statusCode?"GET":u.method,headers:p,withCredentials:r.withCredentials};(e=C(c,n).on("error",N)).end()}}).on("error",N),n&&e.write(n),e.end(),r.dispatchEvent("loadstart")}else{var k=".node-xmlhttprequest-content-"+process.pid,T=".node-xmlhttprequest-sync-"+process.pid;s.writeFileSync(T,"","utf8");for(var j="var http = require('http'), https = require('https'), fs = require('fs');var doRequest = http"+(f?"s":"")+".request;var options = "+JSON.stringify(O)+";var responseText = '';var req = doRequest(options, function(response) {response.setEncoding('utf8');response.on('data', function(chunk) { responseText += chunk;});response.on('end', function() {fs.writeFileSync('"+k+"', JSON.stringify({err: null, data: {statusCode: response.statusCode, headers: response.headers, text: responseText}}), 'utf8');fs.unlinkSync('"+T+"');});response.on('error', function(error) {fs.writeFileSync('"+k+"', JSON.stringify({err: error}), 'utf8');fs.unlinkSync('"+T+"');});}).on('error', function(error) {fs.writeFileSync('"+k+"', JSON.stringify({err: error}), 'utf8');fs.unlinkSync('"+T+"');});"+(n?"req.write('"+JSON.stringify(n).slice(1,-1).replace(/'/g,"\\'")+"');":"")+"req.end();",R=a(process.argv[0],["-e",j]);s.existsSync(T););var D=JSON.parse(s.readFileSync(k,"utf8"));R.stdin.end(),s.unlinkSync(k),D.err?r.handleError(D.err):(t=D.data,r.status=D.data.statusCode,r.responseText=D.data.text,E(r.DONE))}}},this.handleError=function(e){this.status=0,this.statusText=e,this.responseText=e.stack,b=!0,E(this.DONE),this.dispatchEvent("error")},this.abort=function(){e&&(e.abort(),e=null),p=d,this.status=0,this.responseText="",this.responseXML="",b=!0,this.readyState===this.UNSENT||this.readyState===this.OPENED&&!y||this.readyState===this.DONE||(y=!1,E(this.DONE)),this.readyState=this.UNSENT,this.dispatchEvent("abort")},this.addEventListener=function(e,t){e in m||(m[e]=[]),m[e].push(t)},this.removeEventListener=function(e,t){e in m&&(m[e]=m[e].filter(function(e){return e!==t}))},this.dispatchEvent=function(e){if("function"==typeof r["on"+e]&&r["on"+e](),e in m)for(var t=0,n=m[e].length;t<n;t++)m[e][t].call(r)};var E=function(e){e!=r.LOADING&&r.readyState===e||(r.readyState=e,(u.async||r.readyState<r.OPENED||r.readyState===r.DONE)&&r.dispatchEvent("readystatechange"),r.readyState!==r.DONE||b||(r.dispatchEvent("load"),r.dispatchEvent("loadend")))}},F}(),I=q(_),U=new Map,B=y?window.XMLHttpRequest:I.XMLHttpRequest;function J(e){if(U.has(e))return U.get(e);var t;try{var r=new B;r.open("GET",e,!1),r.setRequestHeader("Content-Type","text/html"),r.send(),200===r.status&&r.responseText&&(t=r.responseText,U.set(e,r.responseText))}catch(e){console.error("【XHR Error】:".concat(e instanceof Error?e.message:"get remote URL resource exception!"))}return t}var M=new Map;function G(e,t){return new Promise(function(r){var n=J(e);if(n){var o=P(n,e);if(o){var i={linkTitle:t.linkTitle,target:t.target||"_blank",classPrefix:t.classPrefix},a=S(o,u(u({},i),{},{href:e})),s={url:e,data:o,options:i,dom:a};M.set(e,s),r(s)}}})}var z=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};function r(e){var r,n=function(e){if(E.has(e))return E.get(e);var t=null,r=J(e);return r&&(t=P(r,e))&&E.set(e,t),t}(e.url);if(n){!function(e,t){e.forEach(function(e,r){r!==t&&(e.hidden=!0)})}(e.tokens,e.i);var o={href:e.url,linkTitle:(r=e.tokens,r.map(function(e){var t=e.hidden,r=e.content;return t?r:""}).filter(Boolean).join("")),target:t.target||"_blank",classPrefix:t.classPrefix,borderColor:t.borderColor,bgColor:t.bgColor};return v(t.render)?t.render(n,o):S(n,o)}}e.renderer.renderInline=function(t,r,n){for(var o="",i=0;i<t.length;i++){var a=t[i],s=e.renderer.rules[a.type];a.hidden?o+="":v(s)?o+=s(t,i,r,n,e.renderer):o+=e.renderer.renderToken(t,i,r)}return o},e.renderer.rules.link_open=function(e,t,n,o,i){var a,s=e[t],c="a"===s.tag&&"link_open"===s.type,l=function(e){var t=new RegExp("^(".concat("@",":)([a-zA-Z0-9]+.*)")),r=null==e?void 0:e.match(t);return{isCardLink:!!r,url:null==r?void 0:r[2]}}(null===(a=s.attrs)||void 0===a||null===(a=a.filter(function(e){return e.includes("href")})[0])||void 0===a?void 0:a[1]),u=l.url,f=l.isCardLink;if(c&&f&&u){var d=r({url:u,tokens:e,i:t});if(d)return d}return i.renderToken(e,t,n)}};export{G as generateCard,z as linkToCardPlugin};
@@ -1,8 +1,17 @@
1
1
  import { isPureObject } from '@luckrya/utility';
2
2
  import fs from 'node:fs';
3
3
  const CONFIG_FILE = () => {
4
- const filePath = `${process.cwd()}/.linkcard_cache.json`;
5
- if (!fs.existsSync(filePath)) {
4
+ let filePath;
5
+ const defaultPath = `${process.cwd()}/.linkcard_cache.json`;
6
+ const fallbackPath = `${process.cwd()}/.config/.linkcard_cache.json`;
7
+ if (fs.existsSync(defaultPath)) {
8
+ filePath = defaultPath;
9
+ }
10
+ else if (fs.existsSync(fallbackPath)) {
11
+ filePath = fallbackPath;
12
+ }
13
+ else {
14
+ filePath = defaultPath;
6
15
  const initialData = {
7
16
  'https://example.com/': {
8
17
  description: 'Example Website',
package/package.json CHANGED
@@ -75,5 +75,5 @@
75
75
  },
76
76
  "type": "module",
77
77
  "types": "./types/index.d.ts",
78
- "version": "1.1.3"
78
+ "version": "1.2.0"
79
79
  }