Compare commits

..

10 commits

Author SHA1 Message Date
Nicola Zambello fb5fc033b0
chore: release v1.1.1
Some checks failed
CI / Build, lint, and test on Node ${{ matrix.node }} and ${{ matrix.os }} (12.x, macOS-latest) (push) Has been cancelled
CI / Build, lint, and test on Node ${{ matrix.node }} and ${{ matrix.os }} (14.x, macOS-latest) (push) Has been cancelled
CI / Build, lint, and test on Node ${{ matrix.node }} and ${{ matrix.os }} (14.x, ubuntu-latest) (push) Has been cancelled
CI / Build, lint, and test on Node ${{ matrix.node }} and ${{ matrix.os }} (16.x, macOS-latest) (push) Has been cancelled
CI / Build, lint, and test on Node ${{ matrix.node }} and ${{ matrix.os }} (16.x, ubuntu-latest) (push) Has been cancelled
CI / Build, lint, and test on Node ${{ matrix.node }} and ${{ matrix.os }} (12.x, ubuntu-latest) (push) Has been cancelled
2022-07-07 10:03:38 +02:00
Nicola Zambello 587d64104d
test: update yt test 2022-07-07 09:52:52 +02:00
Nicola Zambello 4f33058b63
style: run prettier 2022-07-07 09:50:09 +02:00
Nicola Zambello d0b4fb5d66
chore: release v1.1.0 2022-07-07 09:48:54 +02:00
Nicola Zambello 1dcf4e4853
chore: release v1.1.0 2022-07-07 09:47:36 +02:00
Nicola Zambello 9196390a18
feat: handle links with no protocol from wikipedia 2022-07-07 09:46:47 +02:00
Nicola Zambello 6cfe4df5d5
chore: add access public to publish config in package.json 2022-04-28 17:18:17 +02:00
Nicola Zambello aaf7ca2ea4
docs: update readme instructions for types import 2022-04-28 17:17:01 +02:00
Nicola Zambello 69a206a566
chore: release v1.0.1 2022-04-28 17:08:06 +02:00
Nicola Zambello 01e58713f6
chore: update package name 2022-04-28 17:06:40 +02:00
5 changed files with 65 additions and 11 deletions

View file

@ -1,5 +1,26 @@
### [1.1.1](https://github.com/nzambello/link-previewer/compare/v1.1.0...v1.1.1) (2022-07-07)
## [1.1.0](https://github.com/nzambello/link-previewer/compare/v1.0.1...v1.1.0) (2022-07-07)
### Features
* handle links with no protocol from wikipedia ([9196390](https://github.com/nzambello/link-previewer/commit/9196390a186e50bf5d61415de995f23066258fe4))
### Maintenance
* add access public to publish config in package.json ([6cfe4df](https://github.com/nzambello/link-previewer/commit/6cfe4df5d5307daf7830f0fb5e2080e382f3aacd))
### [1.0.1](https://github.com/nzambello/link-previewer/compare/v1.0.0...v1.0.1) (2022-04-28)
### Maintenance
* update package name ([01e5871](https://github.com/nzambello/link-previewer/commit/01e58713f68f261e0fb1c0b0fd44243ab696dce2))
## 1.0.0 (2022-04-28) ## 1.0.0 (2022-04-28)

View file

@ -1,6 +1,6 @@
# link-previewer # link-previewer
[![npm version](https://img.shields.io/github/package-json/v/nzambello/link-previewer)](https://www.npmjs.com/package/link-previewer) [![npm version](https://img.shields.io/github/package-json/v/nzambello/link-previewer)](https://www.npmjs.com/package/@nzambello/link-previewer)
![Tests](https://github.com/nzambello/link-previewer/workflows/CI/badge.svg?branch=main) ![Tests](https://github.com/nzambello/link-previewer/workflows/CI/badge.svg?branch=main)
![TypeScript Support](https://img.shields.io/badge/TypeScript-Support-blue) ![TypeScript Support](https://img.shields.io/badge/TypeScript-Support-blue)
@ -9,17 +9,18 @@ Node util to retrieve preview info from a link (og tags, meta tags, images, vide
## Installation ## Installation
```bash ```bash
yarn add link-previewer yarn add @nzambello/link-previewer
``` ```
```bash ```bash
npm install link-previewer npm install @nzambello/link-previewer
``` ```
## Usage ## Usage
```ts ```ts
import getLinkPreview from 'link-previewer'; import type { ILinkPreviewInfo } from '@nzambello/link-previewer';
import getLinkPreview from '@nzambello/link-previewer';
getLinkPreview('https://www.youtube.com/watch?v=feH26j3rBz8').then(console.log); getLinkPreview('https://www.youtube.com/watch?v=feH26j3rBz8').then(console.log);
``` ```

View file

@ -1,12 +1,12 @@
{ {
"version": "1.0.0", "publishConfig": {
"access": "public"
},
"version": "1.1.1",
"license": "MIT", "license": "MIT",
"main": "dist/index.js", "main": "dist/index.js",
"typings": "dist/index.d.ts", "typings": "dist/index.d.ts",
"files": [ "files": ["dist", "src"],
"dist",
"src"
],
"engines": { "engines": {
"node": ">=12" "node": ">=12"
}, },
@ -32,7 +32,7 @@
"singleQuote": true, "singleQuote": true,
"trailingComma": "es5" "trailingComma": "es5"
}, },
"name": "link-previewer", "name": "@nzambello/link-previewer",
"author": "nzambello", "author": "nzambello",
"description": "Node util to retrieve preview info from a link (og tags, meta tags, images, videos)", "description": "Node util to retrieve preview info from a link (og tags, meta tags, images, videos)",
"repository": { "repository": {

View file

@ -31,6 +31,7 @@ const getMeta = ($: cheerio.Root, metaName: string) => {
const parseUrl = (url?: string, baseUrl?: string) => { const parseUrl = (url?: string, baseUrl?: string) => {
if (!url) return undefined; if (!url) return undefined;
if (!baseUrl || url.startsWith('http')) return url; if (!baseUrl || url.startsWith('http')) return url;
if (url.startsWith('//')) return `https:${url}`;
return `${baseUrl}${url}`; return `${baseUrl}${url}`;
}; };

View file

@ -3,7 +3,7 @@ import getLinkPreview, { ILinkPreviewInfo } from '../src';
const youtubeSample: ILinkPreviewInfo = { const youtubeSample: ILinkPreviewInfo = {
description: description:
'How much do we know about the impact of technologies we use everyday? How much the web industry is responsible for carbon emissions? Can we define an ethic d...', 'How much do we know about the impact of technologies we use everyday? How much the web industry is responsible for carbon emissions? Can we define an ethic d...',
favicon: 'https://www.youtube.com/s/desktop/ce262d3b/img/favicon.ico', favicon: 'https://www.youtube.com/s/desktop/97650662/img/favicon.ico',
image: 'https://i.ytimg.com/vi/feH26j3rBz8/maxresdefault.jpg', image: 'https://i.ytimg.com/vi/feH26j3rBz8/maxresdefault.jpg',
imageHeight: 720, imageHeight: 720,
imageWidth: 1280, imageWidth: 1280,
@ -35,6 +35,30 @@ const rawmaterialSample: ILinkPreviewInfo = {
videos: [], videos: [],
}; };
const wikipediaSample: ILinkPreviewInfo = {
description: undefined,
favicon: 'https://en.wikipedia.org/static/favicon/wikipedia.ico',
image:
'https://upload.wikimedia.org/wikipedia/commons/thumb/e/e2/Plone_5.2.png/1200px-Plone_5.2.png',
imageHeight: 1423,
imageWidth: 1200,
images: [
'https://upload.wikimedia.org/wikipedia/commons/thumb/d/df/Plone-logo.svg/121px-Plone-logo.svg.png',
'https://upload.wikimedia.org/wikipedia/commons/thumb/e/e2/Plone_5.2.png/300px-Plone_5.2.png',
'https://upload.wikimedia.org/wikipedia/en/thumb/8/8a/OOjs_UI_icon_edit-ltr-progressive.svg/10px-OOjs_UI_icon_edit-ltr-progressive.svg.png',
'https://upload.wikimedia.org/wikipedia/commons/thumb/3/31/Free_and_open-source_software_logo_%282009%29.svg/28px-Free_and_open-source_software_logo_%282009%29.svg.png',
'https://upload.wikimedia.org/wikipedia/en/thumb/4/4a/Commons-logo.svg/30px-Commons-logo.svg.png',
'https://upload.wikimedia.org/wikipedia/en/thumb/8/8a/OOjs_UI_icon_edit-ltr-progressive.svg/10px-OOjs_UI_icon_edit-ltr-progressive.svg.png',
'https://en.wikipedia.org/static/images/footer/wikimedia-button.png',
'https://en.wikipedia.org/static/images/footer/poweredby_mediawiki_88x31.png',
],
mediaType: 'website',
siteName: undefined,
title: 'Plone (software) - Wikipedia',
video: undefined,
videos: [],
};
it('gets correct info for RawMaterial website', async () => { it('gets correct info for RawMaterial website', async () => {
const info = await getLinkPreview('https://rawmaterial.it/en'); const info = await getLinkPreview('https://rawmaterial.it/en');
expect(info).toEqual(rawmaterialSample); expect(info).toEqual(rawmaterialSample);
@ -46,3 +70,10 @@ it('gets correct info for YouTube video link', async () => {
); );
expect(info).toEqual(youtubeSample); expect(info).toEqual(youtubeSample);
}); });
it('gets correct info for Wikipedia url', async () => {
const info = await getLinkPreview(
'https://en.wikipedia.org/wiki/Plone_(software)'
);
expect(info).toEqual(wikipediaSample);
});