noddity-lazy-static-render
Render Noddity posts on demand, and cache results in-memory
Last updated 3 years ago by tehshrike .
WTFPL · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install noddity-lazy-static-render 
SYNC missed versions from official npm registry.

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.

API

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

Example

post:

---
title: TEMPLAAAATE
markdown: false
---

<h1>{{metadata.title}}</h1>
<article>{{>current}}</article>

file1.md:

---
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>
<head><title>{{siteName}}</title></head>
<body>{{{html}}}</body>
</html>`
})

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

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

License

WTFPL

Current Tags

  • 2.0.0                                ...           latest (3 years ago)

5 Versions

  • 2.0.0                                ...           3 years ago
  • 1.1.0                                ...           4 years ago
  • 1.0.2                                ...           4 years ago
  • 1.0.1                                ...           4 years ago
  • 1.0.0                                ...           4 years ago
Maintainers (1)
Downloads
Today 0
This Week 1
This Month 1
Last Day 1
Last Week 0
Last Month 5
Dependencies (4)
Dev Dependencies (6)
Dependents (1)

Copyright 2014 - 2016 © taobao.org |