Skip to content
This repository was archived by the owner on Oct 23, 2020. It is now read-only.

Commit 00c55fc

Browse files
committed
Merge branch 'devel'
2 parents 075c2c6 + 3d1917d commit 00c55fc

31 files changed

Lines changed: 1275 additions & 119 deletions

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,6 @@ pip-log.txt
3636

3737
#OS X
3838
.DS_Store
39+
40+
#Sphinx
41+
docs/_build/

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ language: python
22
python:
33
- 2.6
44
- 2.7
5-
- 3.2
65

76
install: python setup.py install
87

README.rst

Lines changed: 10 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
================
21
catsup
3-
================
2+
----------------
43

5-
.. image:: https://travis-ci.org/whtsky/catsup.png?branch=master
4+
.. image:: https://travis-ci.org/whtsky/catsup.png?branch-master
65
:target: https://travis-ci.org/whtsky/catsup
76

87
A lightweight static blog generator.
8+
Document here: https://catsup.readthedocs.org/en/latest/
99

1010
Install
11-
========
11+
--------
1212

1313
Simple way using pip::
1414

@@ -30,16 +30,16 @@ Or another hard way to install::
3030

3131

3232
Setup your blog
33-
===============
33+
---------------
3434

3535
Change directory to the directory you prefer to place your blog and run ``catsup init`` to initialize it.
3636

3737
Then you can edit ``config.json`` to change your configuration.
3838

3939

4040
Write a post
41-
============
42-
catsup uses Markdown to write posts.
41+
------------
42+
Catsup support markup of Markdown.
4343
Filename should like ``year-month-day-title.md``
4444

4545
(For example: ``2000-01-01-catsup.md``)
@@ -55,45 +55,8 @@ Post Example::
5555
print "hi,I'm coding."
5656
```
5757

58-
Post properties
59-
================
60-
catsup supports some post properties. Write them before ``---``
61-
and start with ``-`` .
62-
Example::
63-
64-
- category: A Category
65-
- date: 2012-12-24
66-
- tags: tag1, tag2
67-
- comment: disabled
68-
- summary: this is a simple post.
69-
70-
The ``category`` property defines the category of the post, but it's not used yet.
71-
72-
The ``date`` property can overwrite the date from the file name.
73-
74-
The ``tags`` property defines the tags of the post.
75-
76-
The ``comment`` property defines whether the post can be commented or not.
77-
78-
Post summary
79-
-------------
80-
81-
You can choose to display summary rather than full content on your homepage
82-
by changing `display_summary` in your configuration file.
83-
84-
If you defined summary as a post property, catsup will use it.
85-
86-
Otherwise, we will try to analytic the summary in order of:
87-
88-
1. Content before`<!--more-->` in your post.
89-
90-
2. Content before first horizontal rule(like `***`)
91-
92-
3. Content before second header(like '##xx')
93-
94-
9558
Install theme
96-
=============
59+
-------------
9760

9861
Run ``catsup themes`` to list available themes. And run ``catsup install path [-g]`` to install a new theme.
9962

@@ -105,17 +68,6 @@ If it's a git repo, catsup will clone and install it automatically.
10568

10669

10770
Build your blog
108-
=================
71+
-----------------
10972
run ``catsup build``
110-
And you can find your static blog in ``~/build/`` .
111-
112-
Develop
113-
==========
114-
Catsup needs your code.Fork and code the repo, then run ::
115-
116-
python setup.py develop
117-
118-
And start hacking catsup!
119-
Note that all the code must be flask8 passed ::
120-
121-
flake8 catsup
73+
And you can find your static blog in ``~/build/`` .

catsup/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
Catsup, a lightweight static blog generator
33
"""
44

5-
__version__ = '0.0.7'
5+
__version__ = '0.0.8'

catsup/build.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
from catsup.options import config, g
1111
from catsup.reader import load_posts
12-
from .utils import Pagination
12+
from .utils import Pagination, call
1313

1414

1515
def load_filters():
@@ -226,9 +226,9 @@ def build():
226226
return
227227

228228
if os.path.exists(config.config.output):
229-
shutil.rmtree(config.config.output)
230-
231-
os.makedirs(config.config.output)
229+
call('rm -rf *', cwd=config.config.output)
230+
else:
231+
os.makedirs(config.config.output)
232232

233233
build_feed()
234234
build_articles()

catsup/cli.py

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,15 @@
88
sys.setdefaultencoding('utf-8')
99

1010
import os
11-
from catsup.options import g, enable_pretty_logging
11+
import logging
12+
13+
from catsup.options import config, g, enable_pretty_logging
1214

1315
enable_pretty_logging()
1416

1517
g.catsup_path = os.path.abspath(os.path.dirname(__file__))
1618
g.public_templates_path = os.path.join(g.catsup_path, 'templates')
19+
g.cwdpath = os.path.abspath('.')
1720

1821
try:
1922
import catsup
@@ -26,6 +29,9 @@
2629
Usage:
2730
catsup init [<path>]
2831
catsup build [-s <file>|--settings=<file>]
32+
catsup deploy [-s <file>|--settings=<file>]
33+
catsup git [-s <file>|--settings=<file>]
34+
catsup rsync [-s <file>|--settings=<file>]
2935
catsup server [-s <file>|--settings=<file>] [-p <port>|--port=<port>]
3036
catsup webhook [-s <file>|--settings=<file>] [-p <port>|--port=<port>]
3137
catsup themes
@@ -44,6 +50,7 @@
4450
import catsup.server
4551
import catsup.themes
4652
import catsup.build
53+
import catsup.deploy
4754

4855

4956
from parguments import Parguments
@@ -79,6 +86,56 @@ def build(args):
7986
catsup.build.build()
8087

8188

89+
@parguments.command
90+
def deploy(args):
91+
"""
92+
Usage:
93+
catsup deploy [-s <file>|--settings=<file>]
94+
95+
Options:
96+
-h --help show this screen.
97+
-s --settings=<file> specify a setting file. [default: config.json]
98+
"""
99+
path = args.get('--settings')
100+
catsup.config.load(path)
101+
if config.deploy.default == 'git':
102+
catsup.deploy.git()
103+
elif config.deploy.default == 'rsync':
104+
catsup.deploy.rsync()
105+
else:
106+
logging.error("Unknown deploy: %s" % config.deploy.default)
107+
108+
109+
@parguments.command
110+
def git(args):
111+
"""
112+
Usage:
113+
catsup git [-s <file>|--settings=<file>]
114+
115+
Options:
116+
-h --help show this screen.
117+
-s --settings=<file> specify a setting file. [default: config.json]
118+
"""
119+
path = args.get('--settings')
120+
catsup.config.load(path)
121+
catsup.deploy.git()
122+
123+
124+
@parguments.command
125+
def rsync(args):
126+
"""
127+
Usage:
128+
catsup rsync [-s <file>|--settings=<file>]
129+
130+
Options:
131+
-h --help show this screen.
132+
-s --settings=<file> specify a setting file. [default: config.json]
133+
"""
134+
path = args.get('--settings')
135+
catsup.config.load(path)
136+
catsup.deploy.rsync()
137+
138+
82139
@parguments.command
83140
def server(args):
84141
"""

catsup/config.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,14 @@ def init(path):
4444

4545

4646
def update_config(base, update):
47-
for key in update:
48-
if isinstance(update[key], dict):
49-
if key in base:
50-
update_config(base[key], update[key])
51-
else:
52-
# convert dict into ObjectDict.
53-
base[key] = ObjectDict(**update[key])
47+
for k in update:
48+
v = update[k]
49+
if isinstance(v, dict):
50+
if k not in base:
51+
base[k] = ObjectDict()
52+
update_config(base[k], v)
5453
else:
55-
base[key] = update[key]
54+
base[k] = v
5655

5756

5857
def parse(path):

catsup/deploy.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import os
2+
import sys
3+
import datetime
4+
import logging
5+
6+
from catsup.options import g, config
7+
from catsup.utils import call, check_git, check_rsync
8+
9+
10+
def git():
11+
if not check_git():
12+
logging.error("Catsup can't find git.Please install git first.")
13+
sys.exit(1)
14+
logging.info("Deploying your blog via git")
15+
16+
cwd = os.path.abspath(config.config.output)
17+
def _call(*args, **kwargs):
18+
return call(*args, cwd=cwd, **kwargs)
19+
20+
if not os.path.exists(os.path.join(cwd, '.git')):
21+
_call('rm -rf *')
22+
# Hasn't setup git.
23+
_call('git init', silence=True)
24+
_call(['git', 'remote', 'add', 'origin', config.deploy.git.repo],
25+
silence=False)
26+
if config.deploy.git.branch != 'master':
27+
_call('git branch -m %s' % config.deploy.git.branch, silence=True)
28+
_call(['git', 'pull', 'origin', config.deploy.git.branch])
29+
30+
logging.info("Rebuild your blog..")
31+
import catsup.build
32+
catsup.build.build()
33+
34+
# GitHub custom domain support
35+
with open(os.path.join(cwd, 'CNAME'), 'w') as f:
36+
domain = config.site.url.split('//')[-1].rstrip('/')
37+
f.write(domain)
38+
39+
_call('git add .', silence=True)
40+
_call(['git', 'commit',
41+
'-m',"Update at %s" % str(datetime.datetime.utcnow())],
42+
silence=True)
43+
_call(['git', 'push', 'origin', config.deploy.git.branch])
44+
45+
46+
47+
def rsync():
48+
if not check_rsync():
49+
logging.error("Catsup can't find rsync.Please install rsync first.")
50+
sys.exit(1)
51+
logging.info("Deploying your blog via rsync")
52+
if config.deploy.rsync.delete:
53+
args = "--delete"
54+
else:
55+
args = ""
56+
cmd = "rsync -avze 'ssh -p {ssh_port}' {args}" \
57+
" {deploy_dir}/ {ssh_user}@{ssh_host}:{document_root}".format(
58+
ssh_port=config.deploy.rsync.ssh_port,
59+
args=args,
60+
deploy_dir=config.config.output,
61+
ssh_user=config.deploy.rsync.ssh_user,
62+
ssh_host=config.deploy.rsync.ssh_host,
63+
document_root=config.deploy.rsync.document_root
64+
)
65+
os.system(cmd)

0 commit comments

Comments
 (0)