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

@newskit-render/sitemap

v0.35.0

Published

Newskit Render - Sitemap package

Downloads

8

Readme

@newskit-render/sitemap

A package used for the generation of different types of sitemaps. You can see an example here: @newskit-render/core

Getting started

Add it as a dependency:

npm install @newskit-render/sitemap

or

yarn add @newskit-render/sitemap

Create sitemap pages

Under your /pages/api folder create sitemap.ts and news-sitemap.ts files.

Implementation

genericSitemap

sitemapXml - generic function which is needed by Next.js to resolve page route

genericSitemap - this function will handle the logic for sitemap.xml and sitemap.xml?query=1 routes. It will receive the following parameters:

context (required) - Next.js context object (only needs res and query from context but its easier to destructor as below)

publisher, domain, firstArticleDate, publicationName (required): Required properties for correctly building the sitemap.xml. The domain is the domain of your website. The firstArticleDate is the date of the first article you have published, this will set from when the generic sitemap will produce query sitemaps. publisher is the name of the publisher in the NewsKit API, this string will be used for fetching the articles for the correct publication. publicationName is the name of the publication, used inside the sitemap <news:name>${publicationName}</news:name> tag.

CustomStaticPageCollection (optional): Provides the possibility to manually add a list of static pages, that do not exist in an API. The format of the static page is in the example. Below an example.

import { NextApiRequest, NextApiResponse } from 'next'
import { genericSitemap, PublisherGroup, CustomStaticPage } from '@newskit-render/sitemap'

const defaultCustomStaticPagesCollection: CustomStaticPage[] = [
  {
    channel: 'test-custom-page',
  },
]

const handler = async (req: NextApiRequest, res: NextApiResponse) =>
  genericSitemap({
    res,
    query: req.query,
    publisher: process.env.PUBLISHER as PublisherGroup,
    domain: new URL(process.env.SITE_HOST).host,
    firstArticleDate: process.env.SITEMAP_FIRST_PUBLICATION_DATE,
    publicationName: process.env.SITEMAP_PUBLICATION_NAME,
    customStaticPageCollection: defaultCustomStaticPagesCollection,
  })

export default handler

You will find the env vars in /helm/value-{env}.yaml

example values are:

publisher: 'VIRGIN',
domain: 'virginradio.co.uk',
firstArticleDate: '2016-3-1',
publicationName: 'Virgin Radio',

newsSitemap

newsSitemap - this function will handle the logic for news-sitemap.xml.ts route. It will receive the following parameters:

context (required) - Next.js context object (only needs res from context but its easier to destructor as below)

publisher, domain, publicationName (required): Required properties for correctly building the sitemap.xml. The domain is the domain of your website. publisher is the name of the publisher in the NewsKit API, this string will be used for fetching the articles for the correct publication. publicationName is the name of the publication, used inside the sitemap <news:name>${publicationName}</news:name> tag.

Below an example.

import { NextApiRequest, NextApiResponse } from 'next'
import { newsSitemap, PublisherGroup } from '@newskit-render/sitemap'

const handler = async (req: NextApiRequest, res: NextApiResponse) =>
  newsSitemap({
    res,
    publisher: process.env.PUBLISHER as PublisherGroup,
    domain: new URL(process.env.SITE_HOST).host,
    publicationName: process.env.SITEMAP_PUBLICATION_NAME,
  })

export default handler

You will also need to add this to the next.config.js file:

module.exports = {
    async rewrites() {
        return [
            {
                source: '/sitemap.xml',
                destination: '/api/sitemap'
            },
            {
                source: '/news-sitemap.xml',
                destination: '/api/news-sitemap'
            }
        ];
    }
}