Skip to content

Read-only REST API for Jekyll, making it easy to fetch all posts/settings in JSON for javascript search or advanced queries.

Notifications You must be signed in to change notification settings

riichard/jekyll-rest-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Jekyll REST API

This is a read only JSON API, making it easier to connect third party systems to your content, or do more advanced renderings with javascript on your jekyll site that can't be done with the liquid syntax.

Table of contents

Ideas of what you can build with this API:

  • Search through all your Jekyll posts with javascript, without having to parse the HTML.
  • Define settings for your javascript via your _config.yml.
  • Create a javascript code that will alert the user on the screen when there is a new post available.
  • Apply filters to the post content before rendering, such as wrapping all images in a different code for a lightbox system.

Installation

Via git submodule

Installing
git submodule add 'https://github.com/riichard/jekyll-rest-api'
Usage
http://myjekyllsite.com/jekyll-rest-api/posts.json

This also works like a charm on .github.io URLs.

Via bower

Installing
bower install jekyll-rest-api
Usage
http://myjekyllsite.com/bower_components/jekyll-rest-api/posts.json

Output examples

All output examples can also be found in the output-example folder.

/posts.json

[
		{
            "id"         : "/The unique ID of the post",
            "title"      : "The title of the post",
            "category"   : "demo",
            "tags"       : "demo,test",
            "url"        : "/url-according-to-config-defined-formatting",
            "path"       : "_posts/2015-07-21-demo.md",
            "next"       : "/path-to-next-post-or-empty-string",
            "previous"   : "/path-to-previous-post-or-empty-string",
            "date"       : "2015-07-26 04:00:00 -0400",
            "shortdate"  : "July 26, 2015",
            "content"    : "<p>Escaped content</p>",
            "excerpt"    : "<p>First paragraph of post</p>",
		} 
        ....
]
JSONP - Cross domain access

To access this file cross domain, you can load /posts.js and create a callback function called jekyllPostsCallback. Due to technical limitations of static file servers it's not possible to pass a custom callback function name.

/settings.json

{
    "title": "Richard A. Kraaijenhagen",
    "description": "Full Stack Developer & Data Scientist/Visualizer. Founder Owlin.",
    "default_bg": "avatar_45.jpg",
    "search": "true",
    "share": "true",
    "readtime": "true",
    "wpm": "200",
    "baseurl": "",
    "fin_color": "255,255,255",
    "timezone": "America/New_York",
    "encoding": "utf-8",
    "categories": [
        "owlin"
    ],
    "tags": [
        "owlin",
        "vim"
    ],
}

This will contain all keys defined in _config.yml. Due to a conflict with jekyll, this file couldn't be named config.json but is named settings.json instead.

JSONP - Cross domain access

To access this file cross domain, you can load /settings.js and create a callback function called jekyllSettingsCallback. Due to technical limitations of static file servers it's not possible to pass a custom callback function name.

About

Read-only REST API for Jekyll, making it easy to fetch all posts/settings in JSON for javascript search or advanced queries.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published