0.1.5 • Published 3 years ago
nuxt-link-preview v0.1.5
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:
titleThe title of the pagedescriptionA short descriprion of the pageimageA URL to the main image of the pageurlThe URL of the pagemetaThe whole meta tags inside<head>tag
Development
- Run
npm run dev:prepareto generate type stubs. - Use
npm run devto 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.