neruda 0.1.2 → 0.2.4
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/bin/pablo +67 -36
- data/lib/neruda/config.rb +59 -16
- data/lib/neruda/config/lisp_config.rb +145 -93
- data/lib/neruda/config/org-config.el +6 -6
- data/lib/neruda/config/ox-neruda.el +28 -2
- data/lib/neruda/emacs.rb +37 -0
- data/lib/neruda/index.rb +52 -35
- data/lib/neruda/index/atom_generator.rb +16 -16
- data/lib/neruda/index/org_generator.rb +63 -41
- data/lib/neruda/org_file.rb +46 -13
- data/lib/neruda/org_file/class_methods.rb +38 -21
- data/lib/neruda/org_file/extracter.rb +12 -1
- data/lib/neruda/org_file/htmlizer.rb +2 -37
- data/lib/neruda/preview.rb +9 -7
- data/lib/neruda/templater.rb +19 -12
- data/lib/neruda/utils.rb +69 -33
- data/lib/neruda/version.rb +2 -1
- data/lib/tasks/org.rake +48 -26
- data/lib/tasks/site.rake +12 -33
- data/lib/tasks/sync.rake +6 -2
- data/lib/tasks/tags.rake +2 -6
- data/locales/en.yml +21 -1
- data/locales/fr.yml +22 -2
- metadata +58 -35
- data/themes/default/css/style.css +0 -216
- data/themes/default/fonts/Yanone_Kaffeesatz_400.woff +0 -0
- data/themes/default/fonts/Yanone_Kaffeesatz_400.woff2 +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f704b888004971a0ee3c321f41874132283f7f42a3c6b57f267356b7723b2260
|
4
|
+
data.tar.gz: 54c3738824f1b80b46b00654aedd805ef0a999a096f1ff320c42001027419147
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ba08196581125aa378a938cb34413d856d7126800cbe692b9237f6e3ffb7bf45743d7dd6fa0ab77c9adb13000dd266085a7ebb4fe556b3d223f620596b237074
|
7
|
+
data.tar.gz: efc4308eb4c1d43091f6134fbdee4054feb80535e01fa1cff7f79656f22540bd55011c66c6ac7ca33fb01c0b6c4dbcab6012db44f1726285dc6be85fb8236953
|
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.
|
11
|
-
|
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
|
-
|
24
|
-
|
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
|
28
|
+
def pablo_build
|
29
29
|
@rake.options.build_all = true
|
30
|
-
|
31
|
-
|
32
|
-
|
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
|
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
|
-
|
41
|
+
case current_os
|
42
|
+
when 'windows'
|
44
43
|
system 'start', uri
|
45
|
-
|
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
|
61
|
-
|
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
|
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 "
|
76
|
-
|
77
|
-
|
78
|
-
|
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(
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
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.
|
121
|
-
|
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 = [
|
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
|
data/lib/neruda/config.rb
CHANGED
@@ -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
|
-
|
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
|
-
@
|
70
|
-
|
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
|
-
@
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
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
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
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
|
11
|
+
# Fetch and return the last published version of Org.
|
10
12
|
#
|
11
|
-
# @return [String] the new x.x.x version string of
|
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
|
-
|
15
|
-
|
16
|
-
|
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
|
-
|
22
|
-
|
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
|
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)
|
41
|
-
.gsub('__THEME_CONFIG__',
|
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
|
53
|
-
#
|
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
|
81
|
-
|
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
|
-
|
91
|
-
|
92
|
-
|
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 <<
|
95
|
-
publish_in
|
96
|
-
|
97
|
-
|
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
|
-
|
100
|
-
|
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 "#{
|
140
|
+
:base-directory "#{opts['path']}"
|
106
141
|
:base-extension "org"
|
107
|
-
|
142
|
+
#{other_lines.join("\n ")}
|
108
143
|
:publishing-directory "#{publish_in}"
|
109
144
|
:publishing-function org-html-publish-to-html
|
110
|
-
|
111
|
-
:with-toc nil
|
112
|
-
#{orgtpl})
|
145
|
+
#{opts['org_headers']})
|
113
146
|
("#{project_name}-assets"
|
114
|
-
:base-directory "#{
|
147
|
+
:base-directory "#{opts['path']}"
|
115
148
|
:base-extension "jpg\\\\\\|gif\\\\\\|png\\\\\\|svg\\\\\\|pdf"
|
116
|
-
|
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
|
123
|
-
|
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
|
-
|
130
|
-
|
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' => '
|
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
|
136
|
-
orgtplopts =
|
137
|
-
|
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
|
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
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
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
|
161
|
-
|
162
|
-
|
163
|
-
|
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
|
-
|
244
|
+
format("\n%<conf>s", conf: output.join("\n"))
|
173
245
|
end
|
174
246
|
|
175
|
-
def org_theme_config
|
176
|
-
|
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
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
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
|