Coder Social home page Coder Social logo

blad's Introduction

blað

A minimalist flat-file CMS with dynamic content.

Build Status Dependencies License

Features

  1. Reads content from Markdown files and YAML front-matter.
  2. No database or write access to disk needed.
  3. In-memory cache maintains dynamic content defined in helper functions.
  4. Powerful Swig templating.

Quickstart

$ npm install blad -g
$ blad --port 8080
# blad/4.0.0-alpha started on port 8080

Configuration

The following command will launch a blad server on port 5050, sourcing files from the example/ directory and keep all cached content for a period of 1 day.

$ ./bin/blad.js --port 5050 --source example/ --cache 1440

Content

The site pages are maintained as sets of Markdown files with YAML front-matter. The name corresponds to the url of the page so, for example, /content/people/radek.md will get mapped to the /people/radek URL.

Among the fields one can set in the front-matter, template is the most important one. It sets a Swig HTML file that will be used to render the page. Not specifying this property will make the page serve 204 No Content when accessed.

Fields are represented as key-value pairs of arbitrary depth.

Layouts

Is a place where Swig templates live. They can be extended and macros work too.

If a 404.html template is provided together with a document entitled 404.md, these will be rendered when a user tries to visit a page that does not exist.

You can access the URL of a page you are on by using the url key.

Relations

You can access content in other documents by using the relations helper object.

To get a list of top-level pages in the CMS use:

{% for page in rel.menu() %}
  {{ page.url }}
{% endfor %}

To get a list of sibling documents:

{% for page in rel.siblings(url) %}
  {{ page.url }}
{% endfor %}

You can get a list of children of depth n:

{% for page in rel.children(url, n) %}
  {{ page.url }}
{% endfor %}

Access the first existing parent document:

{% set parent = rel.parent(url) %}

Check if one document is the same as another or one of its descendants:

{% set isFamily = rel.isFamily('/people', '/people') %}

Or just check if one document is a child of another:

{% set isChild = rel.isChild('/people', '/people/radek') %}

Helpers

Are modules (in JS or CoffeeScript) that can be accessed at page render stage. Typically they will be used to access remote data to then be rendered in a page. In a YAML front-matter we would request a helper like so:

---
helpers:
  people: my_helper.js
---

The first time a page is rendered, the helper in my_helper.js is called. It is expected to be a function with two parameters, data and cb. The former is a map of key-value fields from the front-matter, the latter a callback for when the helper has done its job. As an example:

module.exports = (data, cb) => {
  // Do some work...

  // Call back.
  cb(null, result);
};

You can access 3rd party libraries here by defining them in package.json of the site.

The data is then accessible under the key people (in the example above) in the page layout and saved for --cache amount of time. This is a startup parameter and saves having us make potentially expensive operations every time a page is requested.

Public

All static content, like CSS and JS files, can be accessed here. Use /public/path in layouts when accessing these files.

blad's People

Contributors

bitdeli-chef avatar radekstepan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

intermine

blad's Issues

Holder type

...lives only on the client and works as an attribute group on Page types

'Points' to a bunch of files so we can retrieve them as a group

Use a signature on rendered resources

/**
 *
 *      _/    _/  _/_/_/
 *     _/  _/      _/        Qualaroo for theagileplanner.com
 *    _/_/        _/         (C) 2012 Qualaroo. All rights reserved.
 *   _/  _/      _/          qualaroo.com
 *  _/    _/  _/_/_/
 *
 * Version: 2012-07-27 16:03:21 -0700 (62dd6fa57f8b1866b7e0bb8d893f458fe4077d94)
 * Generated: 2012-07-30 23:22:15 +0000
 */

A Page Type

A default page type has these fields:

  • url (optional, making document public or not)
  • unique identifier in the system

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.