lifer 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/main.yml +2 -1
- data/.gitignore +7 -5
- data/Gemfile.lock +12 -2
- data/lib/lifer/builder/html.rb +30 -18
- data/lib/lifer/entry.rb +28 -6
- data/lib/lifer/uri_strategy/base.rb +4 -8
- data/lib/lifer/uri_strategy/pretty.rb +13 -0
- data/lib/lifer/uri_strategy/simple.rb +7 -17
- data/lib/lifer/uri_strategy.rb +10 -1
- data/lifer.gemspec +4 -2
- metadata +19 -5
- data/.rspec +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c5891938dbf0269f6cf30b14cd14130025b2214e0b03b6c756d48efa1abf8ae3
|
4
|
+
data.tar.gz: a6bb29832ac1e2ccde939d17f6c84643c5d8f3544d0cda7f407a696d642836e7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6cd12ec2588d1afc192352219a98e04672ce721069160bc5b3f0db5e2c91998a156318d30ee7a3299d062f32127b0cf9cc9d7eea7ece320212627c3e27344d91
|
7
|
+
data.tar.gz: 1506e4a3bf8957dce6dbacccf25d75a52edf710c886a8955b979dede89b698dfc8f0a8dd1571fa6275ad8737ad0cdc2e9897503b16bb848bcaef2027ddfb8fcf
|
data/.github/workflows/main.yml
CHANGED
@@ -4,13 +4,14 @@ on: [push,pull_request]
|
|
4
4
|
|
5
5
|
jobs:
|
6
6
|
build:
|
7
|
+
name: Run RSpec test suite
|
7
8
|
runs-on: ubuntu-latest
|
8
9
|
steps:
|
9
10
|
- uses: actions/checkout@v2
|
10
11
|
- name: Set up Ruby
|
11
12
|
uses: ruby/setup-ruby@v1
|
12
13
|
with:
|
13
|
-
ruby-version: 3.
|
14
|
+
ruby-version: 3.1.2
|
14
15
|
bundler-cache: true
|
15
16
|
- name: Run the default task
|
16
17
|
run: bundle exec rake
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
@@ -7,10 +7,18 @@ PATH
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
+
debug (1.6.2)
|
11
|
+
irb (>= 1.3.6)
|
12
|
+
reline (>= 0.3.1)
|
10
13
|
diff-lcs (1.5.0)
|
14
|
+
io-console (0.5.11)
|
15
|
+
irb (1.4.1)
|
16
|
+
reline (>= 0.3.0)
|
11
17
|
kramdown (2.4.0)
|
12
18
|
rexml
|
13
19
|
rake (13.0.6)
|
20
|
+
reline (0.3.1)
|
21
|
+
io-console (~> 0.5)
|
14
22
|
rexml (3.2.5)
|
15
23
|
rspec (3.11.0)
|
16
24
|
rspec-core (~> 3.11.0)
|
@@ -27,12 +35,14 @@ GEM
|
|
27
35
|
rspec-support (3.11.0)
|
28
36
|
|
29
37
|
PLATFORMS
|
30
|
-
x86_64-darwin-
|
38
|
+
x86_64-darwin-21
|
39
|
+
x86_64-linux
|
31
40
|
|
32
41
|
DEPENDENCIES
|
42
|
+
debug
|
33
43
|
lifer!
|
34
44
|
rake (~> 13.0)
|
35
45
|
rspec (~> 3.0)
|
36
46
|
|
37
47
|
BUNDLED WITH
|
38
|
-
2.
|
48
|
+
2.3.21
|
data/lib/lifer/builder/html.rb
CHANGED
@@ -1,11 +1,8 @@
|
|
1
1
|
require "fileutils"
|
2
2
|
|
3
|
-
# FIXME:
|
4
|
-
# This builder is not currently designed in a good way. Every builder should
|
5
|
-
# have an interface that lets us swap steps in and out in an easy way.
|
6
|
-
#
|
7
3
|
class Lifer::Builder::HTML
|
8
4
|
DEFAULT_OUTPUT_DIRECTORY_NAME = "_build"
|
5
|
+
FALLBACK_URI_STRATEGY = "simple"
|
9
6
|
|
10
7
|
class << self
|
11
8
|
def execute(root:)
|
@@ -15,21 +12,17 @@ class Lifer::Builder::HTML
|
|
15
12
|
|
16
13
|
def execute
|
17
14
|
# Remove any existing output directory.
|
15
|
+
#
|
18
16
|
FileUtils.rm_r(output_directory)
|
19
17
|
|
20
18
|
# Go into the fresh build directory and generate each HTML file from the
|
21
19
|
# given directory.
|
20
|
+
#
|
22
21
|
Dir.chdir(output_directory) do
|
23
22
|
Lifer.collections.each do |collection|
|
24
23
|
collection.entries.each do |entry|
|
25
|
-
|
26
|
-
|
27
|
-
File.open(uri_strategy.file_for(entry), "w") { |f|
|
28
|
-
f.write Lifer::Layout.build(
|
29
|
-
entry: entry,
|
30
|
-
template: layout_for(collection)
|
31
|
-
)
|
32
|
-
}
|
24
|
+
generate_output_directories_for entry, current_collection: collection
|
25
|
+
generate_output_file_for entry, current_collection: collection
|
33
26
|
end
|
34
27
|
end
|
35
28
|
end
|
@@ -37,18 +30,27 @@ class Lifer::Builder::HTML
|
|
37
30
|
|
38
31
|
private
|
39
32
|
|
40
|
-
attr_reader :root
|
33
|
+
attr_reader :root
|
41
34
|
|
42
35
|
def initialize(root:)
|
43
36
|
@root = root
|
44
|
-
@uri_strategy = Lifer::URIStrategy::Simple.new(directory: root)
|
45
37
|
end
|
46
38
|
|
47
|
-
def
|
48
|
-
|
49
|
-
|
39
|
+
def generate_output_directories_for(entry, current_collection:)
|
40
|
+
dirname =
|
41
|
+
Pathname File.dirname(uri_strategy(current_collection).output_file(entry))
|
42
|
+
FileUtils.mkdir_p dirname unless Dir.exist?(dirname)
|
43
|
+
end
|
50
44
|
|
51
|
-
|
45
|
+
def generate_output_file_for(entry, current_collection:)
|
46
|
+
File.open(uri_strategy(current_collection).output_file(entry), "w") { |file|
|
47
|
+
file.write(
|
48
|
+
Lifer::Layout.build(
|
49
|
+
entry: entry,
|
50
|
+
template: layout_for(current_collection)
|
51
|
+
)
|
52
|
+
)
|
53
|
+
}
|
52
54
|
end
|
53
55
|
|
54
56
|
def layout_for(collection)
|
@@ -70,4 +72,14 @@ class Lifer::Builder::HTML
|
|
70
72
|
Dir.mkdir(dir)
|
71
73
|
Pathname(dir)
|
72
74
|
end
|
75
|
+
|
76
|
+
def uri_strategy(current_collection)
|
77
|
+
collection_settings =
|
78
|
+
Lifer.settings[current_collection.name] || Lifer.settings[:root]
|
79
|
+
current_uri_strategy =
|
80
|
+
collection_settings && collection_settings[:uri_strategy] ||
|
81
|
+
FALLBACK_URI_STRATEGY
|
82
|
+
|
83
|
+
Lifer::URIStrategy.find_by_name(current_uri_strategy).new(root: root)
|
84
|
+
end
|
73
85
|
end
|
data/lib/lifer/entry.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
|
+
require "date"
|
1
2
|
require "kramdown"
|
3
|
+
require "time"
|
2
4
|
|
3
5
|
require_relative "utilities"
|
4
6
|
|
5
7
|
class Lifer::Entry
|
8
|
+
FILENAME_DATE_FORMAT = /^(\d{4}-\d{1,2}-\d{1,2})-/
|
6
9
|
FRONTMATTER_REGEX = /^---\n(.*)---\n/m
|
7
10
|
|
8
11
|
attr_reader :file
|
@@ -17,18 +20,31 @@ class Lifer::Entry
|
|
17
20
|
full_text.gsub(FRONTMATTER_REGEX, "").strip
|
18
21
|
end
|
19
22
|
|
23
|
+
def date
|
24
|
+
date_data = frontmatter[:date] || filename_date
|
25
|
+
|
26
|
+
case date_data
|
27
|
+
when Time then date_data
|
28
|
+
when String then DateTime.parse(date_data).to_time
|
29
|
+
else
|
30
|
+
puts "[%s]: no date metadata" % [file]
|
31
|
+
nil
|
32
|
+
end
|
33
|
+
rescue ArgumentError => error
|
34
|
+
puts "[%s]: %s" % [file, error]
|
35
|
+
nil
|
36
|
+
end
|
37
|
+
|
20
38
|
def frontmatter
|
21
|
-
return
|
39
|
+
return {} unless frontmatter?
|
22
40
|
|
23
41
|
Lifer::Utilities.symbolize_keys(
|
24
|
-
YAML.load
|
42
|
+
YAML.load(full_text[FRONTMATTER_REGEX, 1], permitted_classes: [Time])
|
25
43
|
)
|
26
44
|
end
|
27
45
|
|
28
46
|
def full_text
|
29
|
-
|
30
|
-
|
31
|
-
File.readlines(file).join
|
47
|
+
File.readlines(file).join if file
|
32
48
|
end
|
33
49
|
|
34
50
|
def to_html
|
@@ -37,7 +53,13 @@ class Lifer::Entry
|
|
37
53
|
|
38
54
|
private
|
39
55
|
|
56
|
+
def filename_date
|
57
|
+
return unless file && File.basename(file).match?(FILENAME_DATE_FORMAT)
|
58
|
+
|
59
|
+
File.basename(file).match(FILENAME_DATE_FORMAT)[1]
|
60
|
+
end
|
61
|
+
|
40
62
|
def frontmatter?
|
41
|
-
full_text.match?
|
63
|
+
full_text && full_text.match?(FRONTMATTER_REGEX)
|
42
64
|
end
|
43
65
|
end
|
@@ -1,19 +1,15 @@
|
|
1
1
|
class Lifer::URIStrategy::Base
|
2
|
-
attr_reader :
|
2
|
+
attr_reader :root
|
3
3
|
|
4
|
-
def initialize(
|
5
|
-
@
|
4
|
+
def initialize(root:)
|
5
|
+
@root = root
|
6
6
|
end
|
7
7
|
|
8
8
|
def name
|
9
9
|
raise NotImplementedError, "implement on a subclass"
|
10
10
|
end
|
11
11
|
|
12
|
-
def
|
13
|
-
raise NotImplementedError, "implement on a subclass"
|
14
|
-
end
|
15
|
-
|
16
|
-
def file_for(entry)
|
12
|
+
def output_file(entry)
|
17
13
|
raise NotImplementedError, "implement on a subclass"
|
18
14
|
end
|
19
15
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class Lifer::URIStrategy::Pretty < Lifer::URIStrategy::Base
|
2
|
+
def name
|
3
|
+
"pretty"
|
4
|
+
end
|
5
|
+
|
6
|
+
def output_file(entry)
|
7
|
+
basename = File.basename(entry.file, ".*")
|
8
|
+
|
9
|
+
Pathname entry.file.to_s
|
10
|
+
.gsub(/#{root}[\/]{0,1}/, "")
|
11
|
+
.gsub(/#{basename}(\..+)/, "#{basename}/index.html")
|
12
|
+
end
|
13
|
+
end
|
@@ -1,23 +1,13 @@
|
|
1
1
|
class Lifer::URIStrategy::Simple < Lifer::URIStrategy::Base
|
2
|
-
def
|
3
|
-
|
2
|
+
def name
|
3
|
+
"simple"
|
4
4
|
end
|
5
5
|
|
6
|
-
def
|
7
|
-
|
6
|
+
def output_file(entry)
|
7
|
+
basename = File.basename(entry.file, ".*")
|
8
8
|
|
9
|
-
Pathname entry.file.
|
10
|
-
/#{
|
11
|
-
""
|
12
|
-
)
|
13
|
-
end
|
14
|
-
|
15
|
-
def file_for(entry)
|
16
|
-
Pathname(
|
17
|
-
[
|
18
|
-
dirname_for(entry),
|
19
|
-
("%s.html" % name_for(entry))
|
20
|
-
].compact.join("/")
|
21
|
-
)
|
9
|
+
Pathname entry.file.to_s
|
10
|
+
.gsub(/#{root}[\/]{0,1}/, "")
|
11
|
+
.gsub(/#{basename}(\..+)/, "#{basename}.html")
|
22
12
|
end
|
23
13
|
end
|
data/lib/lifer/uri_strategy.rb
CHANGED
@@ -1,4 +1,13 @@
|
|
1
|
-
|
1
|
+
class Lifer::URIStrategy
|
2
|
+
class << self
|
3
|
+
def find_by_name(name)
|
4
|
+
self.const_get name.capitalize
|
5
|
+
rescue NameError => error
|
6
|
+
raise StandardError, "no URI strategy '#{name}'"
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
2
10
|
|
3
11
|
require_relative "uri_strategy/base"
|
12
|
+
require_relative "uri_strategy/pretty"
|
4
13
|
require_relative "uri_strategy/simple"
|
data/lifer.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Lifer
|
4
|
-
VERSION = "0.
|
4
|
+
VERSION = "0.2.0"
|
5
5
|
end
|
6
6
|
|
7
7
|
Gem::Specification.new do |spec|
|
@@ -13,7 +13,7 @@ Gem::Specification.new do |spec|
|
|
13
13
|
spec.summary = "Minimal static weblog generator."
|
14
14
|
spec.description = "Minimal static weblog generator. Good RSS feeds."
|
15
15
|
spec.homepage = "https://github.com/benjaminwil/lifer"
|
16
|
-
spec.required_ruby_version = ">=
|
16
|
+
spec.required_ruby_version = ">= 3.1"
|
17
17
|
|
18
18
|
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
19
19
|
|
@@ -35,4 +35,6 @@ Gem::Specification.new do |spec|
|
|
35
35
|
spec.require_paths = ["lib"]
|
36
36
|
|
37
37
|
spec.add_dependency "kramdown", "~> 2.4"
|
38
|
+
|
39
|
+
spec.add_development_dependency "debug"
|
38
40
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lifer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- benjamin wil
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-07
|
11
|
+
date: 2022-09-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: kramdown
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '2.4'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: debug
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
description: Minimal static weblog generator. Good RSS feeds.
|
28
42
|
email:
|
29
43
|
- benjamin@super.gd
|
@@ -33,7 +47,6 @@ extra_rdoc_files: []
|
|
33
47
|
files:
|
34
48
|
- ".github/workflows/main.yml"
|
35
49
|
- ".gitignore"
|
36
|
-
- ".rspec"
|
37
50
|
- Gemfile
|
38
51
|
- Gemfile.lock
|
39
52
|
- README.md
|
@@ -53,6 +66,7 @@ files:
|
|
53
66
|
- lib/lifer/templates/layout.html.erb
|
54
67
|
- lib/lifer/uri_strategy.rb
|
55
68
|
- lib/lifer/uri_strategy/base.rb
|
69
|
+
- lib/lifer/uri_strategy/pretty.rb
|
56
70
|
- lib/lifer/uri_strategy/simple.rb
|
57
71
|
- lib/lifer/utilities.rb
|
58
72
|
- lifer.gemspec
|
@@ -71,14 +85,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
71
85
|
requirements:
|
72
86
|
- - ">="
|
73
87
|
- !ruby/object:Gem::Version
|
74
|
-
version:
|
88
|
+
version: '3.1'
|
75
89
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
90
|
requirements:
|
77
91
|
- - ">="
|
78
92
|
- !ruby/object:Gem::Version
|
79
93
|
version: '0'
|
80
94
|
requirements: []
|
81
|
-
rubygems_version: 3.
|
95
|
+
rubygems_version: 3.3.7
|
82
96
|
signing_key:
|
83
97
|
specification_version: 4
|
84
98
|
summary: Minimal static weblog generator.
|
data/.rspec
DELETED