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

nextjs-app-sitemap-generator

v1.0.5

Published

A package to generate sitemaps for Next.js applications

Downloads

15

Readme

nextjs-app-sitemap-generator

Table of Contents

Introduction

nextjs-app-sitemap-generator is a utility package designed to simplify the generation of sitemap.xml and robots.txt files for Next.js projects. It helps in managing SEO by creating comprehensive sitemaps and correctly configured robots.txt files based on the provided options.

Installation

To install this package, run:

npm install nextjs-app-sitemap-generator

or

yarn add nextjs-app-sitemap-generator

After installing the package, a generate-sitemap.mjs file will be created in the root of your project. If the file is not created automatically, you should manually create it.

Usage

Initializing the Sitemap

To initialize the sitemap and robots.txt generation, import the initializeSitemap function and provide a configuration object.

import { initializeSitemap } from 'nextjs-app-sitemap-generator';

initializeSitemap({
    baseUrl: process.env.SITE_URL || 'https://example.com',
    robotsTxtOptions: {
        policies: [
            { userAgent: '*', allow: '/' },
            { userAgent: '*', disallow: '/api' },
            { userAgent: '*', disallow: '/admin' },
            { userAgent: '*', disallow: '/admin-login' },
        ]
    },
    sitemapOptions: {
        unauthenticated: false,
        authenticated: true,
        ignore: ["ignore-path1", "ignore-path2"],
        otherPages: [
            "other-path1",
            "other-path2"
        ],
    }
});

This example demonstrates how to set up the sitemap generation in a Next.js project. The baseUrl can be set via an environment variable or a hardcoded string. The robotsTxtOptions and sitemapOptions are used to configure the generated robots.txt and sitemap.xml files, respectively.

Configuration Options

Sitemap Options

| Option | Type | Description | |-----------------|---------|-------------------------------------------------------| | unauthenticated | Boolean | Generate sitemap for unauthenticated pages if true. | | authenticated | Boolean | Generate sitemap for authenticated pages if true. | | ignore | Array | List of paths to ignore in the sitemap generation. | | otherPages | Array | List of other dynamic pages to include in the sitemap.|

robots.txt Options

| Option | Type | Description | |-----------|-----------------|-------------------------------------------------------| | policies | Array | List of policy objects defining rules for different user agents. | | userAgent | String | The user agent to apply the policy to. | | allow | String/Array | Paths to allow for the user agent. | | disallow | String/Array | Paths to disallow for the user agent. |

Folder Structure

The package expects the following folder structure in your Next.js project:

src
└── app
    ├── (unauthenticated)
    │   ├── test
    │   │   └── page.tsx
    │   └── example
    │       └── page.tsx
    ├── (authenticated)
    │   ├── dashboard
    │   │   └── page.tsx
    │   └── settings
    │       └── page.tsx
    ├── _document.js
    ├── _app.js
    └── ...
  • The (unauthenticated) folder contains pages that do not require authentication.
  • The (authenticated) folder contains pages that require authentication.
  • Other pages and components can be placed in the root of the app directory or other subdirectories.

Contributing

Contributions are welcome! Please open an issue or submit a pull request on GitLab.

License

This project is licensed under the MIT License. See the LICENSE file for details.