fronde 0.4.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ext/nil_time.rb +3 -6
- data/lib/ext/time.rb +10 -17
- data/lib/ext/time_no_time.rb +27 -0
- data/lib/fronde/cli/commands.rb +18 -14
- data/lib/fronde/cli/data/fish_completion +20 -0
- data/lib/fronde/cli/data/gitignore +0 -1
- data/lib/fronde/cli/helpers.rb +0 -2
- data/lib/fronde/cli/opt_parse.rb +15 -18
- data/lib/fronde/cli/throbber.rb +35 -18
- data/lib/fronde/cli.rb +4 -3
- data/lib/fronde/config/data/org-config.el +3 -2
- data/lib/fronde/config/data/ox-fronde.el +91 -46
- data/lib/fronde/config/data/themes/umaneti/css/htmlize.css +364 -0
- data/lib/fronde/config/data/themes/umaneti/css/style.css +250 -0
- data/lib/fronde/config/data/themes/umaneti/img/bottom.png +0 -0
- data/lib/fronde/config/data/themes/umaneti/img/content.png +0 -0
- data/lib/fronde/config/data/themes/umaneti/img/tic.png +0 -0
- data/lib/fronde/config/data/themes/umaneti/img/top.png +0 -0
- data/lib/fronde/config/helpers.rb +1 -19
- data/lib/fronde/config/lisp.rb +14 -7
- data/lib/fronde/config.rb +47 -31
- data/lib/fronde/emacs.rb +23 -9
- data/lib/fronde/index/atom_generator.rb +1 -1
- data/lib/fronde/index/data/all_tags.org +6 -1
- data/lib/fronde/index/data/template.org +8 -4
- data/lib/fronde/index/org_generator.rb +10 -6
- data/lib/fronde/index.rb +19 -17
- data/lib/fronde/org/file.rb +71 -39
- data/lib/fronde/org/file_extracter.rb +23 -12
- data/lib/fronde/org.rb +14 -12
- data/lib/fronde/slug.rb +39 -12
- data/lib/fronde/source/gemini.rb +4 -9
- data/lib/fronde/source/html.rb +9 -9
- data/lib/fronde/source.rb +17 -12
- data/lib/fronde/sync/neocities.rb +220 -0
- data/lib/fronde/sync/rsync.rb +46 -0
- data/lib/fronde/sync.rb +32 -0
- data/lib/fronde/templater.rb +35 -51
- data/lib/fronde/version.rb +1 -1
- data/lib/tasks/cli.rake +45 -13
- data/lib/tasks/org.rake +30 -35
- data/lib/tasks/site.rake +63 -41
- data/lib/tasks/sync.rake +19 -50
- data/lib/tasks/tags.rake +2 -2
- data/locales/en.yml +143 -81
- data/locales/fr.yml +153 -89
- metadata +56 -17
- data/lib/ext/r18n.rb +0 -17
data/lib/fronde/templater.rb
CHANGED
@@ -5,8 +5,6 @@ require 'digest/md5'
|
|
5
5
|
require_relative 'org/file'
|
6
6
|
|
7
7
|
module Fronde
|
8
|
-
class NoHeadError < ::StandardError; end
|
9
|
-
|
10
8
|
# Insert custom part inside generated HTML files.
|
11
9
|
class Templater
|
12
10
|
def initialize(source, dom, config = {})
|
@@ -19,74 +17,55 @@ module Fronde
|
|
19
17
|
|
20
18
|
def apply
|
21
19
|
# Flag the file for this template
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
head.prepend_child("<!--#{@config['check_line']}-->")
|
20
|
+
html = @dom.xpath('//html').first
|
21
|
+
html.add_child("<!--#{@config['check_line']}-->\n")
|
26
22
|
content = @org_file.format extract_content
|
27
23
|
# Remove source element if necessary to avoid doubling it during
|
28
24
|
# the insert action
|
29
25
|
@config['source'].unlink if @config.has_key? 'source'
|
30
26
|
# Insert new content
|
31
|
-
@dom.css(@config['selector']).
|
27
|
+
@dom.css(@config['selector']).map do |element|
|
32
28
|
insert_new_node_at element, content
|
33
29
|
end
|
34
30
|
end
|
35
31
|
|
36
|
-
def
|
37
|
-
@dom.xpath('//
|
32
|
+
def applied?
|
33
|
+
@dom.xpath('//html').children.any? do |child|
|
38
34
|
next false unless child.comment?
|
39
35
|
|
40
36
|
child.text == @config['check_line']
|
41
37
|
end
|
42
38
|
end
|
43
39
|
|
44
|
-
def valid?
|
40
|
+
def valid?
|
45
41
|
return false unless @config.has_key?('selector')
|
46
42
|
|
47
43
|
unless @config.has_key?('content') || @config.has_key?('source')
|
48
44
|
return false
|
49
45
|
end
|
50
46
|
|
51
|
-
check_path
|
47
|
+
check_path
|
52
48
|
end
|
53
49
|
|
54
50
|
class << self
|
55
51
|
def customize_output(file_name)
|
56
|
-
source = Fronde::Org::File.new
|
52
|
+
source = Fronde::Org::File.new file_name
|
57
53
|
# Return if no org file found for this published file
|
58
|
-
return
|
54
|
+
return unless source.pub_file
|
59
55
|
|
60
|
-
|
61
|
-
updated = apply_templates(source, dom, file_name)
|
62
|
-
write_dom(file_name, dom) if updated
|
56
|
+
apply_templates source
|
63
57
|
end
|
64
58
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
Fronde::CONFIG.get('templates', []).map do |config|
|
59
|
+
def apply_templates(source)
|
60
|
+
public_file = source.pub_file absolute: true
|
61
|
+
dom = File.open(public_file, 'r') { Nokogiri::HTML _1 }
|
62
|
+
changes = Fronde::CONFIG.get('templates', []).map do |config|
|
69
63
|
template = Fronde::Templater.new(source, dom, config)
|
70
|
-
next if !template.valid?
|
64
|
+
next if !template.valid? || template.applied?
|
71
65
|
|
72
66
|
template.apply
|
73
|
-
true
|
74
|
-
rescue NoHeadError
|
75
|
-
warn R18n.t.fronde.error.templater.no_head_element(file: file_name)
|
76
|
-
next
|
77
|
-
end.any?
|
78
|
-
end
|
79
|
-
|
80
|
-
def open_dom(file_name)
|
81
|
-
File.open(file_name, 'r') do |file|
|
82
|
-
Nokogiri::HTML file
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
def write_dom(file_name, dom)
|
87
|
-
File.open(file_name, 'w') do |file|
|
88
|
-
dom.write_to file
|
89
67
|
end
|
68
|
+
File.open(public_file, 'w') { dom.write_to _1 } if changes.any?
|
90
69
|
end
|
91
70
|
end
|
92
71
|
|
@@ -103,6 +82,17 @@ module Fronde
|
|
103
82
|
end
|
104
83
|
end
|
105
84
|
|
85
|
+
def warn_no_element(source)
|
86
|
+
public_file = @org_file.pub_file(absolute: true)
|
87
|
+
warn(
|
88
|
+
I18n.t(
|
89
|
+
'fronde.error.templater.no_element_found',
|
90
|
+
source: source, file: public_file.sub(/^#{Dir.pwd}/, '.')
|
91
|
+
)
|
92
|
+
)
|
93
|
+
'' # Return empty string
|
94
|
+
end
|
95
|
+
|
106
96
|
def extract_content
|
107
97
|
# We must either have a source or a content key
|
108
98
|
source = @config.delete 'source'
|
@@ -111,30 +101,24 @@ module Fronde
|
|
111
101
|
end
|
112
102
|
|
113
103
|
node = @dom.css(source)
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
source: source,
|
119
|
-
file: Fronde::CONFIG.get('html_public_folder') + @org_file.pub_file
|
120
|
-
)
|
121
|
-
)
|
122
|
-
return ''
|
104
|
+
if node.any?
|
105
|
+
# Put it back in config
|
106
|
+
@config['source'] = node
|
107
|
+
return node.to_s
|
123
108
|
end
|
124
109
|
|
125
|
-
|
126
|
-
|
110
|
+
# Do nothing if we don’t have a reliable content to work with
|
111
|
+
warn_no_element source
|
127
112
|
end
|
128
113
|
|
129
|
-
def check_path
|
114
|
+
def check_path
|
130
115
|
paths = @config['path']
|
131
116
|
return true unless paths
|
132
117
|
|
133
118
|
paths = [paths] unless paths.is_a? Array
|
134
119
|
|
135
|
-
pub_folder = Fronde::CONFIG.get('html_public_folder')
|
136
120
|
paths.any? do |template_path|
|
137
|
-
File.fnmatch?(
|
121
|
+
File.fnmatch?(template_path, @org_file.pub_file)
|
138
122
|
end
|
139
123
|
end
|
140
124
|
end
|
data/lib/fronde/version.rb
CHANGED
data/lib/tasks/cli.rake
CHANGED
@@ -2,6 +2,24 @@
|
|
2
2
|
|
3
3
|
require_relative '../fronde/cli/opt_parse'
|
4
4
|
|
5
|
+
def comp_opt_to_liquid(option, command)
|
6
|
+
opt_config = Fronde::CLI::OptParse::FRONDE_OPTIONS[option]
|
7
|
+
keyword = nil
|
8
|
+
unless opt_config[:boolean]
|
9
|
+
keyword = opt_config[:keyword] || opt_config[:long].upcase
|
10
|
+
end
|
11
|
+
{
|
12
|
+
'command' => command,
|
13
|
+
'short' => option,
|
14
|
+
'short_no_dash' => option.delete_prefix('-'),
|
15
|
+
'long' => "--#{opt_config[:long]}",
|
16
|
+
'long_no_dash' => opt_config[:long],
|
17
|
+
'keyword' => keyword,
|
18
|
+
'choices' => opt_config[:choices],
|
19
|
+
'help' => opt_config[:help]
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
5
23
|
namespace :cli do
|
6
24
|
desc 'Generate an autocomplete file for zsh'
|
7
25
|
task :zsh_complete do
|
@@ -10,24 +28,38 @@ namespace :cli do
|
|
10
28
|
data['commands'] = all_commands.filter_map do |command, options|
|
11
29
|
next if options[:alias] || command == 'basic'
|
12
30
|
|
13
|
-
opts = (options[:opts] || []).map
|
14
|
-
opt_config = Fronde::CLI::OptParse::FRONDE_OPTIONS[opt]
|
15
|
-
keyword = nil
|
16
|
-
unless opt_config[:boolean]
|
17
|
-
keyword = opt_config[:keyword] || opt_config[:long].upcase
|
18
|
-
end
|
19
|
-
{ 'short' => opt,
|
20
|
-
'long' => "--#{opt_config[:long]}",
|
21
|
-
'keyword' => keyword }
|
22
|
-
end
|
23
|
-
|
24
|
-
translation = R18n.t.fronde.bin.commands[command].tr("'", '’')
|
31
|
+
opts = (options[:opts] || []).map { comp_opt_to_liquid(_1, command) }
|
25
32
|
{ 'name' => command,
|
26
|
-
'translation' =>
|
33
|
+
'translation' => I18n.t("fronde.bin.commands.#{command}"),
|
27
34
|
'options' => opts }
|
28
35
|
end
|
29
36
|
source = File.expand_path '../fronde/cli/data/zsh_completion', __dir__
|
30
37
|
template = Liquid::Template.parse(File.read(source))
|
31
38
|
puts template.render(data)
|
32
39
|
end
|
40
|
+
|
41
|
+
desc 'Generate an autocomplete file for fish'
|
42
|
+
task :fish_complete do
|
43
|
+
data = { 'commands' => [], 'details' => [] }
|
44
|
+
all_commands = []
|
45
|
+
Fronde::CLI::OptParse::FRONDE_COMMANDS.each do |command, options|
|
46
|
+
next if options[:alias]
|
47
|
+
|
48
|
+
data['details'] += (options[:opts] || []).map do |opt|
|
49
|
+
comp_opt_to_liquid opt, command
|
50
|
+
end
|
51
|
+
next if command == 'basic'
|
52
|
+
|
53
|
+
data['commands'] << command
|
54
|
+
|
55
|
+
help = I18n.t("fronde.bin.commands.#{command}")
|
56
|
+
all_commands << "#{command}\\t'#{help}'"
|
57
|
+
end
|
58
|
+
|
59
|
+
data['comcomp'] = all_commands.join('\n')
|
60
|
+
|
61
|
+
source = File.expand_path '../fronde/cli/data/fish_completion', __dir__
|
62
|
+
template = Liquid::Template.parse(File.read(source))
|
63
|
+
puts template.render(data)
|
64
|
+
end
|
33
65
|
end
|
data/lib/tasks/org.rake
CHANGED
@@ -8,10 +8,12 @@ require_relative '../fronde/cli/throbber'
|
|
8
8
|
require 'rake/clean'
|
9
9
|
|
10
10
|
CLOBBER.push(
|
11
|
-
'var/lib/org-config.el', '.
|
12
|
-
'lib/htmlize.el'
|
11
|
+
'var/lib/org-config.el', 'lib/htmlize.el'
|
13
12
|
)
|
14
13
|
|
14
|
+
HTMLIZE_TAG = 'release/1.58'
|
15
|
+
OX_GMI_TAG = 'v0.2'
|
16
|
+
|
15
17
|
namespace :org do
|
16
18
|
directory 'var/tmp'
|
17
19
|
|
@@ -20,54 +22,50 @@ namespace :org do
|
|
20
22
|
# Weird Rake issue, still executing the task even if the file exists
|
21
23
|
next if File.exist? 'var/tmp/org.tar.gz'
|
22
24
|
|
23
|
-
download = Thread.new
|
24
|
-
|
25
|
-
|
26
|
-
else
|
27
|
-
Fronde::CLI::Throbber.run(download, R18n.t.fronde.tasks.org.downloading)
|
25
|
+
download = Thread.new do
|
26
|
+
version = Fronde::Org.download
|
27
|
+
puts I18n.t('fronde.tasks.org.downloaded', version:) if verbose
|
28
28
|
end
|
29
|
-
|
30
|
-
|
29
|
+
Fronde::CLI::Throbber.run(
|
30
|
+
download, I18n.t('fronde.tasks.org.downloading'), verbose
|
31
|
+
)
|
32
|
+
rescue RuntimeError, Interrupt
|
33
|
+
warn I18n.t('fronde.tasks.org.no_download') if verbose
|
31
34
|
end
|
32
35
|
|
33
36
|
desc 'Compile Org'
|
34
37
|
multitask compile: ['var/tmp/org.tar.gz', 'lib'] do |task|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
next
|
41
|
-
end
|
42
|
-
org_dir = "lib/org-#{org_version}"
|
38
|
+
# No need to force fetch last version as it is only interesting as
|
39
|
+
# part of the upgrade task
|
40
|
+
version = Fronde::Org.last_version
|
41
|
+
|
42
|
+
org_dir = "lib/org-#{version}"
|
43
43
|
next if Dir.exist?("#{org_dir}/lisp")
|
44
44
|
|
45
45
|
build = Thread.new do
|
46
|
-
Fronde::Org.compile(
|
47
|
-
task.prerequisites[0], org_version, org_dir, verbose: verbose
|
48
|
-
)
|
46
|
+
Fronde::Org.compile(task.prerequisites[0], version, org_dir, verbose:)
|
49
47
|
Dir.glob('lib/org-[0-9.]*').each { rm_r _1 unless _1 == org_dir }
|
48
|
+
puts I18n.t('fronde.tasks.org.installed', version:) if verbose
|
50
49
|
end
|
51
|
-
|
52
|
-
build.
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
end
|
50
|
+
Fronde::CLI::Throbber.run(
|
51
|
+
build, I18n.t('fronde.tasks.org.installing'), verbose
|
52
|
+
)
|
53
|
+
rescue RuntimeError, Interrupt
|
54
|
+
next
|
57
55
|
end
|
58
56
|
|
59
57
|
directory 'lib'
|
60
58
|
|
61
59
|
file 'lib/htmlize.el' => 'lib' do
|
62
60
|
htmlize = URI(
|
63
|
-
|
61
|
+
"https://raw.githubusercontent.com/hniksic/emacs-htmlize/refs/tags/#{HTMLIZE_TAG}/htmlize.el"
|
64
62
|
).open.read
|
65
63
|
File.write 'lib/htmlize.el', htmlize
|
66
64
|
end
|
67
65
|
|
68
66
|
file 'lib/ox-gmi.el' => 'lib' do
|
69
67
|
ox_gmi = URI(
|
70
|
-
|
68
|
+
"https://git.umaneti.net/ox-gmi/plain/ox-gmi.el?h=#{OX_GMI_TAG}"
|
71
69
|
).open.read
|
72
70
|
File.write 'lib/ox-gmi.el', ox_gmi
|
73
71
|
end
|
@@ -76,10 +74,6 @@ namespace :org do
|
|
76
74
|
Fronde::CONFIG.write_org_lisp_config
|
77
75
|
end
|
78
76
|
|
79
|
-
file '.dir-locals.el' => 'var/lib/org-config.el' do
|
80
|
-
Fronde::Config::Helpers.write_dir_locals
|
81
|
-
end
|
82
|
-
|
83
77
|
file '.gitignore' do
|
84
78
|
next if File.exist? '.gitignore'
|
85
79
|
|
@@ -91,9 +85,10 @@ namespace :org do
|
|
91
85
|
|
92
86
|
desc 'Install Org'
|
93
87
|
multitask install: ['org:compile', '.gitignore'] do
|
94
|
-
#
|
95
|
-
#
|
96
|
-
|
88
|
+
# lib/htmlize.el and lib/ox-gmi.el cannot be generated in parallel
|
89
|
+
# of org:compilation, as it will leads to a weird SSL error. Thus
|
90
|
+
# finishing file generation "manually" here.
|
91
|
+
Rake::Task['var/lib/org-config.el'].invoke
|
97
92
|
sources = Fronde::CONFIG.sources
|
98
93
|
sources.each { mkdir_p _1['path'] }
|
99
94
|
|
data/lib/tasks/site.rake
CHANGED
@@ -5,82 +5,104 @@ require_relative '../fronde/index'
|
|
5
5
|
require_relative '../fronde/templater'
|
6
6
|
require_relative '../fronde/cli/throbber'
|
7
7
|
|
8
|
+
def remove_orphan_file_maybe(file_path)
|
9
|
+
print I18n.t('fronde.tasks.site.remove_orphan_file')
|
10
|
+
action = $stdin.gets.strip.downcase
|
11
|
+
return unless action == 'y'
|
12
|
+
|
13
|
+
FileUtils.rm file_path
|
14
|
+
end
|
15
|
+
|
8
16
|
namespace :site do
|
9
17
|
desc 'Build all your projects'
|
10
18
|
task :build, [:force?] => ['var/lib/org-config.el'] do |_, args|
|
11
19
|
args.with_defaults(force?: false)
|
20
|
+
|
21
|
+
FileUtils.rm_f 'var/tmp/keywords'
|
12
22
|
build_index = Thread.new do
|
13
|
-
all_index = Fronde::Index.
|
23
|
+
all_index = Fronde::Index.all_blog_index
|
24
|
+
offset = 0
|
14
25
|
all_index.each do |index|
|
15
|
-
index.write_all_org(verbose:
|
26
|
+
index.write_all_org(verbose:)
|
27
|
+
offset = File.write('var/tmp/keywords', index.emacs_keywords, offset)
|
16
28
|
end
|
17
29
|
Thread.current[:all_indexes] = all_index
|
18
30
|
end
|
19
|
-
|
20
|
-
build_index.
|
21
|
-
|
22
|
-
Fronde::CLI::Throbber.run(
|
23
|
-
build_index, R18n.t.fronde.tasks.site.generating_indexes
|
24
|
-
)
|
25
|
-
end
|
31
|
+
Fronde::CLI::Throbber.run(
|
32
|
+
build_index, I18n.t('fronde.tasks.site.generating_indexes'), verbose
|
33
|
+
)
|
26
34
|
all_indexes = build_index[:all_indexes]
|
27
35
|
|
28
|
-
|
29
|
-
|
30
|
-
rm_r 'var/tmp/timestamps', force: true if args[:force?]
|
31
|
-
Fronde::Emacs.new(verbose: verbose).publish
|
32
|
-
end
|
33
|
-
Fronde::CLI::Throbber.run(build_html, R18n.t.fronde.tasks.site.building)
|
34
|
-
|
35
|
-
# :nocov:
|
36
|
-
rescue RuntimeError
|
37
|
-
warn R18n.t.fronde.tasks.site.aborting
|
38
|
-
next
|
36
|
+
build_html = Thread.new do
|
37
|
+
Fronde::Emacs.new(verbose:).publish(force: args[:force?])
|
39
38
|
end
|
40
|
-
|
41
|
-
|
39
|
+
Fronde::CLI::Throbber.run(
|
40
|
+
build_html, I18n.t('fronde.tasks.site.building'), verbose
|
41
|
+
)
|
42
42
|
if all_indexes.any?
|
43
|
-
|
44
|
-
all_indexes.each
|
45
|
-
|
46
|
-
publish_feed = Thread.new do
|
47
|
-
all_indexes.each do |index|
|
48
|
-
index.write_all_feeds(verbose: false)
|
49
|
-
end
|
43
|
+
publish_feed = Thread.new do
|
44
|
+
all_indexes.each do |index|
|
45
|
+
index.write_all_feeds(verbose: false)
|
50
46
|
end
|
51
|
-
Fronde::CLI::Throbber.run(
|
52
|
-
publish_feed, R18n.t.fronde.tasks.site.publishing_feeds
|
53
|
-
)
|
54
47
|
end
|
48
|
+
Fronde::CLI::Throbber.run(
|
49
|
+
publish_feed, I18n.t('fronde.tasks.site.publishing_feeds'), verbose
|
50
|
+
)
|
55
51
|
end
|
56
52
|
|
57
53
|
next unless Fronde::CONFIG.sources.any? { |source| source.type == 'html' }
|
58
54
|
|
59
55
|
customize_html = Thread.new do
|
60
56
|
pubfolder = Fronde::CONFIG.get('html_public_folder')
|
61
|
-
Dir
|
57
|
+
Dir.glob("#{pubfolder}/**/*.html").each do |f|
|
58
|
+
if verbose
|
59
|
+
short_file = f.sub(/^#{Dir.pwd}/, '.')
|
60
|
+
puts I18n.t('fronde.tasks.site.customizing_file', file: short_file)
|
61
|
+
end
|
62
62
|
Fronde::Templater.customize_output(f)
|
63
63
|
end
|
64
64
|
end
|
65
65
|
Fronde::CLI::Throbber.run(
|
66
|
-
customize_html,
|
66
|
+
customize_html, I18n.t('fronde.tasks.site.customizing'), verbose
|
67
67
|
)
|
68
|
+
# :nocov:
|
69
|
+
rescue RuntimeError, Interrupt
|
70
|
+
warn I18n.t('fronde.tasks.site.aborting')
|
71
|
+
next
|
72
|
+
# :nocov:
|
73
|
+
end
|
74
|
+
|
75
|
+
desc 'Build a single file'
|
76
|
+
task :build_file, %i[path force?] do |_, args|
|
77
|
+
args.with_defaults(force?: false)
|
78
|
+
Fronde::Emacs.new(verbose: true).publish_file(
|
79
|
+
args[:path], force: args[:force?]
|
80
|
+
)
|
81
|
+
puts I18n.t('fronde.tasks.site.customizing_file', file: args[:path])
|
82
|
+
Fronde::Templater.customize_output(args[:path])
|
68
83
|
end
|
69
84
|
|
70
85
|
desc 'Cleanup orphaned published files'
|
71
86
|
task :clean do
|
87
|
+
Fronde::Index.all_blog_index do |index|
|
88
|
+
project = index.project
|
89
|
+
all_tags = %w[index] + index.all_tags
|
90
|
+
Dir.glob("#{project['path']}/tags/*").each do |file_name|
|
91
|
+
slug = File.basename file_name, '.org'
|
92
|
+
next if all_tags.include?(slug)
|
93
|
+
|
94
|
+
short_file = file_name.sub(/^#{Dir.pwd}/, '.')
|
95
|
+
puts I18n.t('fronde.tasks.site.orphan_tag', file: short_file)
|
96
|
+
remove_orphan_file_maybe file_name
|
97
|
+
end
|
98
|
+
end
|
72
99
|
pubfolder = Fronde::CONFIG.get('html_public_folder')
|
73
|
-
Dir
|
100
|
+
Dir.glob("#{pubfolder}/**/*.html").each do |file_name|
|
74
101
|
source = Fronde::Org::File.new(file_name)
|
75
|
-
|
76
102
|
# Return if an org file has been found for this published file
|
77
103
|
next unless source.file == file_name
|
78
104
|
|
79
|
-
|
80
|
-
action = $stdin.gets.strip.downcase
|
81
|
-
next unless action == 'y'
|
82
|
-
|
83
|
-
rm file_name
|
105
|
+
remove_orphan_file_maybe file_name
|
84
106
|
end
|
85
107
|
end
|
86
108
|
|
data/lib/tasks/sync.rake
CHANGED
@@ -1,40 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative '../fronde/config'
|
4
|
+
require_relative '../fronde/sync'
|
4
5
|
require_relative '../fronde/cli/throbber'
|
5
6
|
|
6
|
-
module Fronde
|
7
|
-
class SyncError < ::StandardError; end
|
8
|
-
end
|
9
|
-
|
10
|
-
def rsync_command(test = nil)
|
11
|
-
rsync_command = Fronde::CONFIG.get('rsync')
|
12
|
-
return rsync_command unless rsync_command.nil?
|
13
|
-
|
14
|
-
optstring = []
|
15
|
-
optstring << 'n' if test
|
16
|
-
if verbose
|
17
|
-
optstring << 'v'
|
18
|
-
else
|
19
|
-
optstring << 'q'
|
20
|
-
end
|
21
|
-
"rsync -#{optstring.join}rlt --delete"
|
22
|
-
end
|
23
|
-
|
24
|
-
def pull_or_push(direction, type, test)
|
25
|
-
remote_path = Fronde::CONFIG.get("#{type}_remote")
|
26
|
-
raise Fronde::SyncError, "No #{type} remote path set" if remote_path.nil?
|
27
|
-
|
28
|
-
public_folder = Fronde::CONFIG.get("#{type}_public_folder")
|
29
|
-
# Default is to push
|
30
|
-
cmd = ["#{public_folder}/", remote_path]
|
31
|
-
cmd.reverse! if direction == :pull
|
32
|
-
rsync = rsync_command(test)
|
33
|
-
Thread.new do
|
34
|
-
sh "#{rsync} #{cmd.join(' ')}"
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
7
|
def source_types
|
39
8
|
Fronde::CONFIG.sources.map(&:type).uniq
|
40
9
|
end
|
@@ -43,34 +12,34 @@ namespace :sync do
|
|
43
12
|
desc 'Push changes to server'
|
44
13
|
task :push, :test? do |_, args|
|
45
14
|
source_types.each do |type|
|
46
|
-
publish_thread = pull_or_push(
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
end
|
54
|
-
rescue Fronde::SyncError => e
|
15
|
+
publish_thread = Fronde::Sync.pull_or_push(
|
16
|
+
:push, type, test: args[:test?], verbose: verbose
|
17
|
+
)
|
18
|
+
Fronde::CLI::Throbber.run(
|
19
|
+
publish_thread, format('Publishing %<fmt>s:', fmt: type), verbose
|
20
|
+
)
|
21
|
+
rescue Fronde::Sync::Error => e
|
55
22
|
warn e
|
56
23
|
next
|
57
24
|
end
|
25
|
+
rescue RuntimeError, Interrupt
|
26
|
+
next
|
58
27
|
end
|
59
28
|
|
60
29
|
desc 'Pull changes from server'
|
61
30
|
task :pull, :test? do |_, args|
|
62
31
|
source_types.each do |type|
|
63
|
-
pull_thread = pull_or_push(
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
end
|
71
|
-
rescue Fronde::SyncError => e
|
32
|
+
pull_thread = Fronde::Sync.pull_or_push(
|
33
|
+
:pull, type, test: args[:test?], verbose: verbose
|
34
|
+
)
|
35
|
+
Fronde::CLI::Throbber.run(
|
36
|
+
pull_thread, format('Pulling %<fmt>s:', fmt: type), verbose
|
37
|
+
)
|
38
|
+
rescue Fronde::Sync::Error => e
|
72
39
|
warn e
|
73
40
|
next
|
74
41
|
end
|
42
|
+
rescue RuntimeError, Interrupt
|
43
|
+
next
|
75
44
|
end
|
76
45
|
end
|
data/lib/tasks/tags.rake
CHANGED
@@ -5,7 +5,7 @@ require_relative '../fronde/index'
|
|
5
5
|
namespace :tags do
|
6
6
|
desc 'List all tags by name'
|
7
7
|
task :name do
|
8
|
-
Fronde::Index.
|
8
|
+
Fronde::Index.all_blog_index do |index|
|
9
9
|
next if index.empty?
|
10
10
|
|
11
11
|
puts index.sort_by(:name).join("\n")
|
@@ -14,7 +14,7 @@ namespace :tags do
|
|
14
14
|
|
15
15
|
desc 'List all tags by weight'
|
16
16
|
task :weight do
|
17
|
-
Fronde::Index.
|
17
|
+
Fronde::Index.all_blog_index do |index|
|
18
18
|
next if index.empty?
|
19
19
|
|
20
20
|
puts index.sort_by(:weight).join("\n")
|