neruda 0.1.3 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: de0736f77b1fd461b05781a1afee1775cc0e0bf8fea098f14223475a28fb5282
4
- data.tar.gz: c3443f328c833e1591631243f4df6e7ff29dbc2fcceb3889bc0d0f763b41662f
3
+ metadata.gz: 17662f4cf2e6c65e29fa06f8ca3554e251eaa89ead1c5e194922d20a4def3f21
4
+ data.tar.gz: 801cb4f6d07b83b1fc466036e5d91e3411d922de8be1a4c66dc63cc67a3ff461
5
5
  SHA512:
6
- metadata.gz: 6239d642c54843825f9009514772452200acfd70ca3b65ed564b761fc24ae885ec7b0bf852b8bd947c8b24d325013342c3047019b83f33f98067d0162c0b3bef
7
- data.tar.gz: bd3528ca312d8435b360fb34436817e4ffbea7e3bd758a90ea74b5713d7ec457ee1844dc443459705f6c0c94c22aaaad313b8d6b8565cfacc6a4a309c33e63a2
6
+ metadata.gz: fd3e86c22eb0c8f0236d3094fa63defb33a60a9635527cae27675c894563013af06d47f74d81af12bcdd38a34d25e8124be43a8a4d4b2be9905f9e4412857532
7
+ data.tar.gz: 73410f4451ff330b9293c936837a928787b4ab0b186cfff3723c724b8c2dcbbc5358f938caf90370cfa795dedf7fc6e199e5d48a1f0b664fad5fb40f207da667
data/bin/pablo CHANGED
@@ -7,42 +7,41 @@ require 'r18n-core'
7
7
  require 'neruda/utils'
8
8
  require 'neruda/version'
9
9
 
10
- R18n.set(Neruda::Config.settings['lang'],
11
- File.expand_path('../locales', __dir__))
10
+ R18n.default_places = File.expand_path('../locales', __dir__)
11
+ R18n.set Neruda::Config.settings['lang']
12
12
 
13
13
  # Pablo commands
14
14
  module PabloCommands
15
15
  def pablo_init
16
16
  cnf = @options.merge
17
17
  cnf.delete(:verbose)
18
- cnf.delete(:directory)
19
18
  cnf.transform_keys!(&:to_s)
20
19
  Neruda::Config.save(Neruda::Config.settings.merge(cnf))
21
20
  @rake.options.build_all = true
22
21
  @rake.invoke_task('org:install')
23
- o = Neruda::OrgFile.new('src/index.org', @options)
24
- o.write unless File.exist? 'src/index.org'
22
+ return if File.exist? 'src/index.org'
23
+ Neruda::OrgFile.new('src/index.org', @options).write
24
+ pablo_open 'src/index.org'
25
25
  end
26
26
  alias_method :pablo_config, :pablo_init
27
27
 
28
- def pablo_build(file = ARGV[0])
28
+ def pablo_build
29
29
  @rake.options.build_all = true
30
- if file.nil?
31
- @rake.invoke_task('site:build')
32
- else
33
- @rake.invoke_task("site:build:one[#{file}]")
34
- end
30
+ task = 'site:build'
31
+ task = "#{task}[true]" if @options[:force]
32
+ @rake.invoke_task task
35
33
  end
36
34
 
37
35
  def pablo_preview
38
36
  Thread.new do
39
37
  sleep 1
40
- port = Neruda::Config.settings['server_port'] || 5000
38
+ port = Neruda::Config.settings.dig('preview', 'server_port') || 5000
41
39
  uri = "http://127.0.0.1:#{port}/"
42
40
  current_os = Neruda::Utils.current_os
43
- if current_os == 'windows'
41
+ case current_os
42
+ when 'windows'
44
43
  system 'start', uri
45
- elsif current_os == 'apple'
44
+ when 'apple'
46
45
  system 'open', uri
47
46
  else
48
47
  system 'gio', 'open', uri
@@ -51,14 +50,17 @@ module PabloCommands
51
50
  @rake.invoke_task('site:preview')
52
51
  end
53
52
 
54
- def pablo_open
55
- filename = new_file_name(ARGV[0])
56
- FileUtils.mkdir_p File.dirname(filename)
57
- o = Neruda::OrgFile.new(filename, @options)
58
- o.write unless File.exist? filename
53
+ def pablo_open(file_path = ARGV[0])
59
54
  editor = ENV['EDITOR'] || ENV['VISUAL'] || 'emacs'
60
- cmd = [editor, filename]
61
- cmd.insert(1, '+6') if editor.match?(/^emacs/)
55
+ cmd = [editor]
56
+ if file_path.nil? || !File.file?(file_path)
57
+ # file_path may be updated with title given in options
58
+ file_path = create_new_file(file_path)
59
+ # Only move to the end of file for new file. Let the editor handle
60
+ # the best position for already existing files
61
+ cmd << '+6'
62
+ end
63
+ cmd << file_path
62
64
  system(*cmd)
63
65
  end
64
66
  alias_method :pablo_edit, :pablo_open
@@ -67,27 +69,56 @@ module PabloCommands
67
69
  @rake.invoke_task('sync:push')
68
70
  end
69
71
 
70
- def pablo_help(command = 'basic', error = false)
72
+ def pablo_help(command = 'basic', error: false)
71
73
  warn R18n.t.pablo.error.no_command if error
72
74
  cmd = Neruda::Utils.resolve_possible_alias(command)
73
75
  cmd_opt = Neruda::Utils::PABLO_COMMANDS[cmd]
74
76
  label = cmd_opt[:label] || command
75
- warn "Usage: pablo #{label} [options]\n\n"
76
- warn cmd_opt[:desc] + "\n\n" if cmd_opt.has_key?(:desc)
77
- warn "Options\n#{Neruda::Utils.summarize_command(cmd)}\n"
78
- warn "Commands\n#{Neruda::Utils.list_commands}\n" if cmd == 'basic'
77
+ warn format("%<label>s\n\n", label: R18n.t.pablo.usage(label))
78
+ if R18n.t.pablo.commands[cmd].translated?
79
+ warn format("%<label>s\n\n", label: R18n.t.pablo.commands[cmd])
80
+ end
81
+ warn help_command_body(cmd).join("\n")
79
82
  exit 1 if error
80
83
  exit
81
84
  end
82
85
 
83
86
  private
84
87
 
85
- def new_file_name(title)
86
- title ||= @options[:title]
87
- title = 'new' if title.nil? || title == ''
88
- filename = Neruda::OrgFile.slug title
89
- return "#{filename}.org" unless @options[:directory]
90
- "#{filename}/index.org"
88
+ def new_file_name(file_path)
89
+ file_path = File.expand_path(file_path || '')
90
+ return file_path if file_path[-4..] == '.org'
91
+ # file_path seems to be a dir path. Thus we have to create the new
92
+ # filename from its title
93
+ title = @options[:title]
94
+ # No title, nor a reliable file_path? Better abort
95
+ return nil if title.nil? || title == ''
96
+ filename = "#{Neruda::OrgFile.slug(title)}.org"
97
+ File.join file_path, filename
98
+ end
99
+
100
+ def create_new_file(file_path)
101
+ filename = new_file_name(file_path)
102
+ if filename.nil?
103
+ warn R18n.t.pablo.error.no_file
104
+ exit 1
105
+ end
106
+ FileUtils.mkdir_p File.dirname(filename)
107
+ Neruda::OrgFile.new(filename, @options).write
108
+ filename
109
+ end
110
+
111
+ def help_command_body(command)
112
+ body = [
113
+ R18n.t.pablo.options.cmd_title,
114
+ Neruda::Utils.summarize_command(command)
115
+ ]
116
+ return body unless command == 'basic'
117
+ body + [
118
+ '',
119
+ R18n.t.pablo.commands.cmd_title,
120
+ Neruda::Utils.list_commands
121
+ ]
91
122
  end
92
123
  end
93
124
 
@@ -117,8 +148,8 @@ class Pablo
117
148
  require 'r18n-core'
118
149
 
119
150
  neruda_spec = Gem::Specification.find_by_name 'neruda'
120
- R18n.set(Neruda::Config.settings['lang'] || 'en',
121
- "\#{neruda_spec.gem_dir}/locales")
151
+ R18n.default_places = "\#{neruda_spec.gem_dir}/locales"
152
+ R18n.set(Neruda::Config.settings['lang'] || 'en')
122
153
  R18n::Filters.on(:named_variables)
123
154
 
124
155
  Dir.glob("\#{neruda_spec.gem_dir}/lib/tasks/*.rake").each { |r| import r }
@@ -153,10 +184,10 @@ command = "pablo_#{ARGV[0]}".to_sym
153
184
  cmd_err = !pablo.respond_to?(command)
154
185
  if params[:help] || cmd_err
155
186
  cmd_err = false if params[:help] && !ARGV[0]
156
- pablo.pablo_help(ARGV[0], cmd_err)
187
+ pablo.pablo_help(ARGV[0], error: cmd_err)
157
188
  end
158
189
  ARGV.shift
159
190
 
160
- init_cmds = ['pablo_init', 'pablo_config']
191
+ init_cmds = [:pablo_init, :pablo_config]
161
192
  pablo.pablo_init unless File.exist?('config.yml') || init_cmds.include?(command)
162
193
  pablo.send command
@@ -53,8 +53,17 @@ module Neruda
53
53
  # @param new_config [Hash] the settings to save
54
54
  # @return [Hash] the new settings after save
55
55
  def save(new_config)
56
+ # Do not save obvious default config values. We'll always try to
57
+ # save author and lang as they default on system variables,
58
+ # which may be different from a system to another. Thus it may
59
+ # be confusing if one use neruda on two different computer and
60
+ # these params always change.
61
+ new_config.delete_if do |k, v|
62
+ ['domain', 'public_folder', 'templates', 'theme'].include?(k) \
63
+ && v == default_settings[k]
64
+ end
56
65
  IO.write 'config.yml', new_config.to_yaml
57
- @config = new_config.freeze
66
+ load_settings # Reload config, taking default settings into account
58
67
  end
59
68
 
60
69
  # Load the given settings as if they comes from the ~config.yml~ file.
@@ -66,28 +75,62 @@ module Neruda
66
75
  # @param config [Hash] the settings to artificially load
67
76
  # @return [Hash] the new settings
68
77
  def load_test(config)
69
- @config = config
70
- add_default_settings
78
+ @sources = nil # Reset sources
79
+ @config = default_settings.merge config
80
+ end
81
+
82
+ # Return the qualified projects sources list.
83
+ #
84
+ # @return [Array] the fully qualified projects sources list
85
+ def sources
86
+ return @sources if @sources
87
+ default_sources = [{ 'path' => 'src', 'target' => '.' }]
88
+ @sources = (settings['sources'] || default_sources).map do |s|
89
+ build_source(s)
90
+ end.compact
71
91
  end
72
92
 
73
93
  private
74
94
 
75
95
  def load_settings
76
- @config = {}
77
- conf = 'config.yml'
78
- @config = YAML.load_file(conf) if File.exist? conf
79
- add_default_settings
80
- @config.freeze
96
+ @sources = nil
97
+ conf_file = 'config.yml'
98
+ if File.exist? conf_file
99
+ @config = default_settings.merge(YAML.load_file(conf_file)).freeze
100
+ else
101
+ @config = default_settings
102
+ end
103
+ end
104
+
105
+ def extract_lang_from_env(default)
106
+ (ENV['LANG'] || default).split('_', 2).first
107
+ end
108
+
109
+ def default_settings
110
+ return @default_settings if @default_settings
111
+ @default_settings = {
112
+ 'author' => (ENV['USER'] || ''),
113
+ 'domain' => '',
114
+ 'lang' => extract_lang_from_env('en'),
115
+ 'public_folder' => 'public_html',
116
+ 'templates' => [],
117
+ 'theme' => 'default'
118
+ }.freeze
81
119
  end
82
120
 
83
- def add_default_settings
84
- @config['lang'] ||= 'en'
85
- @config['author'] ||= (ENV['USER'] || '')
86
- @config['domain'] ||= ''
87
- @config['public_folder'] ||= 'public_html'
88
- @config['templates'] ||= []
89
- return if @config['blog_path'].nil?
90
- @config['blog_pattern'] ||= '**/*.org'
121
+ def build_source(seed)
122
+ opts = { 'recursive' => true, 'is_blog' => false }
123
+ case seed
124
+ when String
125
+ opts['path'] = seed
126
+ when Hash
127
+ opts.merge! seed
128
+ end
129
+ return nil unless opts.has_key?('path')
130
+ opts['path'] = File.expand_path(opts['path'])
131
+ opts['name'] ||= File.basename(opts['path']).sub(/^\./, '')
132
+ opts['target'] ||= opts['name']
133
+ opts
91
134
  end
92
135
  end
93
136
  end
@@ -1,28 +1,32 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'json'
3
4
  require 'open-uri'
5
+ require 'neruda/version'
4
6
 
5
7
  module Neruda
6
8
  # This module contains utilitary methods to ease ~org-config.el~
7
9
  # file generation
8
10
  module LispConfig
9
- # Fetch and return the last published version of org mode.
11
+ # Fetch and return the last published version of Org.
10
12
  #
11
- # @return [String] the new x.x.x version string of org mode
13
+ # @return [String] the new x.x.x version string of Org
12
14
  def org_last_version
13
15
  return @org_version if @org_version
14
- index = open('https://orgmode.org/index.html', 'r').read
15
- last_ver = index.match(/https:\/\/orgmode\.org\/org-([0-9.]+)\.tar\.gz/)
16
- # :nocov:
17
- if last_ver.nil?
18
- warn 'Org last version not found'
19
- return nil
16
+ if File.exist?('tmp/__last_org_version__')
17
+ @org_version = IO.read('tmp/__last_org_version__')
18
+ return @org_version
20
19
  end
21
- # :nocov:
22
- @org_version = last_ver[1]
20
+ versions = JSON.parse(
21
+ URI('https://updates.orgmode.org/data/releases').open.read
22
+ ).sort { |a, b| b['date'] <=> a['date'] }
23
+ @org_version = versions.first['version']
24
+ FileUtils.mkdir_p 'tmp'
25
+ IO.write('tmp/__last_org_version__', @org_version)
26
+ @org_version
23
27
  end
24
28
 
25
- # Generate emacs lisp configuration file for org mode and write it.
29
+ # Generate emacs lisp configuration file for Org and write it.
26
30
  #
27
31
  # This method saves the generated configuration in the file
28
32
  # ~org-config.el~ at the root of your project, overwriting it if it
@@ -30,15 +34,16 @@ module Neruda
30
34
  #
31
35
  # @return [Integer] the length written (as returned by the
32
36
  # underlying ~IO.write~ method call)
33
- def write_org_lisp_config
34
- projects = org_generate_projects
37
+ def write_org_lisp_config(with_tags: false)
38
+ projects = org_generate_projects(with_tags: with_tags)
35
39
  workdir = Dir.pwd
36
40
  content = IO.read(File.expand_path('./org-config.el', __dir__))
41
+ .gsub('__VERSION__', Neruda::VERSION)
37
42
  .gsub('__WORK_DIR__', workdir)
38
43
  .gsub('__NERUDA_DIR__', __dir__)
39
44
  .gsub('__ORG_VER__', org_last_version)
40
- .gsub('__ALL_PROJECTS__', all_projects(projects).strip)
41
- .gsub('__THEME_CONFIG__', org_theme_config.strip)
45
+ .gsub('__ALL_PROJECTS__', all_projects(projects))
46
+ .gsub('__THEME_CONFIG__', org_default_theme_config)
42
47
  .gsub('__ALL_PROJECTS_NAMES__', project_names(projects))
43
48
  .gsub('__LONG_DATE_FMT__', r18n_full_datetime_format)
44
49
  .gsub('__AUTHOR_EMAIL__', settings['author_email'] || '')
@@ -49,8 +54,8 @@ module Neruda
49
54
  # Generate emacs directory variables file.
50
55
  #
51
56
  # This method generate the file ~.dir-locals.el~, which is
52
- # responsible to load neruda org mode settings when visiting an
53
- # org file of this neruda instance.
57
+ # responsible to load neruda Org settings when visiting an Org file
58
+ # of this neruda instance.
54
59
  #
55
60
  # @return [Integer] the length written (as returned by the
56
61
  # underlying ~IO.write~ method call)
@@ -76,69 +81,137 @@ module Neruda
76
81
  )
77
82
  end
78
83
 
84
+ def ruby_to_lisp_boolean(value)
85
+ return 't' if value == true
86
+ 'nil'
87
+ end
88
+
79
89
  def project_names(projects)
80
- projects.keys.map { |p| ["\"#{p}\"", "\"#{p}-assets\""] }
81
- .flatten.join(' ')
90
+ names = projects.keys.map do |p|
91
+ ["\"#{p}\"", "\"#{p}-assets\""]
92
+ end.flatten
93
+ unless settings['theme'] == 'default'
94
+ names << "\"theme-#{settings['theme']}\""
95
+ end
96
+ sources.each do |s|
97
+ # Default theme defined in settings is already included
98
+ next unless s['theme'] && s['theme'] != settings['theme']
99
+ # Never include theme named 'default' as it does not rely on any
100
+ # file to export.
101
+ next if s['theme'] == 'default'
102
+ theme = "\"theme-#{s['theme']}\""
103
+ next if names.include? theme
104
+ names << theme
105
+ end
106
+ names.join(' ')
82
107
  end
83
108
 
84
109
  def all_projects(projects)
85
110
  projects.values.join("\n").strip
86
- .gsub(/\n\n/, "\n")
111
+ .gsub(/\n\s*\n/, "\n")
87
112
  .gsub(/\n/, "\n ")
88
113
  end
89
114
 
90
- def org_project(project_name, opts)
91
- orgtpl = opts['org_headers']
92
- base_directory = File.expand_path(opts['path'])
115
+ # Return the full path to the publication path of a given project
116
+ # configuration.
117
+ #
118
+ # @param project [Hash] a project configuration (as extracted from
119
+ # the ~sources~ key)
120
+ # @return [String] the full path to the target dir of this project
121
+ def publication_path(project)
93
122
  publish_in = [Dir.pwd, settings['public_folder']]
94
- publish_in << project_name unless project_name == 'neruda'
95
- publish_in = publish_in.join('/')
96
- recline = [opts['recursive'] || 't']
97
- default_ex_ptrn = settings['exclude_pattern']
123
+ publish_in << project['target'] unless project['target'] == '.'
124
+ publish_in.join('/')
125
+ end
126
+
127
+ def org_project(project_name, opts)
128
+ publish_in = publication_path(opts)
129
+ other_lines = [
130
+ format(':recursive %<value>s',
131
+ value: ruby_to_lisp_boolean(opts['recursive']))
132
+ ]
98
133
  if opts['exclude']
99
- recline << ":exclude \"#{opts['exclude']}\""
100
- elsif project_name == 'neruda' && default_ex_ptrn
101
- recline << ":exclude \"#{default_ex_ptrn}\""
134
+ other_lines << format(':exclude "%<value>s"',
135
+ value: opts['exclude'])
102
136
  end
137
+ themeconf = org_theme_config(opts['theme'])
103
138
  <<~ORGPROJECT
104
139
  ("#{project_name}"
105
- :base-directory "#{base_directory}"
140
+ :base-directory "#{opts['path']}"
106
141
  :base-extension "org"
107
- :recursive #{recline.join("\n ")}
142
+ #{other_lines.join("\n ")}
108
143
  :publishing-directory "#{publish_in}"
109
144
  :publishing-function org-html-publish-to-html
110
- :section-numbers nil
111
- :with-toc nil
112
- #{orgtpl})
145
+ #{opts['org_headers']})
113
146
  ("#{project_name}-assets"
114
- :base-directory "#{base_directory}"
147
+ :base-directory "#{opts['path']}"
115
148
  :base-extension "jpg\\\\\\|gif\\\\\\|png\\\\\\|svg\\\\\\|pdf"
116
- :recursive #{recline[0]}
149
+ #{other_lines[0]}
117
150
  :publishing-directory "#{publish_in}"
118
151
  :publishing-function org-publish-attachment)
152
+ #{themeconf}
119
153
  ORGPROJECT
120
154
  end
121
155
 
122
- def org_default_theme_options
123
- postamble = <<~POSTAMBLE
156
+ def org_default_postamble
157
+ <<~POSTAMBLE
124
158
  <p><span class="author">#{R18n.t.neruda.org.postamble.written_by}</span>
125
159
  #{R18n.t.neruda.org.postamble.with_emacs}</p>
126
160
  <p class="date">#{R18n.t.neruda.org.postamble.last_modification}</p>
127
161
  <p class="validation">%v</p>
128
162
  POSTAMBLE
129
- { 'html-head' => build_html_head.strip,
130
- 'html-postamble' => postamble.strip,
163
+ end
164
+
165
+ def org_default_html_head
166
+ <<~HTMLHEAD
167
+ <link rel="stylesheet" type="text/css" media="screen"
168
+ href="__DOMAIN__/assets/__THEME__/css/style.css">
169
+ <link rel="stylesheet" type="text/css" media="screen"
170
+ href="__DOMAIN__/assets/__THEME__/css/htmlize.css">
171
+ __ATOM_FEED__
172
+ HTMLHEAD
173
+ end
174
+
175
+ def org_default_html_options(project)
176
+ defaults = {
177
+ 'section-numbers' => 'nil',
178
+ 'with-toc' => 'nil',
179
+ 'html-postamble' => org_default_postamble,
180
+ 'html-head' => '__ATOM_FEED__',
131
181
  'html-head-include-default-style' => 't',
132
- 'html-head-include-scripts' => 'nil' }
182
+ 'html-head-include-scripts' => 't'
183
+ }
184
+ curtheme = project['theme'] || settings['theme']
185
+ return defaults if curtheme.nil? || curtheme == 'default'
186
+ defaults['html-head'] = org_default_html_head
187
+ defaults['html-head-include-default-style'] = 'nil'
188
+ defaults['html-head-include-scripts'] = 'nil'
189
+ defaults
190
+ end
191
+
192
+ def expand_vars_in_html_head(head, project)
193
+ curtheme = project['theme'] || settings['theme']
194
+ # Head may be frozen when coming from settings
195
+ head = head.gsub('__THEME__', curtheme)
196
+ .gsub('__DOMAIN__', settings['domain'])
197
+ return head.gsub('__ATOM_FEED__', '') unless project['is_blog']
198
+ atomfeed = <<~ATOMFEED
199
+ <link rel="alternate" type="application/atom+xml" title="Atom 1.0"
200
+ href="#{settings['domain']}/feeds/index.xml" />
201
+ ATOMFEED
202
+ head.gsub('__ATOM_FEED__', atomfeed)
133
203
  end
134
204
 
135
- def org_templates
136
- orgtplopts = org_default_theme_options.merge
137
- orgtplopts.merge!(settings['org-html'] || {})
205
+ def build_project_org_headers(project)
206
+ orgtplopts = org_default_html_options(project).merge(
207
+ settings['org-html'] || {}, project['org-html'] || {}
208
+ )
138
209
  orgtpl = []
210
+ truthy_val = ['t', 'nil', '1'].freeze
139
211
  orgtplopts.each do |k, v|
212
+ v = expand_vars_in_html_head(v, project) if k == 'html-head'
140
213
  val = v.strip.gsub(/"/, '\"')
141
- if ['t', 'nil', '1'].include? val
214
+ if truthy_val.include? val
142
215
  orgtpl << ":#{k} #{val}"
143
216
  else
144
217
  orgtpl << ":#{k} \"#{val}\""
@@ -147,62 +220,41 @@ module Neruda
147
220
  orgtpl.join("\n ")
148
221
  end
149
222
 
150
- def org_external_projects_opts(seed, orgtpl)
151
- opts = { 'org_headers' => orgtpl }
152
- if seed.is_a? String
153
- opts['path'] = seed
154
- elsif seed.is_a? Hash
155
- opts.merge! seed
223
+ def org_generate_projects(with_tags: false)
224
+ projects = {}
225
+ projects_sources = sources
226
+ if with_tags
227
+ tags_conf = build_source('tags')
228
+ tags_conf['recursive'] = false
229
+ projects_sources << tags_conf
156
230
  end
157
- opts
231
+ projects_sources.each do |opts|
232
+ opts['org_headers'] = build_project_org_headers(opts)
233
+ projects[opts['name']] = org_project(opts['name'], opts)
234
+ end
235
+ projects
158
236
  end
159
237
 
160
- def org_generate_projects
161
- orgtpl = org_templates
162
- default_project = org_project(
163
- 'neruda', 'org_headers' => orgtpl, 'path' => './src'
164
- )
165
- projects = { 'neruda' => default_project }
166
- settings['external_sources']&.each do |s|
167
- opts = org_external_projects_opts(s, orgtpl)
168
- next unless opts.has_key?('path')
169
- pname = File.basename(opts['path']).sub(/^\./, '')
170
- projects[pname] = org_project(pname, opts)
238
+ def org_default_theme_config
239
+ theme_config = org_theme_config(settings['theme'])
240
+ return theme_config if theme_config == ''
241
+ output = theme_config.split("\n").map do |line|
242
+ " #{line}"
171
243
  end
172
- projects
244
+ format("\n%<conf>s", conf: output.join("\n"))
173
245
  end
174
246
 
175
- def org_theme_config
176
- curtheme = settings['theme'] || 'default'
247
+ def org_theme_config(theme)
248
+ return '' if theme.nil? || theme == 'default'
177
249
  workdir = Dir.pwd
178
- if curtheme == 'default'
179
- sourcedir = File.expand_path('../../../', __dir__)
180
- else
181
- sourcedir = workdir
182
- end
183
250
  <<~THEMECONFIG
184
- ("theme"
185
- :base-directory "#{sourcedir}/themes/#{curtheme}"
186
- :base-extension "jpg\\\\\\|gif\\\\\\|png\\\\\\|js\\\\\\|css\\\\\\|otf\\\\\\|ttf\\\\\\|woff2?"
187
- :recursive t
188
- :publishing-directory "#{workdir}/#{settings['public_folder']}/assets"
189
- :publishing-function org-publish-attachment)
251
+ ("theme-#{theme}"
252
+ :base-directory "#{workdir}/themes/#{theme}"
253
+ :base-extension "jpg\\\\\\|gif\\\\\\|png\\\\\\|js\\\\\\|css\\\\\\|otf\\\\\\|ttf\\\\\\|woff2?"
254
+ :recursive t
255
+ :publishing-directory "#{workdir}/#{settings['public_folder']}/assets/#{theme}"
256
+ :publishing-function org-publish-attachment)
190
257
  THEMECONFIG
191
258
  end
192
-
193
- def build_html_head
194
- stylesheet = <<~CSS
195
- <link rel="stylesheet" type="text/css" media="screen"
196
- href="#{settings['domain']}/assets/css/style.css">
197
- <link rel="stylesheet" type="text/css" media="screen"
198
- href="#{settings['domain']}/assets/css/htmlize.css">
199
- CSS
200
- return stylesheet if settings['blog_path'].nil?
201
- <<~ATOM
202
- #{stylesheet.strip}
203
- <link rel="alternate" type="application/atom+xml" title="Atom 1.0"
204
- href="#{settings['domain']}/feeds/index.xml" />
205
- ATOM
206
- end
207
259
  end
208
260
  end