inert 0.1.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/README.md +24 -0
- data/exe/inert +11 -0
- data/lib/inert.rb +22 -0
- data/lib/inert/builder.rb +62 -0
- data/lib/inert/middleware.rb +34 -0
- data/lib/inert/page.rb +29 -0
- metadata +110 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9fa03de85cd5a1d823843221a17b25ba4a48608c
|
4
|
+
data.tar.gz: 3d5c640a2cf87564991504c84435820016a6eaab
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e9c3978a0924899c9d3cb7f326d727a07364b0ca6814b07ea931f46a8ea3cfd5660bb537de3e8c2b5fe35ede51fca105aa06f6cc53da71eb129e9a1a6f3db1da
|
7
|
+
data.tar.gz: 3b57e1472757407d5a3b00725f7aedc1f089055eb674425c6e43a43449ab44d1dbb127fc2d4c06e2cbf3542502c53ead4ed227fdea6358a254d930262c1e4ac1
|
data/README.md
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# Inert
|
2
|
+
|
3
|
+
An experimental static site builder with unambitious goals.
|
4
|
+
|
5
|
+
## Project Goals
|
6
|
+
|
7
|
+
- Be fast
|
8
|
+
- Allow reading of YAML frontmatter
|
9
|
+
- Allow queueing of manual URLs for preservation
|
10
|
+
|
11
|
+
## Contributing
|
12
|
+
|
13
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/adam12/inert.
|
14
|
+
|
15
|
+
I love pull requests! If you fork this project and modify it, please ping me to see
|
16
|
+
if your changes can be incorporated back into this project.
|
17
|
+
|
18
|
+
That said, if your feature idea is nontrivial, you should probably open an issue to
|
19
|
+
[discuss it](http://www.igvita.com/2011/12/19/dont-push-your-pull-requests/)
|
20
|
+
before attempting a pull request.
|
21
|
+
|
22
|
+
## License
|
23
|
+
|
24
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/exe/inert
ADDED
data/lib/inert.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require_relative "inert/page"
|
3
|
+
require_relative "inert/builder"
|
4
|
+
require_relative "inert/middleware"
|
5
|
+
|
6
|
+
module Inert
|
7
|
+
module_function
|
8
|
+
|
9
|
+
def start
|
10
|
+
app = Inert::Middleware
|
11
|
+
|
12
|
+
if ENV["RACK_ENV"] != "production"
|
13
|
+
app = Rack::ShowExceptions.new(app)
|
14
|
+
end
|
15
|
+
|
16
|
+
Rack::Server.start(app: app)
|
17
|
+
end
|
18
|
+
|
19
|
+
def build
|
20
|
+
Inert::Builder.new(Inert::Middleware).call("/")
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "fileutils"
|
3
|
+
require "set"
|
4
|
+
require "oga"
|
5
|
+
|
6
|
+
module Inert
|
7
|
+
class Builder
|
8
|
+
attr_accessor :app, :build_path
|
9
|
+
attr_reader :queue, :history
|
10
|
+
|
11
|
+
def initialize(app)
|
12
|
+
@app = app
|
13
|
+
@queue = []
|
14
|
+
@history = Set.new
|
15
|
+
@build_path = "./build"
|
16
|
+
end
|
17
|
+
|
18
|
+
def call(starting_url)
|
19
|
+
save(starting_url)
|
20
|
+
|
21
|
+
while (url = queue.pop)
|
22
|
+
next if history.include?(url) || url == "#"
|
23
|
+
|
24
|
+
save(url)
|
25
|
+
history.add(url)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def save(url)
|
30
|
+
warn "Saving #{url}"
|
31
|
+
request = Rack::MockRequest.new(app)
|
32
|
+
|
33
|
+
dest = url.dup
|
34
|
+
dest << "index.html" if dest.end_with?("/")
|
35
|
+
dest << ".html" unless dest =~ /\.\w+$/
|
36
|
+
dest = File.expand_path(dest[1..-1], build_path)
|
37
|
+
|
38
|
+
FileUtils.mkdir_p(File.dirname(dest))
|
39
|
+
|
40
|
+
response = request.get(url)
|
41
|
+
return unless response.ok?
|
42
|
+
|
43
|
+
File.write(dest, response.body)
|
44
|
+
return unless response.content_type == "text/html"
|
45
|
+
|
46
|
+
html = Oga.parse_html(response.body)
|
47
|
+
html.css("[href], [src]").each do |el|
|
48
|
+
url = (el.get("href") || el.get("src"))
|
49
|
+
|
50
|
+
next if url =~ /\Ahttps?/
|
51
|
+
|
52
|
+
queue.push(url)
|
53
|
+
end
|
54
|
+
|
55
|
+
html.css("[style*='url']").each do |el|
|
56
|
+
el.get("style").match(/url\(['"]?([^'"]+)['"]?\)/) do |m|
|
57
|
+
queue.push(m[1])
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "roda"
|
3
|
+
|
4
|
+
module Inert
|
5
|
+
class Middleware < Roda
|
6
|
+
plugin :render, cache: ENV["RACK_ENV"] == "production"
|
7
|
+
plugin :partials
|
8
|
+
plugin :public, root: "static"
|
9
|
+
|
10
|
+
attr_reader :page
|
11
|
+
|
12
|
+
route do |r|
|
13
|
+
r.public
|
14
|
+
|
15
|
+
view_file = r.remaining_path.dup
|
16
|
+
view_file << "index.html" if view_file.end_with?("/")
|
17
|
+
|
18
|
+
begin
|
19
|
+
page = Page.load_from_file("./views#{view_file}.erb")
|
20
|
+
rescue Errno::ENOENT
|
21
|
+
r.halt([404, {}, ["Not found"]])
|
22
|
+
end
|
23
|
+
|
24
|
+
@page = page.frontmatter
|
25
|
+
|
26
|
+
view(inline: page.body, layout: page.layout)
|
27
|
+
end
|
28
|
+
|
29
|
+
def inline(file)
|
30
|
+
File.read("./views/#{file}")
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
data/lib/inert/page.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "yaml"
|
3
|
+
require "ostruct"
|
4
|
+
|
5
|
+
module Inert
|
6
|
+
class Page
|
7
|
+
attr_reader :body, :frontmatter, :layout
|
8
|
+
|
9
|
+
def initialize(body: "", frontmatter: {})
|
10
|
+
@body = body
|
11
|
+
@frontmatter = frontmatter
|
12
|
+
@layout = @frontmatter.delete(:layout) || "layout"
|
13
|
+
|
14
|
+
@frontmatter = OpenStruct.new(@frontmatter)
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.load_from_file(filename)
|
18
|
+
body = File.read(filename)
|
19
|
+
frontmatter = {}
|
20
|
+
|
21
|
+
body = body.gsub(/---(.*)---/m) do |m|
|
22
|
+
frontmatter = YAML.load($1)
|
23
|
+
""
|
24
|
+
end.lstrip
|
25
|
+
|
26
|
+
new(body: body, frontmatter: frontmatter)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: inert
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Adam Daniels
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-11-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: roda
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '4.0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '2.0'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '4.0'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: tilt
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '2.0'
|
40
|
+
- - "<"
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '4.0'
|
43
|
+
type: :runtime
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '2.0'
|
50
|
+
- - "<"
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '4.0'
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: oga
|
55
|
+
requirement: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '2.0'
|
60
|
+
- - "<"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '4.0'
|
63
|
+
type: :runtime
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '2.0'
|
70
|
+
- - "<"
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '4.0'
|
73
|
+
description:
|
74
|
+
email: adam@mediadrive.ca
|
75
|
+
executables:
|
76
|
+
- inert
|
77
|
+
extensions: []
|
78
|
+
extra_rdoc_files: []
|
79
|
+
files:
|
80
|
+
- README.md
|
81
|
+
- exe/inert
|
82
|
+
- lib/inert.rb
|
83
|
+
- lib/inert/builder.rb
|
84
|
+
- lib/inert/middleware.rb
|
85
|
+
- lib/inert/page.rb
|
86
|
+
homepage: https://github.com/adam12/inert
|
87
|
+
licenses:
|
88
|
+
- MIT
|
89
|
+
metadata: {}
|
90
|
+
post_install_message:
|
91
|
+
rdoc_options: []
|
92
|
+
require_paths:
|
93
|
+
- lib
|
94
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
requirements: []
|
105
|
+
rubyforge_project:
|
106
|
+
rubygems_version: 2.5.2
|
107
|
+
signing_key:
|
108
|
+
specification_version: 4
|
109
|
+
summary: An experimental static site builder with unambitious goals
|
110
|
+
test_files: []
|