@sota1235/remark-link-bookmark 0.0.5 → 0.0.7

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/dist/ogp.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import ogs from 'open-graph-scraper';
2
2
  import * as fs from 'node:fs';
3
- import { logger } from './logger';
3
+ import { logger } from './logger.js';
4
4
  function isError(result) {
5
5
  return result.error;
6
6
  }
package/dist/plugin.js CHANGED
@@ -2,7 +2,7 @@ import { visit } from 'unist-util-visit';
2
2
  import { isUrl } from './url.js';
3
3
  import { fetchOgpInfo } from './ogp.js';
4
4
  import { buildBookmarkHtml } from './view.js';
5
- import { logger } from './logger';
5
+ import { logger } from './logger.js';
6
6
  export const remarkLinkBookmark = (options) => {
7
7
  return async (tree) => {
8
8
  const transformers = [];
package/dist/url.js CHANGED
@@ -1,4 +1,4 @@
1
- import { logger } from './logger';
1
+ import { logger } from './logger.js';
2
2
  export function isUrl(url) {
3
3
  try {
4
4
  const instance = new URL(url);
package/dist/view.js CHANGED
@@ -11,6 +11,12 @@ function buildOgpImageHtml(ogImageSrc, ogImageAlt, className) {
11
11
  ? `<img class="${className}" src="${ogImageSrc}" alt="${ogImageAlt}" />`
12
12
  : '';
13
13
  }
14
+ function removeEmptyLines(str) {
15
+ return str
16
+ .split(/\r?\n/)
17
+ .filter((line) => line.trim() !== '')
18
+ .join('\n');
19
+ }
14
20
  export const buildBookmarkHtml = ({ title, description, faviconSrc, ogImageSrc, ogImageAlt, url }, { classPrefix = 'rlb', mergeClassNames }) => {
15
21
  const host = new URL(url).host;
16
22
  const dompurify = createDOMPurify(new JSDOM('').window);
@@ -24,8 +30,8 @@ export const buildBookmarkHtml = ({ title, description, faviconSrc, ogImageSrc,
24
30
  const footerClassName = clsx(`${classPrefix}-footer`, mergeClassNames?.footer);
25
31
  const footerLinkClassName = clsx(`${classPrefix}-footer-link`, mergeClassNames?.footerLink);
26
32
  const faviconImageClassName = clsx(`${classPrefix}-favicon`, mergeClassNames?.favicon);
27
- return dompurify
28
- .sanitize(`
33
+ const footerLinkTextClassName = clsx(`${classPrefix}-footer-link-text`, mergeClassNames?.favicon);
34
+ return removeEmptyLines(dompurify.sanitize(`
29
35
  <div class="${containerClassName}">
30
36
  <div class="${contentClassName}">
31
37
  <div class="${infoClassName}">
@@ -38,8 +44,10 @@ export const buildBookmarkHtml = ({ title, description, faviconSrc, ogImageSrc,
38
44
  >
39
45
  ${title}
40
46
  </a>
41
- </h2>${buildDescriptionHtml(description, descriptionClassName)}
42
- </div>${buildOgpImageHtml(ogImageSrc, ogImageAlt, imageClassName)}
47
+ </h2>
48
+ ${buildDescriptionHtml(description, descriptionClassName)}
49
+ </div>
50
+ ${buildOgpImageHtml(ogImageSrc, ogImageAlt ?? url, imageClassName)}
43
51
  </div>
44
52
  <div class="${footerClassName}">
45
53
  <a
@@ -49,10 +57,9 @@ export const buildBookmarkHtml = ({ title, description, faviconSrc, ogImageSrc,
49
57
  rel="noopener noreferrer"
50
58
  >
51
59
  <img class="${faviconImageClassName}" src="${faviconSrc}" alt="${host}" />
52
- ${host}
60
+ <span class="${footerLinkTextClassName}">${host}</span>
53
61
  </a>
54
62
  </div>
55
63
  </div>
56
- `)
57
- .trim();
64
+ `)).trim();
58
65
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sota1235/remark-link-bookmark",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "description": "Remark plugin to convert link to bookmark component",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
@@ -20,6 +20,7 @@
20
20
  "@types/debug": "4.1.12",
21
21
  "@types/dompurify": "3.0.5",
22
22
  "@types/jsdom": "21.1.7",
23
+ "@types/node": "22",
23
24
  "eslint": "9.14.0",
24
25
  "husky": "9.1.6",
25
26
  "lint-staged": "15.2.10",
@@ -29,6 +30,19 @@
29
30
  "typescript-eslint": "8.13.0",
30
31
  "vitest": "^2.1.4"
31
32
  },
33
+ "scripts": {
34
+ "build": "tsc -p ./tsconfig.publish.json",
35
+ "build:publish": "tsc -p ./tsconfig.publish.json",
36
+ "watch": "tsc -p ./tsconfig.publish.json --watch",
37
+ "fix": "npm run prettier && npm run eslint:fix",
38
+ "lint": "npm run eslint",
39
+ "eslint": "eslint 'src/**/*.ts'",
40
+ "eslint:fix": "npm run eslint --fix",
41
+ "prettier": "prettier './src/**/*.ts' --write",
42
+ "test": "vitest",
43
+ "test:ci": "vitest",
44
+ "prepare": "husky"
45
+ },
32
46
  "keywords": [
33
47
  "remark"
34
48
  ],
@@ -43,16 +57,5 @@
43
57
  "npm run fix"
44
58
  ]
45
59
  },
46
- "scripts": {
47
- "build": "tsc -p ./tsconfig.publish.json",
48
- "build:publish": "tsc -p ./tsconfig.publish.json",
49
- "watch": "tsc -p ./tsconfig.publish.json --watch",
50
- "fix": "npm run prettier && npm run eslint:fix",
51
- "lint": "npm run eslint",
52
- "eslint": "eslint 'src/**/*.ts'",
53
- "eslint:fix": "npm run eslint --fix",
54
- "prettier": "prettier './src/**/*.ts' --write",
55
- "test": "vitest",
56
- "test:ci": "vitest"
57
- }
58
- }
60
+ "packageManager": "pnpm@9.12.3+sha512.cce0f9de9c5a7c95bef944169cc5dfe8741abfb145078c0d508b868056848a87c81e626246cb60967cbd7fd29a6c062ef73ff840d96b3c86c40ac92cf4a813ee"
61
+ }
package/.envrc DELETED
@@ -1 +0,0 @@
1
- export NODE_AUTH_TOKEN=
@@ -1 +0,0 @@
1
- export {};
@@ -1,16 +0,0 @@
1
- import { expect, test } from 'vitest';
2
- import { remark } from 'remark';
3
- import { remarkLinkBookmark } from './plugin.js';
4
- test('Input markdown should be expected', async () => {
5
- const document = `
6
- # Sample
7
-
8
- https://example.com
9
-
10
- [example](https://example.com/) is inline link
11
-
12
- [remark-link-card](https://www.npmjs.com/package/remark-link-card) is inline link
13
- `.trim();
14
- const file = await remark().use(remarkLinkBookmark, {}).process(document);
15
- expect(file.toString()).toMatchFileSnapshot('snapshots/output.md');
16
- });
package/dist/mdast.d.ts DELETED
@@ -1,3 +0,0 @@
1
- import { Text, Link, PhrasingContent } from 'mdast';
2
- export declare function isLink(child: PhrasingContent): child is Link;
3
- export declare function isText(child: PhrasingContent): child is Text;
package/dist/mdast.js DELETED
@@ -1,6 +0,0 @@
1
- export function isLink(child) {
2
- return child.type === 'link';
3
- }
4
- export function isText(child) {
5
- return child.type === 'text';
6
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,4 +0,0 @@
1
- import { expect, test } from 'vitest';
2
- test('1 + 1 = 2', () => {
3
- expect(1 + 1).toBe(2);
4
- });
package/dist/script.d.ts DELETED
@@ -1 +0,0 @@
1
- export declare function main(): void;
package/dist/script.js DELETED
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.main = main;
4
- function main() {
5
- console.log('hello, world');
6
- }