npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vuepress-plugin-seo

v0.2.0

Published

Generate SEO friendly meta header for every page, VuePress v2

Downloads

1,195

Readme

Vuepress Plugin SEO

🔌 Generate SEO friendly meta header for every page

Installation

npm i vuepress-plugin-seo -D

Usage

plugins: {
    'seo': { /* options */ }
},

Note that Vuepress allows multiple syntaxes to register plugins. See Vuepress documentation on how to use a plugin for more information.

Options

The default options below show you how the relevant data is being retrieved from your vuepress application and its pages. Simply override the function of your choice to define your own logic.

// Options
{
    siteTitle: (_, $site) => $site.title,
    title: $page => $page.title,
    description: $page => $page.frontmatter.description,
    author: (_, $site) => $site.themeConfig.author,
    tags: $page => $page.frontmatter.tags,
    twitterCard: _ => 'summary_large_image',
    type: $page => ['articles', 'posts', 'blog'].some(folder => $page.regularPath.startsWith('/' + folder)) ? 'article' : 'website',
    url: (_, $site, path) => ($site.themeConfig.domain || '') + path,
    image: ($page, $site) => $page.frontmatter.image && (($site.themeConfig.domain && !$page.frontmatter.image.startsWith('http') || '') + $page.frontmatter.image),
    publishedAt: $page => $page.frontmatter.date && new Date($page.frontmatter.date),
    modifiedAt: $page => $page.lastUpdated && new Date($page.lastUpdated),
}

A few things to note:

  • Each of those functions take three agurments: $page (page configs provided by Vuepress), $site (site configs provided by Vuepress) and path (the built permalink of the page which is different than $page.path in the plugin world).
  • If the return value of any of these options is null or undefined, it will not add the metadata. This avoids having lots of empty meta header in your pages.
  • The author option should be an object with any of the following values: name (the full name of the author) and twitter (the Twitter handle of the author, e.g. @lorismatic).
  • The tags option should be an array.
  • The type should be part of the Open Graph protocol. E.g. article, profile, book, website.
  • Both the url and image options try to use the $site.themeConfig.domain variable as a prefix. If it's not available, it will still work but the links of your meta headers will be relative and not absolute.
  • When defining the image attribute in your frontmatter, you should make sure that its path is already resolved. That means, either storing your SEO images in the public folder or simply copy/pasting the path of a resolved image from the browser, e.g. /assets/img/my_image.8b54ab32.jpg. You cannot use for example image: ./my_image.jpg to reference the image in the current folder. We cannot resolve this path for you at this time because vuepress does not support asset resolution in frontmatter.
  • It can be wise to include a timezone when defining publishedAt in your frontmatter. E.g. date: 2018-06-07 23:46 UTC.
  • The modifiedAt default value will work out-of-the-box if you registers the @vuepress/last-updated plugin before this one.

Finally you can also add your own custom meta headers through the customMeta option:

// Options
{
    //...
    customMeta: (add, context) => {

        const {
            $site, // Site configs provided by Vuepress
            $page, // Page configs provided by Vuepress

            // All the computed options from above:
            siteTitle, title, description, author, tags,
            twitterCard, type, url, image, publishedAt, modifiedAt,
        } = context

        add('twitter:site', $site.themeConfig.twitter)
        // -> <meta name="twitter:site" content="@github"></meta>

        add('book:isbn', '9780091929114', 'property')
        // -> <meta property="book:isbn" content="9780091929114"></meta>
    },
}

Note that customMeta defaults to () => {}.