Render Noddity posts on demand, and cache results in-memory
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

A lazy renderer that caches the rendered HTML in-memory so future renders of that page will be as fast as possible.

Whenever a post changes, or the index.json changes, all HTML in the cache is cleared.

Some stuff is still kind of hardcoded - for example, right now it assumes you have a post named post that is your root post. If you need any changes, PRs+tests will be merged happily.


This module exports a single function.

makeLazyRenderer({ butler, data = {}, indexHtml })

Returns a lazyRender function.

  • butler: a noddity-butler instance
  • data [optional]: any data to be merged with the other data passed to Ractive to render the templates
  • indexHtml: a Ractive template for the rendered posts to be embedded in. It has access to the post's metadata object, as well as the html of the rendered file.

lazyRender({ key = '?', file, sessionData = {} })

Returned by the factory function above. Returns a promise that resolves to HTML based on the indexHtml passed to the factory function.

  • file: the post filename to be fetched from the butler.
  • key [optional]: a string identifier used for caching. Should uniquely identify the sessionData.
  • sessionData [optional]: data to be merged with the global data passed to the factory function, plus any data on the post, before rendering the html



markdown: false


title: Sweet example post
date: 2017-01-31T00:32:51.468Z

Some cool post

Library usage:

const lazyRender = createLazyRenderer({
	butler: butler,
	data: {
		siteName: 'Sweet Example Site'
	indexHtml: `<html>

const expected = `<html>
<body><h1>Sweet example post</h1> <article><p>Some cool post</p>

	file: ''
}).then(html => {
	html // => expected