Skip to content

Commit

Permalink
Release version 0.1a2
Browse files Browse the repository at this point in the history
Release version 0.1a2 of Stone
  • Loading branch information
neuralsandwich authored Jul 23, 2017
2 parents e0b2429 + 0a7cc9d commit c281d5f
Show file tree
Hide file tree
Showing 15 changed files with 562 additions and 328 deletions.
14 changes: 10 additions & 4 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
Stone Changelog
===============
# Stone Changelog

Here are the release notes for each version of Stone.

Version 0.0.1
-------------
## Version 0.1 - WIP

* Add init and newpage commands
* Add versioned site.json
* Add support for footnotes

## Version 0.0.1

* Generate HTML from Markdown
* jinja2 templating is processed in HTML files
* Installable through setup.py
* Can generate basic template
52 changes: 29 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# stone
# Stone

Yet another static website generator.

Used by half.systems
Used by (www|blog).half.systems


# Installation
Expand All @@ -19,51 +19,57 @@ To get started with `stone`:
stone example_site init --site-name 'example.com'
# Generate site
stone example_site generate
# Add a new page
stone example_site newpage --name "About Us"


## Folder Structure

Site projects can be structured as you wish.
Stone is designed to generate the subdomains of half.systems. The following is
the layout of the sites:

The layout which stone was developed along side is:

* root
* blog
* main
* templates
* templated HTML for blog and main
* site.json
.
├── blog
│   └── ...
├── main
│   └── ...
├── site.json
└── templates
└── ...

As `site.json` is explicit about the location of templates and files, the
structure is flexible. You could locate separate template folder inside each
site or have one giant mess in your project root.

[`site.json` is very flexiable](docs/site-json.md) about the location of
templates and files. As such your not constrained to any particular layout for
your site. You could have separate template folders inside each site or have
one giant mess in your project root.


## Pages

The source markdown files should consist of simple markdown with a YAML header
Pages are Markdown files with some optional YAML metadata
that describe the attributes of the generated page including the page title and
the template it uses. For example:


```
---
template: base.html
title: TEST
title: Hello, World
# This is a header
Here is so lovely content.
Here is some lovely content.
```

There are additional attributes:

* date - Adds the date the page was create to the page metadata. This is
currently used when generating indexes for blogs. Format YYYY-MM-DD
Stone makes all metadata available to page templates. Any data templates may use
can be embedded into a page. For exampled the data, an authors name and email,
etc.


## Templates

Templates support **jinja2**, an example:
Templates are HTML pages with **[jinja2](http://jinja.pocoo.org)** markup.

`base.html`:

Expand All @@ -87,8 +93,8 @@ Templates support **jinja2**, an example:

## Generating

To generate a particular site invoke `stone` with the location of the
project's root folder.
To generate a particular site invoke `stone` with the location of the project's
root folder.

```
stone root_folder generate
Expand Down
1 change: 0 additions & 1 deletion example/README.md

This file was deleted.

30 changes: 19 additions & 11 deletions example/site.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
{
"sites": [
{
"site": "example.com",
"pages": [
"version": 1,
"sites": [
{
"source": "README.md",
"target": "README.html"
"site": "example.com",
"source": "source",
"target": "target",
"pages": [
{
"source": "index.md",
"target": "index.html",
"page_type": "index"
},
{
"source": "example.md",
"target": "example.html",
"page_type": "post"
}
]
}
],
"templates": ["templates"]
}
]
}
]
}
4 changes: 4 additions & 0 deletions example/source/example.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
title: Hello, World!

# Hello, World!
6 changes: 6 additions & 0 deletions example/source/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

{% for post in posts %}
<ul>
<li><a href="{{ post.href }}">{{ post.title }}</a></li>
</ul>
{% endfor %}
26 changes: 0 additions & 26 deletions example/templates/base.html

This file was deleted.

3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
css_html_js_minify
jinja2
Markdown
css_html_js_minify
unidecode
10 changes: 5 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Setup script for Stone
See:
https://github.com/NeuralSandwich/stone
See: https://github.com/NeuralSandwich/stone
"""

# To use a consistent encoding
Expand All @@ -21,8 +20,8 @@

setup(name='stone-site',

# Versions should comply with PEP440. For a discussion on single-sourcing
version='0.1a1.dev3',
# Versions should comply with PEP440. For a discussion on single-sourcing
version='0.1a2',


description='Static site generator',
Expand Down Expand Up @@ -59,7 +58,8 @@

# List run-time dependencies here.
# https://packaging.python.org/en/latest/requirements.html
install_requires=['jinja2', 'Markdown'],
install_requires=['css_html_js_minify', 'jinja2', 'Markdown',
'unidecode'],
extras_require={
'dev': ['check-manifest'],
'test': ['coverage'],
Expand Down
68 changes: 45 additions & 23 deletions stone/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,48 @@
import argparse
import os

from .stone import generate_site, init_site, new_page
from stone.stone import generate_site, init_site, new_page


def add_newpage(parser):
"""Add arguments for newpage command"""
subparser = parser.add_parser(
'newpage', help=('add a new page to site.json and an emtpy file'))
subparser.add_argument(
"source",
type=str,
help='input filename')
subparser.add_argument(
"--target",
type=str,
help='output filename')
subparser.add_argument(
"--page-type",
default="post",
type=str,
help='type of page to generate')
subparser.set_defaults(func=new_page)


def add_init(parser):
"""Add arguments for init command"""
subparser = parser.add_parser(
'init', help=('create a template site.json'))
subparser.add_argument(
"--type", default="blog", type=str, help='type of site to generate')
subparser.add_argument(
"--site-name",
type=str,
help='name of the site: example.com',
required=True)
subparser.set_defaults(func=init_site)


def add_generate(parser):
"""Add arguments for generate command"""
subparser = parser.add_parser(
'generate', aliases=['gen', 'build'], help=('generate site'))
subparser.set_defaults(func=generate_site)


def main(args=None):
Expand All @@ -18,32 +59,13 @@ def main(args=None):
subparsers = parser.add_subparsers(title='commands', help='commands')

# stone build <path>
build_parser = subparsers.add_parser(
'generate', aliases=['gen'], help=('generate site'))
build_parser.set_defaults(func=generate_site)
add_generate(subparsers)

# stone init <path>
init_parser = subparsers.add_parser(
'init', help=('create a template site.json'))
init_parser.add_argument(
"--type", default="blog", type=str, help='type of site to generate')
init_parser.add_argument(
"--site-name",
type=str,
help='name of the site: example.com',
required=True)
init_parser.set_defaults(func=init_site)
add_init(subparsers)

# stone newpage <path>
newpage_parser = subparsers.add_parser(
'newpage', help=('add a new page to site.json and an emtpy file'))
newpage_parser.add_argument(
"--page-type",
default="post",
type=str,
help='type of page to generate')
newpage_parser.set_defaults(func=new_page)

add_newpage(subparsers)
args = parser.parse_args()

if not os.path.isdir(args.site_root):
Expand Down
52 changes: 52 additions & 0 deletions stone/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
"""Config
Stone's representation for site.json
"""
import errno
import json
import os
import sys

from stone.site import Site, SiteEncoder


class Config(object):
"""Loader site.json"""

site_config_file = "site.json"

def __init__(self):
pass

def read(self, path):
"""Load site configuration"""
configs = []
try:
json_data = json.loads(
open(os.path.join(path, self.site_config_file), "r").read())
except FileNotFoundError as fnf:
if fnf.errno != errno.ENOENT:
raise
else:
print("[ERROR] No path to site config")
return 1

try:
if json_data["version"] != 1:
print(
"This is an older site.json and it doesn't checkout",
file=sys.stderr)
exit(1)
for site_data in json_data["sites"]:
configs.append(Site(path, site_data))
except KeyError:
configs.append(Site(path, site_data))

return configs

def write(self, path, sites):
"""Serialize a site to JSON"""
config = {'version': 1}
config['sites'] = sites
with open(os.path.join(path, self.site_config_file), "w") as cfg_file:
cfg_file.write(json.dumps(config, cls=SiteEncoder, indent=4))
Loading

0 comments on commit c281d5f

Please sign in to comment.