0.1.1 • Published 1 year ago

vitepress-plugin-og-image v0.1.1

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

vitepress-plugin-og-image

npm version build codecov License

Overview

A VitePress plugin to generate OGP images.

Installation

You can install this library using npm:

npm install vitepress-plugin-og-image

Usage

  • Import into VitePress config.ts file for use.
  • Set the path of the OG image in the metadata with the transformHead hook
  • Generate OG image entities with the buildEnd hook.

Params

keytyperequireddescription
destDirstringOG image placement directory specified by relative path from outDir
authorobjectUsed to include the author's name or image in the OG image
author.namestringSpecify the author's name to be displayed
author.imageURLstringSpecify the author's avatar image url to be displayed

config.ts

const ogImagePlugin = new OgImagePlugin({
  destDir: "/og",
  author: { name: "Author Name", imageURL: "{Author Avatar URL}" },
});

// https://vitepress.dev/reference/site-config
export default defineConfig({
  transformHead(context) {
    return [
      ["meta", { property: "og:title", content: context.pageData.title }],
      ...ogImagePlugin.transformHead(context),
    ];
  },
  buildEnd(siteConfig) {
    ogImagePlugin.buildEnd(siteConfig);
  },
});

Link

License

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