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

metadatah

v1.1.0

Published

All the SEO meta tags you might need in one React component

Downloads

78

Readme

metadatah

All the SEO meta tags you might need in one React component.

Why?

I can NOT entirely say that there's a motivation behind building this, to be honest. I was just tired of having to copy the same meta tags that I've been using for my blog whenever I share an article on the internet — mostly on social platforms.

What are the "perks" of using it?

Well... for one, you won't have to copy meta tags from one component to the other.

And if you're that person that goes: "I can just build this myself". Well, you're in luck. Because you don't have to do that.

<Metadata /> accepts a children prop, so you can still add other HTML tags that goes into the <head> element.

<Metadata>
  <link href="style.css" />
</Metadata>

Usage

You can use the component by installing it from the NPM registry.

yarn add metadatah

Import the component into any of your pages, or wherever it is needed like so:

import { MetaData } from "metadatah";

export default function pageComponent() {
  return (
    <>
      <MetaData
        pageTitle="Homepage"
        url="your-website.com"
        description="description of the page"
        previewImage="path-to-image or a remote link to where it is located."
      />
      // rest of the page content falls below
    </>
  );
}

pageTitle, url, previewImage and description are required props.

I've tested MetaData and this is what your website metadata will look like on Google search, Facebook — and meta related websites i.e LinkedIn — and Twitter.

Below are some screenshots of my website's preview

| Facebook | Twitter | | --------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- | | Preview of Caleb's website on Facebook | Preview of Caleb's website on Twitter |

| Google Search | | ------------------------------------------------------------------------------------------------------------------------------------------------ | | Preview of Caleb's website on Google Search |

Try sharing your link on Slack or Discord, it works fine there too.

This attribute helps you describe the type of content you share. Is it a blog post, pictures, videos or whatever you want really. By default the value is "website", since it is assumed that you're using this component on the web.

There's a list that covers all the available values here

Optional props

  • contentType: accepts either "article" or "webiste" as values
  • contentLanguage: can be used to chnage the language of your content. Defaults to "en_US" if none is sepcified.
  • children: include additional meta tags if you like.

Usage with Next.js

When you try to use <MetaData /> in a Next.js project, you might end up with an error similar to the one in the image below

Hydration error with Next.js when you try to use MetaData

The reason you're seeing this error could be because you have _document.ts|js file in /pages and you've imported <Head /> from `"next/document``.

import NextDocument, { Html, Head, Main, NextScript } from "next/document";

export default class Document extends NextDocument {
  render() {
    return (
      <Html lang="en">
        <Head />
        <body>
          <Main />
          <NextScript />
        </body>
      </Html>
    );
  }
}

Removing it from the markup fixes the error you're seeing.

Athough, when you follow this approach, You'd still end up with some hydration error in React, as the Next.js Head component does not match the one that MetaData extends.

It is recommended that you import the component from `"metadata/next"`` if you want compatibility with Next.js like so:

import { MetaData } from "metadata/next";

<MetaData
  url="website.com"
  pageTitle="name of site"
  description="Some description of your website"
>
  <link rel="icon" href="./icon.svg" />
</MetaData>;

Contributing

Want to contribute? Please feel free to create an issue or submit a Pull Request.

License

MIT