siteleaf 1.0.10 → 2.0.0.pre.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +0 -3
- data/README.md +33 -61
- data/bin/siteleaf +191 -165
- data/lib/siteleaf.rb +14 -31
- data/lib/siteleaf/asset.rb +32 -25
- data/lib/siteleaf/client.rb +17 -9
- data/lib/siteleaf/collection.rb +21 -0
- data/lib/siteleaf/content.rb +36 -0
- data/lib/siteleaf/document.rb +15 -0
- data/lib/siteleaf/entity.rb +1 -1
- data/lib/siteleaf/file.rb +9 -0
- data/lib/siteleaf/page.rb +3 -86
- data/lib/siteleaf/post.rb +2 -27
- data/lib/siteleaf/site.rb +24 -88
- data/lib/siteleaf/upload.rb +9 -0
- data/lib/siteleaf/version.rb +1 -1
- data/siteleaf.gemspec +6 -6
- metadata +20 -19
- data/.rbenv-vars +0 -2
- data/lib/patches/time_with_zone_encode_with.rb +0 -12
- data/lib/siteleaf/server.rb +0 -81
- data/lib/siteleaf/theme.rb +0 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5b163f9a10681add3de4aee5e6eb18e16634a50a
|
4
|
+
data.tar.gz: 4683680196a957815215170ed5c0c535fa144b80
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 96d07c4683161d4b174a1b4253f82cd81de741c4d90e4ee6cf861d30aa0376d259f7a8878060eb1d3b4fd74bb3cc0ed0020d9b43f57ca4956d5f0ebc5b3bb633
|
7
|
+
data.tar.gz: 54194023b24413f1703f5a0ff23ee722cef7e2f75cbcd7c5c8468e72406795262b62109a729ebad7be253d7107acd9a3172b3c3cebc617cdc07f57cc26fc6856
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,35 +1,44 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
Siteleaf v1 Gem
|
4
|
-
=================
|
1
|
+
Siteleaf Gem V2
|
2
|
+
===============
|
5
3
|
|
6
4
|
- [Installation](#installation)
|
7
5
|
- [Using the CLI](#using-the-cli)
|
8
6
|
- [Using this gem in your application](#using-this-gem-in-your-application)
|
9
7
|
- [Using the API](#using-the-api)
|
10
|
-
- [Exporting your site](#exporting-your-site)
|
11
8
|
- [Troubleshooting](#troubleshooting)
|
12
9
|
- [Contributing](#contributing)
|
13
10
|
|
14
|
-
|
15
11
|
Installation
|
16
12
|
------------
|
17
13
|
|
18
14
|
The Siteleaf gem is available for installation on [Rubygems](https://rubygems.org/gems/siteleaf). To install run:
|
19
15
|
|
20
|
-
gem install siteleaf
|
16
|
+
gem install siteleaf --pre
|
17
|
+
|
18
|
+
Important: make sure to use `--pre` for V2. If maintaining sites with multiple versions, we recommend using a Gemfile.
|
21
19
|
|
22
20
|
|
23
21
|
Using the CLI
|
24
22
|
-------------
|
25
23
|
|
26
|
-
Important: if using a Gemfile, make sure to prepend all commands with bundle exec (e.g. bundle exec siteleaf auth).
|
24
|
+
Important: if using a Gemfile, make sure to prepend all commands with `bundle exec` (e.g. `bundle exec siteleaf auth`).
|
25
|
+
|
26
|
+
**Authorize your account:**
|
27
27
|
|
28
|
-
|
28
|
+
siteleaf auth
|
29
|
+
|
30
|
+
This will create an authorization file located at `~/.siteleaf.yml`.
|
29
31
|
|
30
|
-
|
32
|
+
Alternatively, you can also use environment variables: `API_KEY=xxx API_SECRET=yyy siteleaf command`
|
31
33
|
|
32
|
-
|
34
|
+
You can also include use a `.siteleaf.yml` file in the root of your project:
|
35
|
+
|
36
|
+
```yaml
|
37
|
+
---
|
38
|
+
api_key: xxx
|
39
|
+
api_secret: yyy
|
40
|
+
site_id: zzz
|
41
|
+
```
|
33
42
|
|
34
43
|
**Set up a new site locally:**
|
35
44
|
|
@@ -41,33 +50,17 @@ This will create a new theme folder called `yoursite.com` in the directory where
|
|
41
50
|
|
42
51
|
siteleaf config yoursite.com
|
43
52
|
|
44
|
-
|
53
|
+
**Upload your files:**
|
45
54
|
|
46
|
-
|
47
|
-
|
48
|
-
**If you don't want to install Pow, local sites can also be manually run:**
|
49
|
-
|
50
|
-
siteleaf server
|
51
|
-
|
52
|
-
In this case, your local site can be accessed at `http://localhost:9292`.
|
53
|
-
|
54
|
-
**Lastly...**
|
55
|
-
|
56
|
-
Your local folder should contain at least one template file (`default.html`), for sample themes and documentation see: https://github.com/siteleaf/siteleaf-themes
|
57
|
-
|
58
|
-
For new sites, you will also need to create at least one page or post on https://manage.siteleaf.com in order to preview.
|
55
|
+
To upload your theme to Siteleaf, run the following command:
|
59
56
|
|
60
|
-
|
57
|
+
siteleaf push
|
58
|
+
|
59
|
+
**Download your files:**
|
61
60
|
|
62
61
|
To download your theme (or the default theme for new sites) from Siteleaf, run the following command:
|
63
62
|
|
64
|
-
siteleaf pull
|
65
|
-
|
66
|
-
**Upload your theme:**
|
67
|
-
|
68
|
-
To upload your theme to Siteleaf, run the following command:
|
69
|
-
|
70
|
-
siteleaf push theme
|
63
|
+
siteleaf pull
|
71
64
|
|
72
65
|
**Publish your site:**
|
73
66
|
|
@@ -75,10 +68,6 @@ To publish your site changes to your hosting provider, run the following command
|
|
75
68
|
|
76
69
|
siteleaf publish
|
77
70
|
|
78
|
-
**Switch Siteleaf users or re-authenticate:**
|
79
|
-
|
80
|
-
siteleaf auth
|
81
|
-
|
82
71
|
**For a full list of commands, run:**
|
83
72
|
|
84
73
|
siteleaf help
|
@@ -89,8 +78,7 @@ Using this gem in your application
|
|
89
78
|
|
90
79
|
To use this gem in your application, add the following to your Gemfile:
|
91
80
|
|
92
|
-
gem 'siteleaf', '
|
93
|
-
|
81
|
+
gem 'siteleaf', :git => 'git://github.com/siteleaf/siteleaf-gem.git', :branch => '2.0.0.pre'
|
94
82
|
|
95
83
|
|
96
84
|
Using the API
|
@@ -148,22 +136,19 @@ page = Siteleaf::Page.find('519719ddcc85910626000001')
|
|
148
136
|
|
149
137
|
# create new post in page
|
150
138
|
post = Siteleaf::Post.create({
|
151
|
-
:parent_id => page.id,
|
152
139
|
:title => 'My Post',
|
153
140
|
:body => 'This is my first post.'
|
154
141
|
})
|
155
142
|
|
156
|
-
# update page, add metadata
|
143
|
+
# update page, add metadata
|
157
144
|
post.title = 'New Title'
|
158
|
-
post.meta =
|
159
|
-
post.taxonomy = [ {"key" => "Tags", "values" => ["One","Two","Three"]} ]
|
145
|
+
post.meta = {'foo' => 'bar'}
|
160
146
|
post.save
|
161
147
|
|
162
|
-
# upload
|
163
|
-
asset = Siteleaf::
|
164
|
-
:post_id => post.id,
|
148
|
+
# upload file
|
149
|
+
asset = Siteleaf::File.create({
|
165
150
|
:file => File.open("~/image.png"),
|
166
|
-
:
|
151
|
+
:path => "image.png"
|
167
152
|
})
|
168
153
|
|
169
154
|
# delete post
|
@@ -173,19 +158,6 @@ post.delete
|
|
173
158
|
Siteleaf::Page.delete('519719ddcc85910626000001')
|
174
159
|
```
|
175
160
|
|
176
|
-
|
177
|
-
Exporting your site
|
178
|
-
---------------------------------
|
179
|
-
|
180
|
-
You can backup or export your Siteleaf content to Jekyll-compatible format by running the following command:
|
181
|
-
|
182
|
-
siteleaf export
|
183
|
-
|
184
|
-
You will be asked to enter your main posts path, this is typically `posts` (default) or `blog` (if your posts are located at `/blog/hello-world` for example). If your site does not have any posts, leave blank to use the default.
|
185
|
-
|
186
|
-
All content including Pages, Posts, Site Metadata, and Assets will be exported to a sub-folder called `export`. Theme files are not included in the export.
|
187
|
-
|
188
|
-
|
189
161
|
Troubleshooting
|
190
162
|
------------
|
191
163
|
|
@@ -193,7 +165,7 @@ Troubleshooting
|
|
193
165
|
|
194
166
|
Try running:
|
195
167
|
|
196
|
-
sudo gem install siteleaf
|
168
|
+
sudo gem install siteleaf
|
197
169
|
|
198
170
|
|
199
171
|
Contributing
|
data/bin/siteleaf
CHANGED
@@ -3,7 +3,8 @@
|
|
3
3
|
require 'siteleaf'
|
4
4
|
require 'fileutils'
|
5
5
|
require 'open-uri'
|
6
|
-
require 'digest/
|
6
|
+
require 'digest/sha1'
|
7
|
+
require 'tempfile'
|
7
8
|
require 'yaml'
|
8
9
|
|
9
10
|
def help
|
@@ -12,20 +13,17 @@ Usage: siteleaf [COMMAND] [OPTIONS]
|
|
12
13
|
|
13
14
|
Commands:
|
14
15
|
auth Login in with your credentials
|
15
|
-
s, server Starts a local server
|
16
16
|
c, config DOMAIN Configure an existing directory
|
17
17
|
n, new DOMAIN Creates new site on siteleaf.net
|
18
|
-
pull
|
19
|
-
push
|
18
|
+
pull Pulls files for configured site from Siteleaf
|
19
|
+
push Pushes all files in dir to configured site
|
20
20
|
publish Publish website to hosting provider
|
21
|
-
export Exports site content to Jekyll-compatible format
|
22
21
|
help Prints this help document
|
23
22
|
version Prints the siteleaf gem version
|
24
23
|
|
25
24
|
Options:
|
26
25
|
-h, --help Prints this help document
|
27
26
|
-v, --version Prints the siteleaf gem version
|
28
|
-
-p, --port PORT Binds local server to PORT (default: 9292)
|
29
27
|
-q, --quiet Suppress publish status
|
30
28
|
|
31
29
|
See https://github.com/siteleaf/siteleaf-gem for additional documentation.
|
@@ -58,90 +56,193 @@ def auth(re_auth = false)
|
|
58
56
|
end
|
59
57
|
|
60
58
|
def config(site)
|
61
|
-
|
62
|
-
|
63
|
-
require 'rubygems'
|
64
|
-
require 'siteleaf'
|
65
|
-
run Siteleaf::Server.new(:site_id => '#{site.id}')" }
|
66
|
-
|
67
|
-
pow_path = File.expand_path('~/.pow')
|
68
|
-
if File.directory?(pow_path)
|
69
|
-
site_no_tld = site.domain.gsub(/\.[a-z]{0,4}$/i,'')
|
70
|
-
site_symlink = "#{pow_path}/#{site_no_tld}"
|
71
|
-
FileUtils.rm(site_symlink) if File.symlink?(site_symlink)
|
72
|
-
FileUtils.symlink(File.expand_path('.'), site_symlink)
|
73
|
-
puts "=> Site configured with Pow, open `http://#{site_no_tld}.dev` to test site locally.\n"
|
74
|
-
else
|
75
|
-
puts "=> Site configured, run `siteleaf server` to test site locally.\n"
|
76
|
-
end
|
59
|
+
Siteleaf.save_settings({site_id: site.id}, '.siteleaf.yml')
|
60
|
+
puts "=> Site configured."
|
77
61
|
end
|
78
62
|
|
79
63
|
def get_site_id
|
80
|
-
|
81
|
-
|
82
|
-
|
64
|
+
# check env vars
|
65
|
+
[:api_key, :api_secret, :api_base, :api_version].each do |key|
|
66
|
+
if value = ENV[key.to_s.upcase]
|
67
|
+
Siteleaf.send "#{key}=", value
|
83
68
|
end
|
84
69
|
end
|
70
|
+
|
71
|
+
ENV['SITE_ID'] || if settings = Siteleaf.load_settings('.siteleaf.yml')
|
72
|
+
settings[:site_id]
|
73
|
+
end
|
85
74
|
end
|
86
75
|
|
87
|
-
def
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
76
|
+
def pull(site_id)
|
77
|
+
# get all the things
|
78
|
+
site = Siteleaf::Site.new(id: site_id)
|
79
|
+
files = site.files
|
80
|
+
uploads = site.uploads
|
81
|
+
pages = site.pages
|
82
|
+
posts = site.posts
|
83
|
+
collections = site.collections
|
84
|
+
documents = []
|
85
|
+
collections.each do |collection|
|
86
|
+
documents += collection.documents
|
87
|
+
end
|
88
|
+
|
89
|
+
assets = files + uploads + pages + posts + documents
|
90
|
+
|
91
|
+
updated_count = 0
|
92
|
+
|
93
|
+
assets.each do |asset|
|
94
|
+
sha = ::File.exist?(asset.filename) && Digest::SHA1.hexdigest(::File.read(asset.filename))
|
95
|
+
if asset.sha == sha
|
96
|
+
# file is up to date
|
97
|
+
else
|
98
|
+
print "Downloading #{asset.filename}..."
|
99
|
+
FileUtils.mkdir_p(::File.dirname(asset.filename))
|
100
|
+
::File.open(asset.filename, 'w:UTF-8') { |f| f.write(asset.to_file) }
|
101
|
+
updated_count += 1
|
102
|
+
print "complete.\n"
|
101
103
|
end
|
102
|
-
puts "=> #{updated_count} asset(s) downloaded.\n"
|
103
104
|
end
|
105
|
+
|
106
|
+
puts "=> #{updated_count} file(s) downloaded.\n"
|
104
107
|
end
|
105
108
|
|
106
|
-
def
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
109
|
+
def push(site_id)
|
110
|
+
# check config
|
111
|
+
config = ::File.exist?('_config.yml') ? YAML::load(::File.read('_config.yml')) : {}
|
112
|
+
markdown_ext = (config['markdown_ext'] || 'markdown,mdw,mdwn,md,text').split(',')
|
113
|
+
|
114
|
+
# get all the things
|
115
|
+
site = Siteleaf::Site.new(id: site_id)
|
116
|
+
files = site.files
|
117
|
+
uploads = site.uploads
|
118
|
+
pages = site.pages
|
119
|
+
posts = site.posts
|
120
|
+
collections = site.collections
|
121
|
+
documents = []
|
122
|
+
collections.each do |collection|
|
123
|
+
documents += collection.documents
|
111
124
|
end
|
112
|
-
|
125
|
+
|
126
|
+
assets = files + uploads + pages + posts + documents
|
127
|
+
|
113
128
|
updated_count = 0
|
114
|
-
ignore_paths = ['config.ru', '.*']
|
115
|
-
ignore_paths += File.read('.siteleafignore').split(/\r?\n/) if File.exists?('.siteleafignore')
|
116
|
-
|
129
|
+
ignore_paths = ['_config.yml', 'config.ru', '.*', '_site/*', 'Gemfile', 'Gemfile.lock']
|
130
|
+
ignore_paths += ::File.read('.siteleafignore').split(/\r?\n/) if ::File.exists?('.siteleafignore')
|
131
|
+
ignore_paths += config['exclude'] if config['exclude'].is_a? Array
|
132
|
+
|
133
|
+
# create collections
|
134
|
+
existing_collections = config['collections'] || {}
|
135
|
+
existing_collections.each do |label, metadata|
|
136
|
+
path = label.gsub(/[^a-z0-9_\-\.]/i, '')
|
137
|
+
unless collections.find {|c| c.path == path }
|
138
|
+
# create any new collections
|
139
|
+
output = metadata.delete('output')
|
140
|
+
permalink = metadata.delete('permalink')
|
141
|
+
collections << Siteleaf::Collection.create(site_id: site.id, title: label, path: path, permalink: permalink, metadata: metadata)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
collection_dirs = collections.map{|c| c.basename }
|
145
|
+
|
117
146
|
# upload files
|
118
147
|
paths = Dir.glob("**/*")
|
119
148
|
paths.each do |path|
|
120
|
-
if
|
149
|
+
if !::File.directory?(path) && !ignore_paths.any?{|i| ::File.fnmatch?(i, path, File::FNM_CASEFOLD) || ::File.fnmatch?(i, ::File.basename(path), File::FNM_CASEFOLD) }
|
121
150
|
asset = assets.find{|a| a.filename == path }
|
122
|
-
|
151
|
+
sha = Digest::SHA1.hexdigest(::File.read(path))
|
152
|
+
if asset.nil? || asset.sha != sha
|
153
|
+
|
123
154
|
print "Uploading #{path}..."
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
155
|
+
|
156
|
+
static = !has_yaml_header?(path)
|
157
|
+
basename = ::File.basename(path)
|
158
|
+
basedir = ::File.dirname(path).split('/').first
|
159
|
+
ext = ::File.extname(path).sub('.', '')
|
160
|
+
|
161
|
+
response = if !static && markdown_ext.include?(ext) && basedir != '_uploads'
|
162
|
+
|
163
|
+
# handle content
|
164
|
+
metadata = {}
|
165
|
+
unless static
|
166
|
+
body, metadata = read_frontmatter(path)
|
167
|
+
end
|
168
|
+
|
169
|
+
clean_path = path.sub("#{basedir}/",'').sub(".#{ext}",'')
|
170
|
+
title = metadata.delete('title') || ::File.basename(clean_path)
|
171
|
+
|
172
|
+
attrs = {site_id: site.id, title: title, path: clean_path, static: static}
|
173
|
+
attrs[:body] = body if body && body != ""
|
174
|
+
attrs[:metadata] = metadata if metadata && !metadata.empty?
|
175
|
+
model = if basedir == '_drafts'
|
176
|
+
attrs[:visibility] = 'draft'
|
177
|
+
Siteleaf::Post
|
178
|
+
elsif basedir == '_posts'
|
179
|
+
attrs[:visibility] = (metadata['published'].delete == false) ? 'hidden' : 'visible'
|
180
|
+
Siteleaf::Post
|
181
|
+
elsif collection = collections.find {|c| c.basename == basedir }
|
182
|
+
attrs[:collection_id] = collection.id
|
183
|
+
Siteleaf::Document
|
184
|
+
else
|
185
|
+
attrs[:path] = path.sub(".#{ext}",'')
|
186
|
+
Siteleaf::Page
|
187
|
+
end
|
188
|
+
|
189
|
+
if asset && asset.is_a?(model)
|
190
|
+
attrs[:id] = asset.id
|
191
|
+
asset = model.new(attrs).save
|
192
|
+
else
|
193
|
+
asset.delete if asset
|
194
|
+
asset = model.create(attrs)
|
195
|
+
end
|
196
|
+
|
128
197
|
else
|
129
|
-
|
198
|
+
|
199
|
+
# handle assets
|
200
|
+
file = path
|
201
|
+
metadata = {}
|
202
|
+
unless static
|
203
|
+
body, metadata = read_frontmatter(path)
|
204
|
+
file = Tempfile.new(basename)
|
205
|
+
::File.open(file, 'w:UTF-8') { |f| f.write(body) }
|
206
|
+
end
|
207
|
+
|
208
|
+
attrs = {site_id: site.id, file: ::File.new(path), path: path, static: static}
|
209
|
+
model = if basedir == '_uploads'
|
210
|
+
attrs[:path] = path.sub("#{basedir}/",'')
|
211
|
+
Siteleaf::Upload
|
212
|
+
else
|
213
|
+
Siteleaf::File
|
214
|
+
end
|
215
|
+
|
216
|
+
asset.delete if asset
|
217
|
+
asset = model.create(attrs)
|
218
|
+
if metadata && !metadata.empty?
|
219
|
+
asset.metadata = metadata
|
220
|
+
asset.save
|
221
|
+
end
|
222
|
+
|
223
|
+
end
|
224
|
+
|
225
|
+
if error = !response || response.error || response.message
|
226
|
+
print (error) ? "error: #{error}\n" : "error.\n"
|
130
227
|
break
|
228
|
+
else
|
229
|
+
updated_count += 1
|
230
|
+
print "complete.\n"
|
131
231
|
end
|
232
|
+
|
132
233
|
end
|
133
234
|
end
|
134
235
|
end
|
135
|
-
|
236
|
+
|
136
237
|
# check for old files
|
137
238
|
missing_assets = []
|
138
|
-
assets.each do |asset|
|
239
|
+
assets.each do |asset|
|
139
240
|
missing_assets << asset if !paths.include?(asset.filename)
|
140
241
|
end
|
141
242
|
if missing_assets.empty?
|
142
|
-
puts "=> #{updated_count}
|
243
|
+
puts "=> #{updated_count} file(s) uploaded.\n"
|
143
244
|
else
|
144
|
-
print "=> #{updated_count}
|
245
|
+
print "=> #{updated_count} file(s) uploaded. Delete the following #{missing_assets.size} unmatched file(s)?\n"
|
145
246
|
missing_assets.each do |asset|
|
146
247
|
puts asset.filename
|
147
248
|
end
|
@@ -152,7 +253,7 @@ def put_theme_assets(site_id)
|
|
152
253
|
asset.delete
|
153
254
|
print "complete.\n"
|
154
255
|
end
|
155
|
-
puts "=> #{missing_assets.size}
|
256
|
+
puts "=> #{missing_assets.size} file(s) deleted.\n"
|
156
257
|
end
|
157
258
|
end
|
158
259
|
end
|
@@ -175,77 +276,18 @@ def publish(site_id, quiet = true)
|
|
175
276
|
end
|
176
277
|
end
|
177
278
|
|
178
|
-
def
|
179
|
-
|
180
|
-
|
181
|
-
site = Siteleaf::Site.find(site_id)
|
182
|
-
site.posts_path = posts_path
|
183
|
-
|
184
|
-
export_uploads(site, dir)
|
185
|
-
export_content(site, dir)
|
186
|
-
export_config(site, dir)
|
279
|
+
def has_yaml_header?(file)
|
280
|
+
!!(File.open(file, 'rb') { |f| f.read(5) } =~ /\A---\r?\n/)
|
187
281
|
end
|
188
282
|
|
189
|
-
def
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
f.puts site.to_file(dir)
|
196
|
-
end
|
197
|
-
|
198
|
-
print "complete.\n"
|
199
|
-
end
|
200
|
-
|
201
|
-
def export_content(site, dir = 'export')
|
202
|
-
pages = site.pages
|
203
|
-
|
204
|
-
pages.each do |page|
|
205
|
-
# export non-blank pages
|
206
|
-
unless page.body.to_s == "" and page.meta.empty?
|
207
|
-
filename = page.filename
|
208
|
-
print "Exporting #{filename}..."
|
209
|
-
|
210
|
-
filename = File.join(dir, filename)
|
211
|
-
FileUtils.mkdir_p File.dirname(filename)
|
212
|
-
open(filename, 'w:UTF-8') do |f|
|
213
|
-
f.puts page.to_file(dir)
|
214
|
-
end
|
215
|
-
|
216
|
-
print "complete.\n"
|
217
|
-
end
|
218
|
-
|
219
|
-
page.posts.each do |post|
|
220
|
-
filename = post.filename(site.posts_path)
|
221
|
-
print "Exporting #{filename}..."
|
222
|
-
|
223
|
-
filename = File.join(dir, filename)
|
224
|
-
FileUtils.mkdir_p File.dirname(filename)
|
225
|
-
open(filename, 'w:UTF-8') do |f|
|
226
|
-
f.puts post.to_file(dir)
|
227
|
-
end
|
228
|
-
|
229
|
-
print "complete.\n"
|
230
|
-
end
|
231
|
-
end
|
232
|
-
end
|
233
|
-
|
234
|
-
def export_uploads(site, dir = 'export')
|
235
|
-
if assets = site.assets
|
236
|
-
assets.each do |asset|
|
237
|
-
filename = File.join(dir, "_uploads", asset.filename)
|
238
|
-
if !File.exist?(filename) or (asset.checksum != Digest::MD5.hexdigest(IO.binread(filename)))
|
239
|
-
print "Exporting #{filename}..."
|
240
|
-
|
241
|
-
file = open(asset.file['url'], 'r:UTF-8') { |f| f.read }
|
242
|
-
FileUtils.mkdir_p(File.dirname(filename))
|
243
|
-
File.open(filename, 'w:UTF-8') { |f| f.write(file) }
|
244
|
-
|
245
|
-
print "complete.\n"
|
246
|
-
end
|
247
|
-
end
|
283
|
+
def read_frontmatter(file)
|
284
|
+
content = ::File.read(file)
|
285
|
+
metadata = {}
|
286
|
+
if content =~ /\A(---\s*\n.*?\n?)^((---|\.\.\.)\s*$\n?)/m
|
287
|
+
content = $POSTMATCH
|
288
|
+
metadata = YAML.load($1)
|
248
289
|
end
|
290
|
+
return content, metadata
|
249
291
|
end
|
250
292
|
|
251
293
|
case ARGV[0]
|
@@ -253,13 +295,6 @@ when '-v', '--version', 'version'
|
|
253
295
|
puts Siteleaf::VERSION
|
254
296
|
when '-h', '--help', 'help'
|
255
297
|
puts help
|
256
|
-
when 's', 'server'
|
257
|
-
if File.exist?('config.ru')
|
258
|
-
port = ARGV[2] if %w[-p --port].include?(ARGV[1]) && ARGV[1]
|
259
|
-
`rackup config.ru -p #{port || '9292'} >&2`
|
260
|
-
else
|
261
|
-
puts "No config found, run `siteleaf config yoursite.com`.\n"
|
262
|
-
end
|
263
298
|
when 'auth'
|
264
299
|
auth true
|
265
300
|
when 'c', 'config', 'setup'
|
@@ -274,60 +309,51 @@ when 'n', 'new'
|
|
274
309
|
if auth != false
|
275
310
|
if (site = Siteleaf::Site.create(:title => ARGV[1], :domain => ARGV[1])) && (!site.error)
|
276
311
|
dir = ARGV.size >= 3 ? ARGV[2] : ARGV[1]
|
277
|
-
|
278
|
-
Dir.chdir
|
312
|
+
Dir.mkdir(dir) unless ::File.directory?(dir)
|
313
|
+
Dir.chdir(dir)
|
279
314
|
config site
|
280
315
|
else
|
281
316
|
puts "Could not create site `#{ARGV[1]}`.\n"
|
282
317
|
end
|
283
318
|
end
|
284
319
|
when 'pull'
|
285
|
-
case ARGV[1]
|
286
|
-
when 'theme'
|
320
|
+
#case ARGV[1]
|
321
|
+
#when 'theme'
|
322
|
+
site_id = get_site_id
|
287
323
|
if auth != false
|
288
|
-
if site_id
|
289
|
-
|
324
|
+
if site_id
|
325
|
+
pull(site_id)
|
290
326
|
else
|
291
327
|
puts "Site not configured, run `siteleaf config yoursite.com`.\n"
|
292
328
|
end
|
293
329
|
end
|
294
|
-
else
|
295
|
-
|
296
|
-
end
|
330
|
+
#else
|
331
|
+
# puts "`#{ARGV[0]}` command not found.\n"
|
332
|
+
#end
|
297
333
|
when 'push'
|
298
|
-
case ARGV[1]
|
299
|
-
when 'theme'
|
334
|
+
#case ARGV[1]
|
335
|
+
#when 'theme'
|
336
|
+
site_id = get_site_id
|
300
337
|
if auth != false
|
301
|
-
if site_id
|
302
|
-
|
338
|
+
if site_id
|
339
|
+
push(site_id)
|
303
340
|
else
|
304
341
|
puts "Site not configured, run `siteleaf config yoursite.com`.\n"
|
305
342
|
end
|
306
343
|
end
|
307
|
-
else
|
308
|
-
|
309
|
-
end
|
344
|
+
#else
|
345
|
+
# puts "`#{ARGV[0]}` command not found.\n"
|
346
|
+
#end
|
310
347
|
when 'publish'
|
348
|
+
site_id = get_site_id
|
311
349
|
if auth != false
|
312
350
|
quiet = %w[-q --quiet].include?(ARGV[1]) && ARGV[1]
|
313
|
-
if site_id
|
351
|
+
if site_id
|
314
352
|
publish(site_id, quiet)
|
315
353
|
else
|
316
354
|
puts "Site not configured, run `siteleaf config yoursite.com`.\n"
|
317
355
|
end
|
318
356
|
end
|
319
|
-
when 'export'
|
320
|
-
if auth != false
|
321
|
-
if site_id = get_site_id
|
322
|
-
print 'Enter your main posts path (default "posts"): '
|
323
|
-
posts_path = $stdin.gets.chomp
|
324
|
-
dir = ARGV.size >= 2 ? ARGV[1] : 'export'
|
325
|
-
FileUtils.mkdir_p dir
|
326
|
-
export(site_id, posts_path, dir)
|
327
|
-
else
|
328
|
-
puts "Site not configured, run `siteleaf config yoursite.com`.\n"
|
329
|
-
end
|
330
|
-
end
|
331
357
|
else
|
332
358
|
puts "`#{ARGV[0]}` command not found.\n"
|
333
359
|
puts help
|