Skip to content

jason-huh/jikji

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

54 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Jikji

Pypi Build Status

Static website generator based on RESTFul Server

What's different

In common static website generator like Jekyll, it transform plain text like mardown to html.

But jikji generate pages based on JSON data returned in RESTFul Server.

You can use "Rest-base Cloud Database" like IBM Cloudant as RESTFul Server, so you don't need to code RESTFul server yourself.

We call the JSON data that gotten from RESTFul Server model.
After getting model, you can access it in template like {{ article_content }}.

Code for getting data from model and generate template is NOT needed.
You just write some configs and templates of website, then jikji will create static website greatly.

Install

$ pip install jikji

Usage

$ jikji <my_site> generate

or

from jikji import Jikji
jikji = Jikji('my_site')
jikji.generate()

template engine

jikji use Jinja2 template engine which is used in Flask.
You can see jinja template documentation on here.

config.json

Configure directory structure of site, and rest api server's information.

{
	"server_info": {
		"type": "cloudant",
		"baseurl": "https://rexpress.cloudant.com/",
		"headers": {
			"Authorization": "Basic aGVsbG93b3JsZDpoZWxsb3dvcmxkMTIz="
		}
	},
	"path": {
		"template": "templates",
		"output": "generated",
		"assets": [
			"assets"
		],
		"pages_xml": "pages.xml"
	}
}

pages.xml

Config pages of static website. Each page tag generates one static website, and it has 3 properties.

  • url is URL of each output static page.
    • If url is ends with '/', $path/index.html will be generated
  • context is data object used in template, getting from cloudant.
  • template is path of html template file.

Specially, pages.xml is also parsed like template. So, in pages.xml, you can use for, foreach, if, and other grammars.

You can use model variable in pages.xml, which you can connect to RESTFul Server. After getting data in RESTFul Server, you can make page tag with model data like below.

<?xml version="1.0" encoding="UTF-8" ?>
<site>
	{% set all_docs = model.get('/_all_docs') %}
	<page>
		<url>/</url>
		<context>{{ all_docs }}</context>
		<template>home.html</template>
	</page>
	{% for id in all_docs.rows %}
	<page>
		<url>/doc/{{ id }}/</url>
		<context>{{ model.get('/doc/' + id) }}</context>
		<template>document.html</template>
	</page>
	{% endfor %}
</site>

After template is rendered, jikji generate pages by this information.

First, generator get template file declared in template tag.
And then, inject context data to template and render it.
Finally, create static page file with name declared in url tag.

You can look sample

sample response of /_all_docs

{
	"site": "Sample site",
	"rows": [
		"a69425f9d9dc1b",
		"ca3dfe24aaeca0"
	]
}

rendered pages of sample

  • /index.html
  • /doc/a69425f9d9dc1b/index.html
  • /doc/ca3dfe24aaeca0/index.html

Realtime develop

You don't have to generate all the time after modify template.
Jikji has useful function to develop in realtime

run jikji as listening mode

$ jikji <my_site> listen
$ jikji <my_site> listen --port PORT --host HOST

Then you can see rendered website in your browser (default: http://localhost:7000)

Web server opened with Flask, and when you reload the website, jikji will re-rendering template

But one server is opened, jikji DO NOT reload MODEL from rest server.
Please close flask server if you need to reload model data.

About

Static website generator based on RESTFul Server πŸ“œ

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 90.5%
  • HTML 9.3%
  • CSS 0.2%