headless2static 1.0.0
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 +7 -0
- data/bin/headless2static +69 -0
- metadata +45 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b224a90f86423a1b8ed6e35d96ee580332c11559dad435bfd0251b1f5370acaa
|
4
|
+
data.tar.gz: b6c105279949be4f344d70c33abc818ade68f5b73d0c30a80bba88257f57d469
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6aa71797025e7213445b855acf75e367a08b6609a5f830a202826057af4de12b11671a113c1bf9518bf6d6885ff4a59ea85aaa77f1abf736b413ce8bdea9002e
|
7
|
+
data.tar.gz: e3483ed47982493be892ffb9e3528b797f371cadcbca5cc352335f026515415bee29b01d03d905c88c1002194a653892b5e50ed0d21d508eed45de37fe77d7aa
|
data/bin/headless2static
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
#!/usr/bin/env ruby2.7
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
require 'liquid'
|
5
|
+
require 'jekyll' # register Jekyll's Liquid filters
|
6
|
+
require 'open-uri'
|
7
|
+
require 'json'
|
8
|
+
|
9
|
+
$options = {:"output-directory" => '.'}
|
10
|
+
|
11
|
+
parser = OptionParser.new do |opt|
|
12
|
+
opt.banner = "usage: headless2static [options] template_file url"
|
13
|
+
opt.on("-o DIR", "--output-directory=DIR", "directory in which the output files are saved")
|
14
|
+
opt.on("-f", "--force", "overwrite existing files")
|
15
|
+
end
|
16
|
+
|
17
|
+
parser.parse!(into: $options)
|
18
|
+
if not ARGV.length() == 2
|
19
|
+
puts "missing argument"
|
20
|
+
puts parser.help()
|
21
|
+
exit
|
22
|
+
end
|
23
|
+
|
24
|
+
$output_directory = $options[:"output-directory"].sub(/\/$/, '')
|
25
|
+
if not File.directory?($output_directory)
|
26
|
+
puts "output directory '#{$output_directory}' is not a directory"
|
27
|
+
exit
|
28
|
+
end
|
29
|
+
|
30
|
+
# this is the file name of the template
|
31
|
+
$template_file_name = ARGV.shift
|
32
|
+
if not File.file?($template_file_name)
|
33
|
+
puts "template file '#{$template_file_name}' is not a file"
|
34
|
+
exit
|
35
|
+
end
|
36
|
+
|
37
|
+
# this is the template for the file names
|
38
|
+
$file_name_template = Liquid::Template.parse(File.basename($template_file_name))
|
39
|
+
|
40
|
+
open($template_file_name) do |file|
|
41
|
+
$content_template = Liquid::Template.parse(file.read)
|
42
|
+
end
|
43
|
+
|
44
|
+
$url = ARGV.shift
|
45
|
+
|
46
|
+
URI.open($url) do |io|
|
47
|
+
json_result = JSON.parse(io.read)
|
48
|
+
if json_result.is_a?(Array)
|
49
|
+
data_array = json_result
|
50
|
+
elsif json_result.key?('data') and json_result['data'].is_a?(Array)
|
51
|
+
data_array = json_result['data']
|
52
|
+
else
|
53
|
+
data_array = [json_result]
|
54
|
+
end
|
55
|
+
for item in data_array do
|
56
|
+
file_name = $file_name_template.render(item)
|
57
|
+
|
58
|
+
output_path = "#{$output_directory}/#{file_name}"
|
59
|
+
|
60
|
+
if File.exist?(output_path) and not $options[:force] then
|
61
|
+
puts "#{output_path} exists, skipping..."
|
62
|
+
next
|
63
|
+
end
|
64
|
+
|
65
|
+
puts "generating #{output_path}..."
|
66
|
+
content = $content_template.render(item)
|
67
|
+
File.write(output_path, content)
|
68
|
+
end
|
69
|
+
end
|
metadata
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: headless2static
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jan Weil
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-08-24 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: headless2static generates static files from REST resource lists using
|
14
|
+
a Liquid template.
|
15
|
+
email: jan.weil@web.de
|
16
|
+
executables:
|
17
|
+
- headless2static
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- bin/headless2static
|
22
|
+
homepage: https://jawebada.github.io/headless2static/
|
23
|
+
licenses:
|
24
|
+
- MIT
|
25
|
+
metadata: {}
|
26
|
+
post_install_message:
|
27
|
+
rdoc_options: []
|
28
|
+
require_paths:
|
29
|
+
- lib
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
requirements: []
|
41
|
+
rubygems_version: 3.1.2
|
42
|
+
signing_key:
|
43
|
+
specification_version: 4
|
44
|
+
summary: the missing link between headless CMSs and static site generators
|
45
|
+
test_files: []
|