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

contentlayer-datapad

v1.0.22

Published

Awesome Contentlayer configuration with GFM, LQIP, TOC and more.

Downloads

166

Readme

datapad

Awesome Contentlayer configuration with GFM, LQIP, TOC and more.

It includes the following plugins:

Installation

yarn add contentlayer-datapad

Setup

import { defineDocumentType, makeSource } from 'contentlayer/source-files';
import {
  computeFields,
  remarkPlugins,
  rehypePlugins,
} from 'contentlayer-datapad';

export const Blog = defineDocumentType(() => ({
  name: 'Blog',
  filePathPattern: `blog/**/*.mdx`,
  contentType: 'mdx',
  fields: {
    title: {
      type: 'string',
      required: true,
    },
    description: {
      type: 'string',
      required: true,
    },
    date: {
      type: 'date',
      required: true,
    },
    image: {
      type: 'string',
      required: false,
    },
  },
  computedFields: computeFields<'Blog'>({}),
}));

const source = makeSource({
  contentDirPath: './content',
  documentTypes: [Blog],
  mdx: {
    remarkPlugins: remarkPlugins(),
    rehypePlugins: rehypePlugins({}),
  },
});

export default source;

Also, update your Tailwind config to include the following:

import type { Config } from 'tailwindcss';

const config: Config = {
  content: ['./node_modules/contentlayer-datapad/**/*.js'],
  // ...
};

export default config;

Configuration

computeFields

computeFields accepts a configuration object with the following properties:

| Property | Type | Description | Default | | --- | --- | --- | --- | | openGraphEndpoint | string | The endpoint of the Open Graph image generator (i.e. @vercel/og) | '/api/og' | | imagesFolder | string | The folder where your images are stored, prepended to the document image path | './public' |

The computed fields are:

| Field Name | Type | Description | Example Output | | --- | --- | --- | --- | | slug | string | The slug of the document, used in the URL | '/blog/my-post' | | slugAsParams | string | The slug as a path segment | 'my-post' | | readingTime | string | The estimated time to read the document, in minutes | '5 min read' | | toc | json | The table of contents of the document | [{ value: 'Heading 1', depth: 1, url: '#heading-1' }] | | imageBlur | string | The LQIP image data of the document | 'UklGRkgAAABXRUJQVlA4IDwAAADQAQCdASoQAAkABUB8JYwC7ADbW2wxAAD+5fWSusCgEGgrbEnESec12AakPGs5RtCwUs8GJTOZH7EgIAA=' |

remarkPlugins

remarkPlugins does not accept any configuration.

rehypePlugins

rehypePlugins accepts a configuration object with the following properties:

| Property | Type | Description | Default | | --- | --- | --- | --- | | shikiTheme | Theme | The theme to use for syntax highlighting | 'one-dark-pro' |

Usage

Here's how to use the custom fields in your Next.js app:

import { allBlogs } from 'contentlayer/generated';
import Image from 'next/image';
import type { Toc } from 'contentlayer-datapad';

return allBlogs.sort(sortBlogPostByDate).map((post) => (
  <div key={post.name}>
    <Image
      src={src}
      width={1920}
      height={1080}
      alt=""
      blurDataURL={`data:image/jpg;base64,${post.imageBlur}`}
      placeholder="blur"
    />

    <p>{post.readingTime}</p>

    <ul>
      {(post.toc as Toc).map((item) => (
        <li
          key={item.url}
          style={{
            paddingLeft: `${item.depth - 2}rem`,
          }}
        >
          <a href={item.url}>{item.value}</a>
        </li>
      ))}
    </ul>
  </div>
));