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

@financial-times/express-markdown-pages

v3.0.0

Published

An Express middleware that transforms plain text files into dynamic pages and fits right into your existing app.

Downloads

50

Readme

@financial-times/express-markdown-pages

CircleCI NPM version

An Express middleware that transforms plain text files into dynamic pages and fits right into your existing app.

const { MarkdownPages } = require('@financial-times/express-markdown-pages');

const markdownPages = new MarkdownPages();

app.get('/*', markdownPages.middleware, (request, response) => {
	const html = myTemplate(response.locals.markdownPages);
	response.send(html);
});

Installation

This is package for Node.js and is available through the npm registry. Node 20 or higher is required.

Installation is done using the npm install command:

npm install -S @financial-times/express-markdown-pages

Features

  • Fits right into your existing Express app, how you render the output is up to you!
  • Finds and transforms Markdown files into HTML with Origami compatible output.
  • Author content that works in your editor, on GitHub, and on your website.
  • Generates hierarchical navigation and user-friendly URLs.
  • Supports taxonomies to dynamically group and filter content.
  • Include images alongside your Markdown content, they'll work too.

Getting started

Start by creating a new instance of MarkdownPages and provide the appropriate options for your app:

const { MarkdownPages } = require('@financial-times/express-markdown-pages');

const markdownPages = new MarkdownPages({
	source: './content',
	pathPrefix: '/docs',
});

Next, add a new route to your app to serve your Markdown pages from, please note this must end with an asterisk (*) so that Express knows to route all requests to URLs beginning with this path through the MarkdownPages middleware:

app.get('/docs*');

Next, add the MarkdownPages middleware to the route you just added:

app.get('/docs*', markdownPages.middleware);

Next, add a final route handler function. This function can use the data added by the middleware to render your pages. Please note, if a page can't be found, or the incoming request is for an image file, then this function will not be called:

app.get('/docs*', markdownPages.middleware, (request, response) => {
	response.send(response.locals.markdownPages);
});

Finally, we recommend initialising MarkdownPages on app startup. This is not strictly necessary but it will help you to spot any errors with your content:

try {
	await markdownPages.init();

	app.listen(PORT, () => {
		console.log(`App listening on http://localhost:${PORT}`);
	});
} catch (error) {
	console.error('The app failed to start: ', error);
	process.exit(1);
}

Now you're up and running you can get on with using the data in your templates or carry on to the documentation for more examples.

Options

See the JSDoc type definitions for more information about configuration options.

Debugging

This package implements debug to provide detailed logs. You can enable these by setting the DEBUG environment variable:

DEBUG=express:markdownPages node app.js

Page data

The middleware provided by this package will append a markdownPages property to the response.locals object when a page matching the request is found. This object includes the content for the requested page and navigation hierarchy, and for index pages it will also include any information about taxonomies and tags used by child pages.

See the JSDoc type definitions for more information about page data.

Writing content

See the writing content guide for more information about the syntax and conventions for authoring content compatible with this package.

Screenshots

| In VSCode | On GitHub | Rendered on a website | | -------------------------------------------------- | -------------------------------------------------- | ------------------------------------------------------------ | | A page viewed in VSCode | A page viewed on GitHub | A page viewed in the web browser |