Elao/blogd

Name: blogd

Owner: Elao

Description: null

Created: 2014-10-01 09:51:44.0

Updated: 2015-03-16 07:09:47.0

Pushed: 2014-12-20 10:53:30.0

Homepage: null

Size: 306

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Blogd

Blogd allow you to retrieve blog's posts and meta from a folder, a git repository or a remote zip and expose them via an API. It's useful when you want to manage a collaborative blog with github for example. Blogd is maintained by http://www.elao.com and is use at http://www.elao.com/blog. The content repository of the blog is located at http://www.github.com/elao/tech-blog.

Configuration

Add a config.js file (copy / past the config.js.dist for example). Or you can also define a blogd config key in your package.json file (or in ../../package.json file).

Example of config.js file

'use strict';

exports.port          = process.env.PORT || 5555;
exports.host         = '127.0.0.1';
exports.store         = 'memory'; // or memory
exports.outputFolder  = __dirname + "/content";
exports.backupFile    = __dirname + "/current.json";
exports.assetsToCopy  = [{
    from: exports.outputFolder + "/posts/images/",
    to:   __dirname + "/public/images",
    url: "/images/"
}];

exports.security = {
    rules: {
        guest:  {},
        admin:  {}
    },
    basic: {
        realm:    'Blogd Private Api',
        user:     'admin',
        password: 'private'
    }
};

exports.source = {
    type:        'zip',
    url:         'https://github.com/Elao/tech-blog/archive/master.zip'
}

Available configuration options:

<tr><th>key</th><th>default</th><th>description</th></tr>
<tr><td>host</td><td>'127.0.0.1'</td><td>Binded host</td></tr>
<tr><td>port</td><td>5555</td><td>Binded port</td></tr>
<tr><td>store</td><td>'memory'</td><td>The store to use to store the blog data (only 'memory' is supported now)</td><tr>
<tr><td>outputFolder</td><td>'./content'</td><td>The folder where to dump the grabbed content</td></tr>
<tr><td>backupFile</td><td>'./current.json'</td><td>Path of the file where consolidated json data should be backed up</td></tr>
<tr>
    <td>assetsToCopy</td>
    <td>[]</td>
    <td>
        array of folder to copy and/or map.<br /> 
        The object should contains: <br />
        <ul>
            <li>**from** : The folder to copy (*required*)</li>
            <li>**to** : The destination folder (*required*)</li>
            <li>**url** : The absolute url to bind the folder (if none, it'll not be mapped)</li>
    </td>
</tr>
<tr>
    <td>source</td>
    <td>no default.</td>
    <td>
        Where to find the content.
        <ul>
            <li> **type** : The type of source (local, git, zip)</li>
            <li> **url** : The url of the zip file (for the *type zip*)</li>
            <li> **path** : The path to folder to get data from (for the *type local*)</li>
            <li> **repository** : The url of the git repository (for the *type git*)</li>
        </ul>
    </td>
</tr>

API

MethodRouteParamsDescription
GET/postslimit The number of posts to retrieve
offset The offset
status Filter by post status
Retrieve list of blog's post ordered by publish date desc
GET/posts/:tagtag: a tag
limit The number of posts to retrieve
offset The offset
status Filter by post status
Retrive list of blog's post by tag
GET/post/:slugslug: a post's slugRetrieve a single post
GET/tags**none**Retrieve the list of available tags
GET/authors**none**Retrieve the list of authors
GET/authors/:slugslug: slug or email of an authorRetrieve an author
GET/authors/:slug/postsslug: slug or email of an authorRetrieve list of posts from given author
GET/status**none**Retrieve the content status (last update, number of tags, posts, authors, ...)
GET/refresh**none**Force the refresh of the data by retrieving the remote data from the source

Assets mapping

In your config, you can define mapped directories from your source, to a folder and an url. For example:

exports.assetsToCopy  = [{
    from: exports.outputFolder + "/posts/images/",
    to:   __dirname + "/public/images",
    url: "/images/"
}];

Blogd will copy the content of /posts/images/ from your repository, to the Blogd local directory /public/images and then map the /public/images/ folder to the url /images/ For example, if you have a file /posts/images/myimage.png in your repository, you'll be able to access the file to http://localhost:5555/images/myimage.png

Content structure

The content of the source must be structured this way (you can find an example at https://github.com/Elao/tech-blog)

Users file:

Must be at the root of the repo and named users.json

Example of users.json file:

[{
    "name":  "Vincent",
    "slug":  "vincent",
    "email": "vincent.bouzeran@elao.com"
},{
    "name":  "Guewen",
    "slug":  "guewen",
    "email": "guewen.faivre@elao.com"
}]
Tags file:

Must be at the root of the repo and be named tags.json It contains the allowed tags used in posts. If a post use a tag not referenced in these file, the tag will be ignored. Properties label and slug on tag objets are mandatory, but you can add other metas and you'll get them back through the API.

Example of tags.json file:

[
    {"label": "Symfony", "slug": "symfony"},
    {"label": "HTML/CSS", "slug": "html-css"},
    {"label": "Webdesign", "slug": "webdesign"},
    {"label": "Framework", "slug": "framework"},
    {"label": "Translation", "slug": "translation"},
    {"label": "Form", "slug": "form"},
    {"label": "Theming", "slug": "theming"},
    {"label": "Linux", "slug": "linux"},
    {"label": "Tips", "slug": "tips"},
    {"label": "Talk", "slug": "talk"},
    {"label": "PHP", "slug": "php"}
]
Posts file:

The post files must be placed in the /posts folder. Each post must have two files: a markdown file and a meta file.

For each post, you need to have 2 files in the /posts folder

The two files must have the same name except the extension.

Example:

If your post is named “mysuperblogpost”, you must have these two files in the /posts folder:

Post meta file

The post meta file contains information about the associated blog post.

The metas are like this:

MetaDescription
_slug_ \*The post's slug (used to identify the post. Must be unique among all posts)
_title_ \*The post's title
_tags_List of post's tag (must be reference by slug or label of tags contains in the tags's file)
_status_ \*The post's status ("published", "draft")
_publish_by_ \*The publisher of the post (must be the reference of a user contains in the users's file either by email or slug)
_publish_at_ \*A date (any format supported by Moment.js)
_meta_title_The html meta title of the post
_meta_description_The html meta description of the post

* indicate required metas

Additional metas will be exposed by the blogd api.

Example of a post meta file:


"tags":                 ["Infra", "Proxmox", "Linux"],
"title":                "Partitioning a proxmox server",
"slug":                 "partitioning-a-proxmox-server",
"status":               "published",
"meta_category":        "virtualisation",
"meta_title":           "Partitioning a proxmox server",
"meta_description":     "How to do it clean and effective",
"meta_language":        "en",
"meta_keywords":        ["Proxmox", "Infra", "Linux", "OVH"],
"thumbnail":            "/blog/medias/thumbnails/proxmox.png",
"publish_by":           "guewen-faivre",
"publish_at":           "2014-11-13"

TODO


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.