zine 0.15.0 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +143 -125
- data/LICENSE +661 -21
- data/bin/console +1 -0
- data/bin/zine +2 -0
- data/lib/zine/cli.rb +26 -15
- data/lib/zine/data_page.rb +3 -0
- data/lib/zine/page.rb +16 -8
- data/lib/zine/post.rb +5 -3
- data/lib/zine/posts_and_headlines.rb +53 -12
- data/lib/zine/query.rb +2 -0
- data/lib/zine/server.rb +9 -8
- data/lib/zine/skeleton/source/templates/atom.erb +22 -0
- data/lib/zine/skeleton/source/templates/footer_partial.erb +1 -1
- data/lib/zine/skeleton/source/templates/header_partial.erb +2 -1
- data/lib/zine/skeleton/source/templates/rss.erb +19 -20
- data/lib/zine/skeleton/zine.yaml +1 -0
- data/lib/zine/style.rb +3 -1
- data/lib/zine/tag.rb +10 -12
- data/lib/zine/templates.rb +3 -3
- data/lib/zine/upload.rb +8 -3
- data/lib/zine/uploader_aws.rb +6 -5
- data/lib/zine/uploader_github.rb +3 -0
- data/lib/zine/uploader_sftp.rb +6 -2
- data/lib/zine/version.rb +1 -1
- data/lib/zine/watcher.rb +4 -2
- data/lib/zine.rb +1 -1
- metadata +65 -63
data/bin/console
CHANGED
data/bin/zine
CHANGED
data/lib/zine/cli.rb
CHANGED
@@ -12,15 +12,26 @@ module Zine
|
|
12
12
|
# CLI for zine
|
13
13
|
class CLI < Thor
|
14
14
|
include Thor::Actions
|
15
|
-
attr_accessor :
|
15
|
+
attr_accessor :site # only used in testing
|
16
16
|
|
17
17
|
no_commands do
|
18
|
-
def
|
19
|
-
|
18
|
+
def self.exit_on_failure?
|
19
|
+
true
|
20
|
+
end
|
21
|
+
|
22
|
+
def site
|
23
|
+
@site ||= Zine::Site.new
|
20
24
|
end
|
21
25
|
|
22
26
|
def options
|
23
|
-
|
27
|
+
site
|
28
|
+
|
29
|
+
# for v0.16.0 & a few more only
|
30
|
+
unless @site.options['templates'] && @site.options['templates']['atom']
|
31
|
+
puts "v0.16.0 changes how rss & atom works, see CHANGELOG.md if you haven't already\n\n"
|
32
|
+
end
|
33
|
+
|
34
|
+
@site.options
|
24
35
|
end
|
25
36
|
end
|
26
37
|
|
@@ -31,28 +42,28 @@ module Zine
|
|
31
42
|
# printf "%25s\#%s\t\t\t%s:%-2d\n", classname, id, file, line
|
32
43
|
# end
|
33
44
|
# }
|
34
|
-
|
35
|
-
@
|
45
|
+
site
|
46
|
+
@site.build_site
|
36
47
|
puts Rainbow('Site built').green
|
37
48
|
end
|
38
49
|
|
39
50
|
desc 'force', 'Build the site, forcing writes & uploads'
|
40
51
|
def force
|
41
|
-
|
42
|
-
@
|
52
|
+
site
|
53
|
+
@site.build_site_forcing_writes
|
43
54
|
puts Rainbow('Site built').green
|
44
55
|
end
|
45
56
|
|
46
57
|
desc 'notice POST', 'Build the site, then force the one POST'
|
47
58
|
def notice(file)
|
48
|
-
|
49
|
-
@
|
59
|
+
site
|
60
|
+
@site.notice(file)
|
50
61
|
puts Rainbow('Site built').green
|
51
62
|
end
|
52
63
|
|
53
64
|
desc 'nuke', 'Delete the build folder'
|
54
65
|
def nuke
|
55
|
-
|
66
|
+
site
|
56
67
|
FileUtils.remove_dir options['directories']['build'],
|
57
68
|
force: true
|
58
69
|
puts Rainbow('Site nuked. It\'s the only way to be sure.').green
|
@@ -60,7 +71,7 @@ module Zine
|
|
60
71
|
|
61
72
|
desc 'post TITLE', 'Create the file for a new blog post, titled TITLE'
|
62
73
|
def post(name)
|
63
|
-
|
74
|
+
site
|
64
75
|
option_dir = options['directories']
|
65
76
|
Zine::CLI.source_root option_dir['templates']
|
66
77
|
@date = DateTime.now
|
@@ -71,8 +82,8 @@ module Zine
|
|
71
82
|
File.join(Dir.pwd, option_dir['posts'], file)
|
72
83
|
end
|
73
84
|
|
74
|
-
desc '
|
75
|
-
def
|
85
|
+
desc 'skeleton', 'Create the skeleton of a new site (overwriting files)'
|
86
|
+
def skeleton
|
76
87
|
# @skeleton_dir ?
|
77
88
|
skeleton_dir = File.join File.dirname(__FILE__), 'skeleton', '/.'
|
78
89
|
FileUtils.cp_r skeleton_dir, Dir.pwd
|
@@ -81,7 +92,7 @@ module Zine
|
|
81
92
|
|
82
93
|
desc 'style', 'Build the site\'s stylesheet'
|
83
94
|
def style
|
84
|
-
|
95
|
+
site
|
85
96
|
style = Zine::Style.new(options['directories'])
|
86
97
|
style.process(File)
|
87
98
|
puts Rainbow('Stylesheet rendered').green
|
data/lib/zine/data_page.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'zine/page'
|
2
4
|
|
3
5
|
module Zine
|
@@ -5,6 +7,7 @@ module Zine
|
|
5
7
|
# links to other pages, eg an index page like the home page
|
6
8
|
class DataPage < Zine::Page
|
7
9
|
def initialize(data, templates, site_options, suffix = '.html')
|
10
|
+
# super(front_matter, site_opt)
|
8
11
|
init_templates(templates)
|
9
12
|
@formatted_data = FormattedData.new({}, site_options)
|
10
13
|
@formatted_data.page[:title] = data[:title]
|
data/lib/zine/page.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'erb'
|
2
4
|
require 'date'
|
3
5
|
require 'htmlcompressor'
|
@@ -16,20 +18,18 @@ module Zine
|
|
16
18
|
attr_accessor :source_file # used in zine notice --
|
17
19
|
# PostsAndHeadlines.one_new_post
|
18
20
|
attr_reader :dest_path, :formatted_data, :template_bundle
|
21
|
+
|
19
22
|
# the meta data, passed formatted to the template
|
20
23
|
class FormattedData
|
21
24
|
include ERB::Util
|
22
25
|
|
23
|
-
attr_accessor :data
|
24
|
-
attr_accessor :footer_partial
|
25
|
-
attr_accessor :header_partial
|
26
|
-
attr_accessor :html
|
26
|
+
attr_accessor :data, :footer_partial, :header_partial, :html, :uri
|
27
27
|
attr_reader :page
|
28
|
-
attr_accessor :uri
|
29
28
|
|
30
29
|
def initialize(front_matter, site_opt)
|
31
30
|
site = site_opt['options']
|
32
31
|
@page = { date_rfc3339: front_matter['date'],
|
32
|
+
date_rfc822: parse_822_date(front_matter['date']),
|
33
33
|
date_us: parse_date(front_matter['date']),
|
34
34
|
github_name: site['github_name'],
|
35
35
|
links_array: site_opt['links'],
|
@@ -56,9 +56,16 @@ module Zine
|
|
56
56
|
''
|
57
57
|
end
|
58
58
|
|
59
|
+
def parse_822_date(front_matter_date)
|
60
|
+
DateTime.rfc3339(front_matter_date).rfc2822
|
61
|
+
rescue ArgumentError
|
62
|
+
''
|
63
|
+
end
|
64
|
+
|
59
65
|
def slugify_tags(tags)
|
60
|
-
return unless tags
|
61
|
-
|
66
|
+
return unless tags
|
67
|
+
|
68
|
+
tags&.map { |tag| { name: tag, tag_slug: Page.slug(tag) } }
|
62
69
|
end
|
63
70
|
end
|
64
71
|
|
@@ -68,7 +75,7 @@ module Zine
|
|
68
75
|
|
69
76
|
def initialize(md_file_name, dest, templates, site_options)
|
70
77
|
@source_file = md_file_name
|
71
|
-
file_parts = File.
|
78
|
+
file_parts = File.read(md_file_name).split('---', 3)
|
72
79
|
@formatted_data = FormattedData.new(parse_yaml(file_parts[1],
|
73
80
|
md_file_name),
|
74
81
|
site_options)
|
@@ -106,6 +113,7 @@ module Zine
|
|
106
113
|
input: 'GFM',
|
107
114
|
auto_ids: false,
|
108
115
|
smart_quotes: %w[apos apos quot quot],
|
116
|
+
typographic_symbols: { hellip: '…', mdash: '—', ndash: '–' }
|
109
117
|
).to_html
|
110
118
|
@raw_text = nil
|
111
119
|
end
|
data/lib/zine/post.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'uri'
|
2
4
|
|
3
5
|
module Zine
|
@@ -5,7 +7,7 @@ module Zine
|
|
5
7
|
class Post < Page
|
6
8
|
def initialize(md_file_name, templates, site_options)
|
7
9
|
@source_file = md_file_name
|
8
|
-
file_parts = File.
|
10
|
+
file_parts = File.read(md_file_name).split('---', 3)
|
9
11
|
@formatted_data = FormattedData.new(parse_yaml(file_parts[1],
|
10
12
|
md_file_name),
|
11
13
|
site_options)
|
@@ -35,7 +37,7 @@ module Zine
|
|
35
37
|
@dest_dir = File.join(build_dir,
|
36
38
|
date.strftime('%Y'),
|
37
39
|
date.strftime('%-m'))
|
38
|
-
slg = Zine::Page.slug(page_data[:title])
|
40
|
+
slg = "#{Zine::Page.slug(page_data[:title])}.html"
|
39
41
|
@dest_path = File.join(@dest_dir, slg)
|
40
42
|
end
|
41
43
|
|
@@ -43,7 +45,7 @@ module Zine
|
|
43
45
|
page_data = @formatted_data.page
|
44
46
|
file_path = rel_path_from_build_dir(@dest_path).to_s
|
45
47
|
# URI.join will expect a root directory to start...
|
46
|
-
@formatted_data.uri = page_data[:site_URL]
|
48
|
+
@formatted_data.uri = "#{page_data[:site_URL]}/#{file_path}"
|
47
49
|
TagData.new(page_data[:tags],
|
48
50
|
file_path,
|
49
51
|
page_data[:title],
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'zine/data_page'
|
2
4
|
require 'zine/post'
|
3
5
|
require 'zine/tag'
|
@@ -32,15 +34,54 @@ module Zine
|
|
32
34
|
dir = @options['directories']['build']
|
33
35
|
options = @options['options']
|
34
36
|
templates = @options['templates']
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
37
|
+
|
38
|
+
headlines = []
|
39
|
+
if templates['home']
|
40
|
+
headlines <<
|
41
|
+
{
|
42
|
+
build_dir: dir,
|
43
|
+
name: 'index',
|
44
|
+
number: options['num_items_on_home'],
|
45
|
+
suffix: '.html',
|
46
|
+
template_name: templates['home'],
|
47
|
+
title: 'Home'
|
48
|
+
}
|
49
|
+
end
|
50
|
+
if templates['articles']
|
51
|
+
headlines <<
|
52
|
+
{
|
53
|
+
build_dir: dir,
|
54
|
+
name: templates['articles'],
|
55
|
+
number: @post_array.size,
|
56
|
+
suffix: '.html',
|
57
|
+
template_name: templates['articles'],
|
58
|
+
title: 'Articles'
|
59
|
+
}
|
60
|
+
end
|
61
|
+
if templates['rss']
|
62
|
+
headlines <<
|
63
|
+
{
|
64
|
+
build_dir: dir,
|
65
|
+
name: 'rss',
|
66
|
+
number: options['number_items_in_RSS'],
|
67
|
+
suffix: '.xml',
|
68
|
+
template_name: templates['rss'],
|
69
|
+
title: ''
|
70
|
+
}
|
71
|
+
end
|
72
|
+
if templates['atom']
|
73
|
+
headlines <<
|
74
|
+
{
|
75
|
+
build_dir: dir,
|
76
|
+
name: 'atom',
|
77
|
+
number: options['number_items_in_RSS'],
|
78
|
+
suffix: '.xml',
|
79
|
+
template_name: templates['atom'],
|
80
|
+
title: ''
|
81
|
+
}
|
82
|
+
end
|
83
|
+
|
84
|
+
headlines
|
44
85
|
end
|
45
86
|
|
46
87
|
def once_only(source_file)
|
@@ -73,7 +114,7 @@ module Zine
|
|
73
114
|
Pathname(File.absolute_path(directories['source']))
|
74
115
|
)
|
75
116
|
relative_path = File.dirname(relative)
|
76
|
-
file = File.basename(relative, '.md')
|
117
|
+
file = "#{File.basename(relative, '.md')}.html"
|
77
118
|
File.delete(File.join(directories['build'], relative_path, file))
|
78
119
|
else
|
79
120
|
File.delete(page[:post].dest_path)
|
@@ -114,7 +155,7 @@ module Zine
|
|
114
155
|
def preview_straight_delete(file)
|
115
156
|
FileUtils.rm(File.join(
|
116
157
|
preview_relative_equivalent(file), File.basename(file)
|
117
|
-
|
158
|
+
))
|
118
159
|
end
|
119
160
|
|
120
161
|
# rebuild a page that's not a post - doesn't create the file structure for a
|
@@ -192,7 +233,7 @@ module Zine
|
|
192
233
|
@post_array.first(page[:number]).each do |post|
|
193
234
|
post_data = post.formatted_data
|
194
235
|
data[:post_array] << { page: post_data.page, html: post_data.html,
|
195
|
-
uri:
|
236
|
+
uri: post_data.uri }
|
196
237
|
end
|
197
238
|
data_page = DataPage.new(data,
|
198
239
|
@site.make_template_bundle(data[:template_name]),
|
data/lib/zine/query.rb
CHANGED
data/lib/zine/server.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'zine/query'
|
2
4
|
require 'rainbow'
|
3
5
|
require 'rack'
|
@@ -23,7 +25,6 @@ module Zine
|
|
23
25
|
motd unless upload_options['test']
|
24
26
|
@thin.start
|
25
27
|
possible_upload rel_path_build, upload_options
|
26
|
-
@thin
|
27
28
|
end
|
28
29
|
|
29
30
|
# Stop the server - only used in test
|
@@ -48,23 +49,23 @@ module Zine
|
|
48
49
|
|
49
50
|
def header_rules
|
50
51
|
[[:all,
|
51
|
-
{ 'ETag'
|
52
|
-
'Last-Modified' => (Time.now + 100**4).to_s,
|
52
|
+
{ 'ETag' => nil,
|
53
|
+
'Last-Modified' => (Time.now + (100**4)).to_s,
|
53
54
|
'Cache-Control' =>
|
54
55
|
'no-store, no-cache, must-revalidate, post-check=0, pre-check=0',
|
55
|
-
'Pragma'
|
56
|
-
'Expires'
|
56
|
+
'Pragma' => 'no-cache',
|
57
|
+
'Expires' => (Time.now - (100**4)).to_s }]]
|
57
58
|
end
|
58
59
|
|
59
60
|
def motd
|
60
|
-
puts "
|
61
|
-
|
62
|
-
"\nCommand double click the URL to open, Control C to quit\n"
|
61
|
+
puts "Preview running at #{Rainbow('http://127.0.0.1:8080/').blue.underline}
|
62
|
+
Control C to quit\n"
|
63
63
|
end
|
64
64
|
|
65
65
|
def possible_upload(rel_path_build, upload_options)
|
66
66
|
return if upload_options['method'] == 'none' ||
|
67
67
|
(@delete_array.empty? && @upload_array.empty?)
|
68
|
+
|
68
69
|
uploader = Zine::Upload.new rel_path_build, upload_options,
|
69
70
|
@delete_array, @upload_array
|
70
71
|
uploader.upload_decision Query
|
@@ -0,0 +1,22 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<feed xmlns="http://www.w3.org/2005/Atom"
|
3
|
+
xmlns:dc="http://purl.org/dc/elements/1.1/">
|
4
|
+
<author>
|
5
|
+
<name><%= page[:site_author] %></name>
|
6
|
+
</author>
|
7
|
+
<id><%= page[:site_URL] %>/atom.xml</id>
|
8
|
+
<title><%= page[:site_name] %></title>
|
9
|
+
<dc:date><%= data[0][:page][:date_rfc3339] %></dc:date>
|
10
|
+
<updated><%= data[0][:page][:date_rfc3339] %></updated>
|
11
|
+
<link href="<%= page[:site_URL] %>/atom.xml" rel="self" type="application/atom+xml"/>
|
12
|
+
<% for @post in data %>
|
13
|
+
<entry>
|
14
|
+
<content type="html"><![CDATA[<%= @post[:html] %>]]></content>
|
15
|
+
<id><%= @post[:uri] %></id>
|
16
|
+
<link href="<%= @post[:uri] %>"/>
|
17
|
+
<title><%= @post[:page][:title] %></title>
|
18
|
+
<updated><%= @post[:page][:date_rfc3339] %></updated>
|
19
|
+
<dc:date><%= @post[:page][:date_rfc3339] %></dc:date>
|
20
|
+
</entry>
|
21
|
+
<% end %>
|
22
|
+
</feed>
|
@@ -18,7 +18,7 @@
|
|
18
18
|
<h3>The fine print</h3>
|
19
19
|
<ul>
|
20
20
|
<li>Built with <a href="https://mikekreuzer.com/projects/zine/">Zine</a></li>
|
21
|
-
<li>©
|
21
|
+
<li>© 2023<span> <%= page[:site_author] %></span></li>
|
22
22
|
</ul>
|
23
23
|
</div>
|
24
24
|
</footer>
|
@@ -5,7 +5,8 @@
|
|
5
5
|
<meta name="viewport" content="width=device-width,user-scalable=yes">
|
6
6
|
<meta name="description" content="<%= page[:site_description] %>">
|
7
7
|
<title><%= page[:site_name] %> | <%= page[:title] %></title>
|
8
|
-
<link rel="home" href="<%= page[:site_URL] %>/
|
8
|
+
<link rel="home alternate" href="<%= page[:site_URL] %>/atom.xml" type="application/atom+xml" title="<%= page[:site_name] %>">
|
9
|
+
<link rel="home alternate" href="<%= page[:site_URL] %>/rss.xml" type="application/rss+xml" title="<%= page[:site_name] %>">
|
9
10
|
<link rel="stylesheet" href="/screen.css">
|
10
11
|
<link rel="apple-touch-icon" href="/apple-touch-icon.png">
|
11
12
|
<!--<link rel="canonical" href="<%= page[:uri] %>" />-->
|
@@ -1,21 +1,20 @@
|
|
1
|
-
<?xml version="1.0" encoding="
|
2
|
-
<
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
<
|
9
|
-
<
|
10
|
-
|
11
|
-
|
12
|
-
<entry>
|
13
|
-
<content type="html"><![CDATA[<%= @post[:html] %>]]></content>
|
14
|
-
<id><%= @post[:uri] %></id>
|
15
|
-
<link href="<%= @post[:uri] %>"/>
|
1
|
+
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
|
2
|
+
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
|
3
|
+
<channel>
|
4
|
+
<title><%= page[:site_name] %></title>
|
5
|
+
<link><%= page[:site_URL] %>/rss.xml</link>
|
6
|
+
<description><%= page[:site_description] %></description>
|
7
|
+
<pubDate><%= data[0][:page][:date_rfc822] %></pubDate>
|
8
|
+
<lastBuildDate><%= data[0][:page][:date_rfc822] %></lastBuildDate>
|
9
|
+
<atom:link href="<%= page[:site_URL] %>/rss.xml" rel="self" type="application/rss+xml" />
|
10
|
+
<% for @post in data %>
|
11
|
+
<item>
|
16
12
|
<title><%= @post[:page][:title] %></title>
|
17
|
-
<
|
18
|
-
<
|
19
|
-
|
20
|
-
|
21
|
-
</
|
13
|
+
<link><%= @post[:uri] %></link>
|
14
|
+
<description><![CDATA[<%= @post[:html] %>]]></description>
|
15
|
+
<pubDate><%= @post[:page][:date_rfc822] %></pubDate>
|
16
|
+
<guid><%= @post[:uri] %></guid>
|
17
|
+
</item>
|
18
|
+
<% end %>
|
19
|
+
</channel>
|
20
|
+
</rss>
|
data/lib/zine/skeleton/zine.yaml
CHANGED
data/lib/zine/style.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'sassc'
|
2
4
|
|
3
5
|
module Zine
|
@@ -11,7 +13,7 @@ module Zine
|
|
11
13
|
|
12
14
|
# Write the CSS file
|
13
15
|
def process(string_or_file_writer)
|
14
|
-
sass = File.
|
16
|
+
sass = File.read(@style_file)
|
15
17
|
css = SassC::Engine.new(sass, style: :compressed).render
|
16
18
|
string_or_file_writer.write @css_file, css
|
17
19
|
end
|
data/lib/zine/tag.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'zine/data_page'
|
2
4
|
|
3
5
|
module Zine
|
@@ -15,7 +17,7 @@ module Zine
|
|
15
17
|
def write_tags
|
16
18
|
@posts_by_tag.each do |tag_name, struct_array|
|
17
19
|
sorted_array = sort_tags_by_date struct_array
|
18
|
-
data = { name: tag_name, title:
|
20
|
+
data = { name: tag_name, title: "Tags: #{tag_name}",
|
19
21
|
post_array: sorted_array, build_dir: @tag_dir }
|
20
22
|
tag_page = Zine::DataPage.new(data, @templates[:tag], @options)
|
21
23
|
tag_page.write
|
@@ -25,21 +27,17 @@ module Zine
|
|
25
27
|
|
26
28
|
private
|
27
29
|
|
28
|
-
# Take an array of posts each with
|
29
|
-
# each with
|
30
|
-
def sort_tags(
|
31
|
-
|
32
|
-
|
30
|
+
# Take an array of posts, each with an array of tags it has, &
|
31
|
+
# make a hash of posts each with an array of posts the tag's in
|
32
|
+
def sort_tags(posts)
|
33
|
+
tags = {}
|
34
|
+
posts.each do |post|
|
33
35
|
post['tagsArray'].each do |tag|
|
34
36
|
name = tag[:name]
|
35
|
-
|
36
|
-
posts_by_tag[name] << post
|
37
|
-
else
|
38
|
-
posts_by_tag[name] = [post]
|
39
|
-
end
|
37
|
+
tags.key?(name) ? tags[name] << post : tags[name] = [post]
|
40
38
|
end
|
41
39
|
end
|
42
|
-
|
40
|
+
tags
|
43
41
|
end
|
44
42
|
|
45
43
|
def sort_tags_by_date(tag_array)
|
data/lib/zine/templates.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Zine
|
2
4
|
# Trio of templates used to create a page
|
3
5
|
class TemplateFiles
|
4
|
-
attr_reader :body
|
5
|
-
attr_reader :footer
|
6
|
-
attr_reader :header
|
6
|
+
attr_reader :body, :footer, :header
|
7
7
|
|
8
8
|
def initialize(body, header, footer)
|
9
9
|
@body = body
|
data/lib/zine/upload.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'rainbow'
|
2
4
|
require 'set'
|
3
5
|
require 'zine'
|
@@ -23,9 +25,11 @@ module Zine
|
|
23
25
|
|
24
26
|
def upload_decision(query_class)
|
25
27
|
return if @no_upload
|
28
|
+
|
26
29
|
cli = query_class.new
|
27
30
|
answer = cli.call 'Upload files? (Y/n)'
|
28
31
|
return if answer != 'Y'
|
32
|
+
|
29
33
|
puts Rainbow('Connecting...').green
|
30
34
|
upload
|
31
35
|
end
|
@@ -74,11 +78,12 @@ module Zine
|
|
74
78
|
end
|
75
79
|
|
76
80
|
def upload
|
77
|
-
|
81
|
+
case @options['method']
|
82
|
+
when 'aws'
|
78
83
|
aws_upload
|
79
|
-
|
84
|
+
when 'sftp'
|
80
85
|
sftp_upload
|
81
|
-
|
86
|
+
when 'github'
|
82
87
|
github_upload
|
83
88
|
else
|
84
89
|
puts Rainbow('Unknown upload option in zine.yaml').red
|
data/lib/zine/uploader_aws.rb
CHANGED
@@ -31,8 +31,8 @@ module Zine
|
|
31
31
|
delete
|
32
32
|
deploy
|
33
33
|
invalidate
|
34
|
-
rescue Aws::S3::Errors::ServiceError =>
|
35
|
-
puts Rainbow("S3 error: #{
|
34
|
+
rescue Aws::S3::Errors::ServiceError => e
|
35
|
+
puts Rainbow("S3 error: #{e}").red
|
36
36
|
end
|
37
37
|
|
38
38
|
private
|
@@ -61,10 +61,11 @@ module Zine
|
|
61
61
|
def deploy_one_file(local_path, remote_path)
|
62
62
|
File.open(local_path, 'rb') do |file|
|
63
63
|
content_type = Rack::Mime.mime_type(File.extname(local_path))
|
64
|
-
@s3.put_object(
|
65
|
-
|
64
|
+
@s3.put_object(body: file,
|
65
|
+
cache_control: 'max-age=86400',
|
66
66
|
content_type: content_type,
|
67
|
-
|
67
|
+
bucket: @bucket_name,
|
68
|
+
key: remote_path)
|
68
69
|
puts "Add: #{remote_path}" if @verbose
|
69
70
|
end
|
70
71
|
end
|
data/lib/zine/uploader_github.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'octokit'
|
2
4
|
require 'rainbow'
|
3
5
|
require 'yaml'
|
@@ -29,6 +31,7 @@ module Zine
|
|
29
31
|
# then .each... upload & delete - uses @build_dir to create relative paths
|
30
32
|
def upload
|
31
33
|
return if @no_upload
|
34
|
+
|
32
35
|
@delete_file_array.each do |file_pathname|
|
33
36
|
delete_file file_pathname
|
34
37
|
end
|
data/lib/zine/uploader_sftp.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'net/ssh'
|
2
4
|
require 'net/sftp'
|
3
5
|
require 'rainbow'
|
@@ -12,6 +14,7 @@ module Zine
|
|
12
14
|
def initialize(build_dir, options, credentials, delete_file_array,
|
13
15
|
upload_file_array)
|
14
16
|
return unless options['method'] == 'sftp'
|
17
|
+
|
15
18
|
@build_dir = build_dir
|
16
19
|
@host = options['host']
|
17
20
|
@path = options['path_or_repo']
|
@@ -67,6 +70,7 @@ module Zine
|
|
67
70
|
node_array.each do |level|
|
68
71
|
level.each do |node|
|
69
72
|
next if node.nil?
|
73
|
+
|
70
74
|
path_string = node.path_string
|
71
75
|
mkdir_p(sftp, path_string)
|
72
76
|
puts "mkdir_p #{path_string}" if @verbose
|
@@ -96,8 +100,8 @@ module Zine
|
|
96
100
|
|
97
101
|
def mkdir_p(sftp, path)
|
98
102
|
sftp.mkdir!(File.join(@path, path), permissions: 0o755) # drwxr-xr-x
|
99
|
-
rescue Net::SFTP::StatusException =>
|
100
|
-
raise if
|
103
|
+
rescue Net::SFTP::StatusException => e
|
104
|
+
raise if e.code != 4 && e.code != 11 # folder already exists
|
101
105
|
end
|
102
106
|
|
103
107
|
# for each level, if a node has the same name & same path it's a duplicate
|
data/lib/zine/version.rb
CHANGED