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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@bizhours/next-seo-plugin-core

v4.0.7

Published

Core library for Next SEO Plugin

Readme

@next-seo-plugin/core

The core Next.js middleware for The Next SEO Plugin. Seamlessly integrate dynamic SEO management into your Next.js application.

Installation

npm install @next-seo-plugin/core
# or
yarn add @next-seo-plugin/core
# or  
pnpm add @next-seo-plugin/core

Quick Start

1. Create middleware.ts

Create a middleware.ts file in your project root:

import { withNextSEO } from '@next-seo-plugin/core';

export const middleware = withNextSEO({
  apiUrl: process.env.NEXT_PUBLIC_SEO_API_URL!,
  apiKey: process.env.NEXT_SEO_API_KEY!,
  siteId: 'your-site-id',
  cache: true,
  cacheTTL: 60, // seconds
});

export const config = {
  matcher: [
    '/((?!api|_next/static|_next/image|favicon.ico).*)',
  ],
};

2. Add Provider to your app

In your app/layout.tsx:

import { NextSEOProvider } from '@next-seo-plugin/core';

export default function RootLayout({
  children,
}: {
  children: React.ReactNode;
}) {
  return (
    <html>
      <body>
        <NextSEOProvider
          config={{
            apiUrl: process.env.NEXT_PUBLIC_SEO_API_URL!,
            apiKey: process.env.NEXT_SEO_API_KEY!,
            siteId: 'your-site-id',
          }}
        >
          {children}
        </NextSEOProvider>
      </body>
    </html>
  );
}

3. Use in your components

'use client';

import { useNextSEO, useContent } from '@next-seo-plugin/core';

export default function HomePage() {
  const { metadata, updateMetadata, loading } = useNextSEO();
  const heroTitle = useContent('hero_title');

  return (
    <div>
      <h1>{heroTitle || 'Welcome'}</h1>
      {/* Your content */}
    </div>
  );
}

Features

🚀 Middleware-based SEO

  • Automatic metadata injection
  • Server-side redirects
  • Zero client-side overhead
  • Edge runtime compatible

💾 Smart Caching

  • LRU cache with configurable TTL
  • Automatic cache invalidation
  • Minimal API calls

🔄 Real-time Updates

  • React hooks for easy integration
  • Optimistic updates
  • Error handling built-in

🛡️ Type Safety

  • Full TypeScript support
  • Typed API responses
  • IntelliSense everywhere

API Reference

withNextSEO(config)

Creates the Next.js middleware function.

interface NextSEOConfig {
  apiUrl: string;      // Your Worker API URL
  apiKey: string;      // Admin API key
  siteId: string;      // Unique site identifier
  cache?: boolean;     // Enable caching (default: true)
  cacheTTL?: number;   // Cache TTL in seconds (default: 60)
  debug?: boolean;     // Enable debug logging
}

useNextSEO()

Hook to access SEO data for the current page.

const {
  metadata,        // Current page metadata
  content,         // Content blocks array
  redirect,        // Redirect info (if any)
  loading,         // Loading state
  error,           // Error state
  updateMetadata,  // Update function
  updateContent,   // Update content function
} = useNextSEO();

useContent(key)

Hook to get a specific content block.

const heroTitle = useContent('hero_title');

Environment Variables

# Required
NEXT_PUBLIC_SEO_API_URL=https://your-worker.workers.dev
NEXT_SEO_API_KEY=your-secret-admin-key

# Optional
NEXT_PUBLIC_SEO_SITE_ID=your-site-id

Advanced Usage

Custom Fetch Implementation

const middleware = withNextSEO({
  // ... other config
  fetch: customFetch, // Use your own fetch implementation
});

Programmatic Updates

const { updateMetadata } = useNextSEO();

await updateMetadata({
  title: 'New Page Title',
  description: 'Updated description',
  og_image: 'https://example.com/image.jpg',
});

Content Management

const { updateContent } = useNextSEO();

await updateContent('hero_title', 'Welcome to our new site!');

Troubleshooting

Middleware not running

Make sure your matcher in middleware.ts is configured correctly:

export const config = {
  matcher: [
    // Include all pages except API routes and static files
    '/((?!api|_next/static|_next/image|favicon.ico).*)',
  ],
};

SEO data not updating

  1. Check cache settings - you may need to reduce cacheTTL
  2. Enable debug mode to see API calls
  3. Verify your API key and permissions

TypeScript errors

Make sure to install the peer dependencies:

npm install next@latest react@latest react-dom@latest

License

MIT