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

@moxy/next-seo

v1.0.0

Published

SEO for Next.js

Downloads

104

Readme

next-seo

NPM version Downloads Build Status Coverage Status Dependency status Dev Dependency status

Manage document head SEO metadata in your Next.js projects with a simple data structure.

Installation

$ npm install @moxy/next-seo

This library is written in modern JavaScript and is published in both CommonJS and ES module transpiled variants. If you target older browsers please make sure to transpile accordingly.

Motivation

SEO helps to improve a website’s overall searchability and visibility. Therefore, an efficient SEO is a must have in every website and there should be a good and easy way to manage all the metadata. These metadata can come from multiple sources, from static files to CMS based approaches, in completely different formats.

There are already different ways of managing all of your changes to the document head, but it can be tough to manage the possibility of duplicates. An example of a duplicate would be two meta tags defining the description of a page with different values:

<meta name="description" content="desc1">
<meta name="description" content="desc2">

Which one should a web crawler assume as the source of truth?

This library aims to solve these problems by analysing common attributes and generating an unique key to exclude duplicates. It also works with a simple data structure that is not bound to any specific origin.

Usage

import React from 'react';
import Seo from '@moxy/next-seo';

const MyPage = (props) => {
    const metadata = {
        title: 'MyPage Title',
        meta: [
            {
                name: 'description',
                content:'MyPage Description',
            },
            {
                property: 'og:title',
                content: 'MyPage Title',
            },
        ],
    };

    return (
        <>
            <Seo data={ metadata } />
            <div className="container">
                ...
            </div>
        </>
    );
};

export default MyPage;

The example above will add to the document head:

<head>
    ...
    <title>MyPage Title</title>
    <meta name="description" content="MyPage Description" />
    <meta property="og:title" content="MyPage Title" />
</head>

API

The <Seo> component supports the following props:

data

Type: object Required: true

The data has the following shape:

data: PropTypes.shape({
    title: PropTypes.string,
    meta: PropTypes.arrayOf(PropTypes.object),
    link: PropTypes.arrayOf(PropTypes.object),
}).isRequired,

The title is a simple key-value pair that will define the page title with the title tag.

Both meta and link are an array of objects where each object represents a single entity (meta or link). Any key-value pair of these objects will serve as an attribute.

Example:

data: {
        title: 'my title',
        meta: [
            {
                name: 'description',
                content: 'my description',
            },
            {
                property: 'og:title',
                content: 'my title',
            },
            {
                itemprop: 'name',
                content: 'my name',
            },
            {
                'http-equiv': 'content-type',
                content: '30',
            },
            {
                foo: 'bar',
            },
        ],
        link: [
            {
                rel: 'icon',
                href: '/favicon.ico',
            },
            {
                rel: 'stylesheet',
                href: '/styles.css',
            },
        ],
    },
};

Result:

<title>my title</title>
<meta name="description" content="my description" />
<meta property="og:title" content="my title" />
<meta itemprop="name" content="my name" />
<meta http-equiv="content-type" content="30" />
<meta foo="bar" />
<link rel="icon" href="/favicon.ico" />
<link rel="stylesheet" href="/styles.css" />

Tests

$ npm test
$ npm test -- --watch # during development

License

Released under the MIT License.