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 🙏

© 2026 – Pkg Stats / Ryan Hefner

remark-preview-to-frontmatter

v1.0.0

Published

remark plugin to add text from the beginning of a document to a property in frontmatter.

Downloads

12

Readme

remark-preview-to-markdown

remark plugin to add text from the beginning of a document to a property in frontmatter.

Contents

What is this?

This is a unified (remark) plugin that extracts some text from the beginning of a markdown file (not including frontmatter and comments) and adds the extracted text as a frontmatter property.

When should I use this?

This plugin is useful in use cases where a preview of the document must be part of the files metadata. For example, blogging sites may use this to show a snippet of each individual blog post in a list of multiple posts.

This plugin selects the snippet based on a number of characters, hence for something like an abstract in a journal article, this plugin is not useful.

Install

The package is only available on npm:

npm install remark-preview-to-frontmatter

Use

Consider exmaple.md

_Lorem Ipsum_ is simply **dummy text** of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.

sourced from [lipsum.com](https://www.lipsum.com/)

To add a preview of this file in markdown, the following is done:

import fs from "fs/promises";
import { remark } from "remark";
import remarkFrontmatter from "remark-frontmatter";
import remarkPreviewToFrontmatter from "remark-preview-to-frontmatter";

const inputFIle = "./example.md";
const outputFile = "./output.md";

const inputMarkdown = await fs.readFile(inputFIle, "utf-8");

const outputMarkdown = await remark()
  .use(remarkFrontmatter)
  .use(remarkPreviewToFrontmatter, { charLimit: 100 })
  .process(inputMarkdown);

await fs.writeFile(outputFile, String(outputMarkdown));

output.md would look like this

---
preview: Lorem Ipsum is simply dummy text of the printing and typesetting
  industry. Lorem Ipsum has been the ...

---

*Lorem Ipsum* is simply **dummy text** of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.

sourced from [lipsum.com](https://www.lipsum.com/)

API

The package only provides the default export used as a plugin to remark. Provding options is of course optional.

remark().use(remarkPreviewToFrontmatter, options)

PluginOptions

| Field | type | default | purpose | | ------------------------- | ------------ | ------- | -------------------------------------------------------------------- | | charLimit | int | 200 | the number of maximum number of characters to include in the preview | | frontmatterKey | string | preview | defined the key to use in the frontmatter | | appendEllipsis | bool | true | whether to add "..." at end of preview | | allowMultipleLines | bool | false | removes new lines and redundant whitespace from the text | | trailingWordBreakPolicy | (see bellow) | break | how to handle a word if the charLimit lies within it |

trailingWordBreakPolicy acts when only part of the last word is included in the preview. For example, if the last word is hello and the charLimit is such that only the first three letters are taken, each policy will handle this scenario differently:

| policy | result | explanation | | ----------- | ----------- | --------------------------------------------------------------- | | break | hel | will strictlly apply the character limit | | full word | hello | will preserve the whole word, exceed the limit | | remove | (nothing) | will remove the incomplete word entirely, going under the limit |