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

@1password/docusaurus-plugin-stored-data

v1.0.0

Published

Load local or external data to be used in Docusaurus

Downloads

162

Readme

docusaurus-plugin-stored-data

Load local or external data to be used in Docusaurus

Usage

Start by installing the dependency:

  • Yarn: yarn add @1password/docusaurus-plugin-stored-data
  • NPM: npm i @1password/docusaurus-plugin-stored-data

Add the plugin to your docusaurus.config.js file's "plugins" option. If you're new to Docusaurus plugins, click here to learn more about installing and configuring them.

These are the available plugin options:

type Options = {
  /**
   * Define key-value pairs, where the key is the ID you want to assign to the data,
   * and the value is a local path or external URL to retrieve the data from.
   */
  data: Record<string, string>;
};

Here's an example of how to set the plugin's options, loading both local and external data:

// docusaurus.config.js
const { resolve } = require("path");

plugins: [
  [
    '@1password/docusaurus-plugin-stored-data',
    {
      data: {
        "blog-feed": "https://example.com/blog.xml",
        "rust-example": resolve(__dirname, "static", "example.rs"),
      }
    }
  ]
],

Now, when you start your dev server or build the site, the plugin will retrieve the contents of each location specified in the config and store it as plugin data. Access this data in your site using one of the plugin's hooks, which takes the ID and returns the data in various formats.

The following hooks are available:

  • @theme/useStoredData - Returns the data unformatted
  • @theme/useStoredJson - Returns the data parsed as JSON
  • @theme/useStoredFeed - Returns the data parsed as RSS XML into JSON structure using fast-xml-parser.

Here's an example of how you might use the plugin to retrieve and render blog posts from an RSS feed:

// FeedItems.tsx

import useStoredFeed from "@theme/useStoredFeed";

const FeedItems = () => {
  const feedData = useStoredFeed("blog-feed");
  return (
    <ul>
      {feedData.item.map((item) => (
        <li key={item.guid}>{item.title}</li>
      ))}
    </ul>
  );
};

Or, if your data can be rendered without modification you can simply call a hook directly inside an MDX file:

// example.mdx

import CodeBlock from "@theme/CodeBlock";
import useStoredData from "@theme/useStoredData";

<CodeBlock language="rust">{useStoredData("rust-example")}</CodeBlock>;

If you're using TypeScript you will need to reference the plugin's types:

// types.d.ts

/// <reference types="@1password/docusaurus-plugin-stored-data" />

License

MIT