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-data

v2.0.0

Published

Inject external data into a VuePress site

Downloads

4

Readme

vuepress-plugin-data

Inject external data into a VuePress site.

Install

npm install -D vuepress-plugin-data

# or

yarn add -D vuepress-plugin-data

Usage

1. Add plugin to your VuePress config

There are multiple ways to do this. Here is one way:

// .vuepress/config.js
module.exports = {
  plugins: [
    ['vuepress-plugin-data', {
      // plugin options go here, see next step
    }]
  ]
}

2. Specify the data

Specify the data in the plugin options as an array of key/value pairs.

// .vuepress/config.js
module.exports = {
  plugins: [
    ['vuepress-plugin-data', {
      data: [
        {
          key: 'count',
          // can be static value
          value: 5
        },
        {
          key: 'rando',
          // can be function
          value() {
            return Math.random();
          }
        },
        {
          key: 'speakers',
          // can be function that returns Promise
          value() {
            return axios.get('https://example.org/api/speakers')
              .then(response => response.data);
          }
        },
        {
          key: 'cities',
          // can be async function
          async value() {
            return await axios.get('https://example.org/api/cities')
              .then(response => response.data);
          }
        }
      ]
    }]
  ]
}

3. Access the data

Your data is accessible in the vppData object.

Data is injected using a global mixin:

Vue.mixin({
  data() {
    return {
      vppData: {
        // Your data will be in here by the keys you specified
      }
    };
  }
});

This means all pages and components can access the data directly.

3a. Access data in a page

---
title: My Site
---

- {{vppData.count}}
- {{vppData.rando}}

<ul>
  <li v-for="city in vppData.cities" :key="city.id">
    {{city.name}}
  </li>
</ul>

3b. Access data in a Vue component

export default {
  computed: {
    speakerCount() {
      return this.vppData.speakers.length;
    }
  }
};

API

PluginOptions

interface PluginOptions {
  /**
   * Array of data specs.
   *
   * Each data spec is one piece of data to inject.
   */
  data: Array<DataSpec>;
}

DataSpec

interface DataSpec {
  /**
   * The property name for this injected data.
   *
   * Must be unique across all other data specs.
   */
  key: string;
  /**
   * The value for this injected data.
   *
   * Any of
   *   - json serializable value
   *   - function that returns a json serializable value
   *   - function that returns a Promise that resolves to a json serializable value
   *   - async function that returns a json serializable value
   *   - Promise that resolves to a json serializable value
   */
  value: any;
}

Caveats

  • Because the data is in the initial js bundle, all data is eagerly loaded by your site.

License

MIT