0.1.5 • Published 1 year ago

nuxt-link-preview v0.1.5

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Nuxt3 Link Preview

License: MIT TypeScript npm bundle size

A Nuxt.js 3.x module for previewing links using the Composition API.

Installation

  1. Add the module to your Nuxt.js project:
npm install --save nuxt-link-preview
  1. 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 page
  • description A short descriprion of the page
  • image A URL to the main image of the page
  • url The URL of the page
  • meta 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

  1. Fork the Repo
  2. Create your feature/bugfix branch (git checkout -b my-branch)
  3. Commit your changes (git commit -am "Add/fixed something somewhere")
  4. Push to the branch (git push origin my-branch)
  5. Create new Pull Request

License

The project is licensed under the MIT License -- see the LICENSE file for details.

0.1.5

1 year ago

0.1.4

1 year ago

0.1.3

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago