neruda 0.1.0 → 0.2.2

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