nuxt-link-preview
v0.1.5
Published
Link preview module for Nuxt.js
Downloads
68
Readme
Nuxt3 Link Preview
A Nuxt.js 3.x module for previewing links using the Composition API.
Installation
- Add the module to your Nuxt.js project:
npm install --save nuxt-link-preview
- Add nuxt-link-preview to the modules section of your nuxt.config.js file:
modules: [
'nuxt-link-preview'
],
Types
interface Preview {
title: string,
description: string,
image: string,
url: string,
meta: Meta[]
}
interface Meta {
name: string;
value: string
}
Usage
In your project, you may create a new api endpoint inside /server/api
called preview.ts
or preview.get.ts
export default defineEventHandler(async (event) => {
const body = getQuery(event);
const preview = await useLinkPreview(<string>body.url);
return { preview };
});
API
useLinkPreview(url: string): Preview
Fetches link preview data for the given url. Returns an object of the Preview interface with the following properties:
title
The title of the pagedescription
A short descriprion of the pageimage
A URL to the main image of the pageurl
The URL of the pagemeta
The whole meta tags inside<head>
tag
Development
- Run
npm run dev:prepare
to generate type stubs. - Use
npm run dev
to start playground in development mode.
Contributing
- Fork the Repo
- Create your feature/bugfix branch (git checkout -b my-branch)
- Commit your changes (git commit -am "Add/fixed something somewhere")
- Push to the branch (git push origin my-branch)
- Create new Pull Request
License
The project is licensed under the MIT License -- see the LICENSE file for details.