forked from neo4j-documentation/developer-resources
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrender_local.rb
executable file
·56 lines (45 loc) · 2.08 KB
/
render_local.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env ruby
require 'rubygems'
require 'bundler/setup'
require 'dotenv'
Dotenv.load
require 'logger'
require 'ascii_press'
LOGGER = Logger.new(STDOUT)
require './html_transformer' # Neo Tech specific
ASCIIDOC_TEMPLATES_DIR = ENV['ASCIIDOC_TEMPLATES_DIR'] || '_templates'
IMAGE_BASE_URL = ENV['IMAGE_BASE_URL'] || 'http://dev.assets.neo4j.com.s3.amazonaws.com/wp-content/uploads/' # '.'
EXAMPLES = ENV['EXAMPLES'] || 'https://github.com/neo4j-examples'
MANUAL = ENV['MANUAL'] || 'http://neo4j.com/docs/developer-manual/current'
OPSMANUAL = ENV['OPSMANUAL'] || 'http://neo4j.com/docs/operations-manual/current'
GITHUB = ENV['GITHUB'] || 'https://github.com/neo4j-contrib/developer/tree/gh-pages'
ASCIIDOC_ATTRIBUTES = %W(allow-uri-read
icons=font
linkattrs
source-highlighter=codemirror
img=#{IMAGE_BASE_URL}
examples=#{EXAMPLES}
manual=#{MANUAL}
opsmanual=#{OPSMANUAL}
github=#{GITHUB})
raise 'Usage: feed me asciidoctor files (or pass `all` to find all files)' if ARGV.empty?
adoc_file_paths = if ARGV == ['all']
`find . -mindepth 2 -maxdepth 4 -name "*.adoc"`.split(/[\n\r]+/)
else
ARGV
end
# AsciiPress.verify_adoc_slugs!(adoc_file_paths)
renderer = AsciiPress::Renderer.new( # after_conversion: HtmlTransformer.method(:transform),
asciidoc_options: {
attributes: ASCIIDOC_ATTRIBUTES,
header_footer: true,
safe: 0,
template_dir: ASCIIDOC_TEMPLATES_DIR,
})
adoc_file_paths.each do |adoc_file_path|
dir = File.join('deploy', File.dirname(adoc_file_path))
FileUtils.mkdir_p(dir)
html_file_path = File.join(dir, 'index.html')
LOGGER.info "Rendering #{adoc_file_path} to #{html_file_path}"
File.open(html_file_path, 'w') { |f| f << renderer.render(adoc_file_path).html }
end