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

markedpage

v0.1.14

Published

Markdown source provider & classification utilities

Downloads

8

Readme

MarkedPage

A Markdown provider for my sveltekit static blog.

Features

  • Markdown source provide
  • Customize Classification
  • Support <!-- more --> tag, it will add excerpt into frontmatter
  • Use marked to parse markdown context.

Usage

  1. Create ./src/site.config.js to configure setting.
const config = {
  title: 'TestWebSite',
  classifier: [
    { id: 'post', params: { path: '/_posts/' }, type: 'directory' },
    { id: 'tag', params: { keys: ['tag', 'tags'] }, type: 'frontmatter' }
  ],
  marked: {
    options: {},
    extensions: {}
  }
};

export default config;
  1. Create ./docs/_posts/2022-04-28-post1.md and put markdown files in it.
/
|_docs
  |_posts
    |_2022-04-28-post1.md
  1. Use getPage or classifiedSet to get page context or page list in endpoints.
// example.ts
import type { DirectoryClassifierResult } from 'markedpage';
import { getPage, classifiedSet } from 'markedpage';
import type { RequestHandler } from '@sveltejs/kit';

export const get: RequestHandler = async () => {
  // Get list.
  const pageSet: DirectoryClassifierResult = await classifiedSet('post');
  const pages = pageSet.pages;
  // Get page.
  const page = await getPage('post1');
  const context = await page.render();

  return {
    body: {
      pages: pages,
      metadata: page.frontMatter,
      body: context
    }
  };
};

Example

<!-- 2022-04-28-firstpage.md -->

title: FirstPost
tags:
- test
---

This is summary field.

<!-- more -->

This is context block.

It will be passed to

{
  frontMatter: {
    title: 'FirstPost',
    tags: [ 'test' ],
    excerpt: 'This is summary field.',
    created: 2022-04-28T00:00:00.000Z
  },
  sourcePath: 'docs/2022-04-28-firstpage.md',
  indexPath: 'docs/2022-04-28-firstpage',
  render: [Function: render],
  raw: [Function: raw],
  slugKey: 'firstpage'
}

Markdown Vite HMR Support

  • Add markedpageVitePlugin() to config.plugins
// vite.config.js
import { sveltekit } from '@sveltejs/kit/vite';
import { markedpageVitePlugin } from 'markedpage';

import siteConfig from './src/site.config.js';

/** @type {import('vite').UserConfig} */
const config = {
	plugins: [sveltekit(), markedpageVitePlugin(siteConfig)]
};

export default config;
  • Listen to onContentUpdate and update the endpoint with invalidate.
// src/routes/
<script lang="ts">
  import { invalidate } from '$app/navigation';
  import { page } from '$app/stores';
  import { onContentUpdate } from 'markedpage/helper';
  
  onContentUpdate((payload) => {
      let slug = $page.params.slug;
      // update endpoint data.
      invalidate(`/api/posts.json`);
      invalidate(`/api/posts/${slug}.json`);
  });
</script>

Example

https://github.com/saweima12/markedpage-example

ChangeLog

  • [2022-08-22] v0.1.14 - breakingMove onContentUpdate to markedpage/helper [issues]
  • [2022-08-18] v0.1.13 - Optimize markdown file reload.
  • [2022-07-22] v0.1.10 - Fix: marked config is not loaded properly
  • [2022-07-22] v0.1.8 - Add support for site.config.js auto-reload via configuration
  • [2022-07-18] v0.1.7 - Replace chalk.js with kleur
  • [2022-07-16] v0.1.5 - Add markdown file Vite HMR Support.
  • [2022-05-31] Add _draft field support in FrontMatter.(It will not be added to list in production)
  • [2022-05-27] Add extendPageData support