-
Notifications
You must be signed in to change notification settings - Fork 0
/
arale.py
74 lines (59 loc) · 1.85 KB
/
arale.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env python
import os
from liquidluck.writers.base import BaseWriter
from liquidluck.writers.core import PostWriter
from liquidluck.readers.base import Post
from liquidluck.options import g
try:
import json
_json_decode = json.loads
except ImportError:
import simplejson
_json_decode = simplejson.loads
class PackageWriter(BaseWriter):
writer_name = 'package'
def __init__(self):
path = os.path.join(g.source_directory, 'package.json')
if os.path.exists(path):
f = open(path)
g.resource['package'] = _json_decode(f.read())
f.close()
else:
g.resource['package'] = {}
def start(self):
"We don't write anything."
pass
class AraleWriter(PostWriter):
writer_name = 'arale'
def __init__(self):
self._template = 'post.html'
self._posts = {}
for post in g.public_posts:
if post.category:
if post.category not in self._posts:
self._posts[post.category] = [post]
else:
self._posts[post.category].append(post)
g.resource['category'] = self._posts
def start(self):
for post in g.public_posts:
self._arale_write(post)
def _arale_write(self, post):
template = post.template or self._template
if post.clean_filepath == 'README.md':
template = 'readme.html'
dest = os.path.join(g.output_directory, 'index.html')
else:
dest = self._dest_of(post)
self.render({'post': post}, template, dest)
class AralePost(Post):
@property
def date(self):
try:
order = int(self.meta.get('order', 0))
except:
order = 0
return 100 - order
@property
def category(self):
return self.clean_folder