bridgetown-core 0.21.5 → 1.0.0.alpha1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/bridgetown +2 -0
- data/bridgetown-core.gemspec +3 -0
- data/lib/bridgetown-core/cleaner.rb +0 -8
- data/lib/bridgetown-core/collection.rb +59 -81
- data/lib/bridgetown-core/commands/base.rb +60 -1
- data/lib/bridgetown-core/commands/build.rb +26 -6
- data/lib/bridgetown-core/commands/concerns/build_options.rb +3 -10
- data/lib/bridgetown-core/commands/concerns/configuration_overridable.rb +3 -1
- data/lib/bridgetown-core/commands/doctor.rb +3 -3
- data/lib/bridgetown-core/commands/new.rb +9 -3
- data/lib/bridgetown-core/commands/plugins.rb +1 -2
- data/lib/bridgetown-core/commands/serve.rb +14 -12
- data/lib/bridgetown-core/commands/start.rb +106 -0
- data/lib/bridgetown-core/commands/webpack/webpack.defaults.js.erb +2 -2
- data/lib/bridgetown-core/concerns/site/configurable.rb +0 -12
- data/lib/bridgetown-core/concerns/site/content.rb +6 -117
- data/lib/bridgetown-core/concerns/site/localizable.rb +3 -1
- data/lib/bridgetown-core/concerns/site/processable.rb +8 -20
- data/lib/bridgetown-core/concerns/site/renderable.rb +19 -30
- data/lib/bridgetown-core/concerns/site/ssr.rb +53 -0
- data/lib/bridgetown-core/concerns/site/writable.rb +5 -8
- data/lib/bridgetown-core/configuration.rb +18 -47
- data/lib/bridgetown-core/configurations/minitesting.rb +1 -1
- data/lib/bridgetown-core/configurations/turbo.rb +1 -1
- data/lib/bridgetown-core/converters/erb_templates.rb +2 -1
- data/lib/bridgetown-core/converters/liquid_templates.rb +3 -2
- data/lib/bridgetown-core/current.rb +4 -0
- data/lib/bridgetown-core/drops/collection_drop.rb +1 -1
- data/lib/bridgetown-core/drops/generated_page_drop.rb +23 -0
- data/lib/bridgetown-core/drops/resource_drop.rb +3 -3
- data/lib/bridgetown-core/drops/site_drop.rb +3 -47
- data/lib/bridgetown-core/filters/url_filters.rb +3 -1
- data/lib/bridgetown-core/frontmatter_defaults.rb +44 -80
- data/lib/bridgetown-core/{page.rb → generated_page.rb} +34 -58
- data/lib/bridgetown-core/generators/prototype_generator.rb +10 -21
- data/lib/bridgetown-core/helpers.rb +7 -2
- data/lib/bridgetown-core/layout.rb +15 -4
- data/lib/bridgetown-core/log_writer.rb +6 -0
- data/lib/bridgetown-core/model/base.rb +10 -2
- data/lib/bridgetown-core/model/builder_origin.rb +22 -10
- data/lib/bridgetown-core/model/origin.rb +3 -0
- data/lib/bridgetown-core/model/plugin_origin.rb +34 -0
- data/lib/bridgetown-core/model/repo_origin.rb +1 -1
- data/lib/bridgetown-core/plugin_manager.rb +0 -2
- data/lib/bridgetown-core/rack/boot.rb +47 -0
- data/lib/bridgetown-core/rack/logger.rb +22 -0
- data/lib/bridgetown-core/rack/roda.rb +66 -0
- data/lib/bridgetown-core/rack/routes.rb +92 -0
- data/lib/bridgetown-core/rack/static_indexes.rb +30 -0
- data/lib/bridgetown-core/reader.rb +16 -48
- data/lib/bridgetown-core/readers/plugin_content_reader.rb +8 -7
- data/lib/bridgetown-core/renderer.rb +1 -11
- data/lib/bridgetown-core/resource/base.rb +33 -10
- data/lib/bridgetown-core/resource/permalink_processor.rb +20 -10
- data/lib/bridgetown-core/resource/relations.rb +2 -3
- data/lib/bridgetown-core/resource/transformer.rb +1 -1
- data/lib/bridgetown-core/ruby_template_view.rb +5 -5
- data/lib/bridgetown-core/site.rb +4 -8
- data/lib/bridgetown-core/static_file.rb +10 -15
- data/lib/bridgetown-core/tags/include.rb +0 -13
- data/lib/bridgetown-core/tags/link.rb +4 -0
- data/lib/bridgetown-core/tags/live_reload_dev_js.rb +13 -0
- data/lib/bridgetown-core/tags/post_url.rb +4 -9
- data/lib/bridgetown-core/tasks/bridgetown_tasks.rake +54 -0
- data/lib/bridgetown-core/url.rb +2 -1
- data/lib/bridgetown-core/utils/aux.rb +57 -0
- data/lib/bridgetown-core/utils/ruby_exec.rb +3 -45
- data/lib/bridgetown-core/utils/ruby_front_matter.rb +22 -7
- data/lib/bridgetown-core/utils.rb +37 -2
- data/lib/bridgetown-core/version.rb +2 -2
- data/lib/bridgetown-core/watcher.rb +2 -4
- data/lib/bridgetown-core.rb +14 -22
- data/lib/site_template/Gemfile.erb +6 -2
- data/lib/site_template/README.md +6 -6
- data/lib/site_template/Rakefile +49 -0
- data/lib/site_template/bridgetown.config.yml +2 -3
- data/lib/site_template/config/puma.rb +27 -0
- data/lib/site_template/config.ru +7 -0
- data/lib/site_template/package.json.erb +1 -9
- data/lib/site_template/server/roda_app.rb +22 -0
- data/lib/site_template/server/routes/hello.rb.sample +10 -0
- data/lib/site_template/src/_components/head.liquid +2 -1
- data/lib/site_template/src/about.md +0 -1
- data/lib/site_template/src/posts.md +2 -3
- metadata +62 -18
- data/lib/bridgetown-core/concerns/data_accessible.rb +0 -20
- data/lib/bridgetown-core/concerns/validatable.rb +0 -56
- data/lib/bridgetown-core/document.rb +0 -437
- data/lib/bridgetown-core/drops/document_drop.rb +0 -80
- data/lib/bridgetown-core/drops/excerpt_drop.rb +0 -19
- data/lib/bridgetown-core/drops/page_drop.rb +0 -18
- data/lib/bridgetown-core/excerpt.rb +0 -200
- data/lib/bridgetown-core/readers/data_reader.rb +0 -89
- data/lib/bridgetown-core/readers/page_reader.rb +0 -26
- data/lib/bridgetown-core/readers/post_reader.rb +0 -109
- data/lib/bridgetown-core/regenerator.rb +0 -202
- data/lib/bridgetown-core/related_posts.rb +0 -55
- data/lib/site_template/config/.keep +0 -0
- data/lib/site_template/start.js +0 -17
- data/lib/site_template/sync.js +0 -35
@@ -1,202 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Bridgetown
|
4
|
-
class Regenerator
|
5
|
-
attr_reader :site, :metadata, :cache
|
6
|
-
attr_accessor :disabled
|
7
|
-
private :disabled, :disabled=
|
8
|
-
|
9
|
-
def initialize(site)
|
10
|
-
@site = site
|
11
|
-
|
12
|
-
# Read metadata from file
|
13
|
-
read_metadata
|
14
|
-
|
15
|
-
# Initialize cache to an empty hash
|
16
|
-
clear_cache
|
17
|
-
end
|
18
|
-
|
19
|
-
# Checks if a renderable object needs to be regenerated
|
20
|
-
#
|
21
|
-
# Returns a boolean.
|
22
|
-
def regenerate?(document) # rubocop:todo Metrics/CyclomaticComplexity
|
23
|
-
return true if disabled
|
24
|
-
|
25
|
-
case document
|
26
|
-
when Page
|
27
|
-
regenerate_page?(document)
|
28
|
-
when Document
|
29
|
-
regenerate_document?(document)
|
30
|
-
when Bridgetown::Resource::Base
|
31
|
-
regenerate_resource?(document)
|
32
|
-
else
|
33
|
-
source_path = document.respond_to?(:path) ? document.path : nil
|
34
|
-
dest_path = document.destination(@site.dest) if document.respond_to?(:destination)
|
35
|
-
source_modified_or_dest_missing?(source_path, dest_path)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
# Add a path to the metadata
|
40
|
-
#
|
41
|
-
# Returns true, also on failure.
|
42
|
-
def add(path)
|
43
|
-
return true unless File.exist?(path)
|
44
|
-
|
45
|
-
metadata[path] = {
|
46
|
-
"mtime" => File.mtime(path),
|
47
|
-
"deps" => [],
|
48
|
-
}
|
49
|
-
cache[path] = true
|
50
|
-
end
|
51
|
-
|
52
|
-
# Force a path to regenerate
|
53
|
-
#
|
54
|
-
# Returns true.
|
55
|
-
def force(path)
|
56
|
-
cache[path] = true
|
57
|
-
end
|
58
|
-
|
59
|
-
# Clear the metadata and cache
|
60
|
-
#
|
61
|
-
# Returns nothing
|
62
|
-
def clear
|
63
|
-
@metadata = {}
|
64
|
-
clear_cache
|
65
|
-
end
|
66
|
-
|
67
|
-
# Clear just the cache
|
68
|
-
#
|
69
|
-
# Returns nothing
|
70
|
-
def clear_cache
|
71
|
-
@cache = {}
|
72
|
-
end
|
73
|
-
|
74
|
-
# Checks if the source has been modified or the
|
75
|
-
# destination is missing
|
76
|
-
#
|
77
|
-
# returns a boolean
|
78
|
-
def source_modified_or_dest_missing?(source_path, dest_path)
|
79
|
-
modified?(source_path) || (dest_path && !File.exist?(dest_path))
|
80
|
-
end
|
81
|
-
|
82
|
-
# Checks if a path's (or one of its dependencies)
|
83
|
-
# mtime has changed
|
84
|
-
#
|
85
|
-
# Returns a boolean.
|
86
|
-
def modified?(path)
|
87
|
-
return true if disabled?
|
88
|
-
|
89
|
-
# objects that don't have a path are always regenerated
|
90
|
-
return true if path.nil?
|
91
|
-
|
92
|
-
# Check for path in cache
|
93
|
-
return cache[path] if cache.key? path
|
94
|
-
|
95
|
-
if metadata[path]
|
96
|
-
# If we have seen this file before,
|
97
|
-
# check if it or one of its dependencies has been modified
|
98
|
-
existing_file_modified?(path)
|
99
|
-
else
|
100
|
-
# If we have not seen this file before, add it to the metadata and regenerate it
|
101
|
-
add(path)
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
# Add a dependency of a path
|
106
|
-
#
|
107
|
-
# Returns nothing.
|
108
|
-
def add_dependency(path, dependency)
|
109
|
-
return if metadata[path].nil? || disabled
|
110
|
-
|
111
|
-
unless metadata[path]["deps"].include? dependency
|
112
|
-
metadata[path]["deps"] << dependency
|
113
|
-
add(dependency) unless metadata.include?(dependency)
|
114
|
-
end
|
115
|
-
regenerate? dependency
|
116
|
-
end
|
117
|
-
|
118
|
-
# Write the metadata to disk
|
119
|
-
#
|
120
|
-
# Returns nothing.
|
121
|
-
def write_metadata
|
122
|
-
unless disabled?
|
123
|
-
Bridgetown.logger.debug "Writing Metadata:", ".bridgetown-metadata"
|
124
|
-
File.binwrite(metadata_file, Marshal.dump(metadata))
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
# Produce the absolute path of the metadata file
|
129
|
-
#
|
130
|
-
# Returns the String path of the file.
|
131
|
-
def metadata_file
|
132
|
-
@metadata_file ||= site.in_root_dir(".bridgetown-metadata")
|
133
|
-
end
|
134
|
-
|
135
|
-
# Check if metadata has been disabled
|
136
|
-
#
|
137
|
-
# Returns a Boolean (true for disabled, false for enabled).
|
138
|
-
def disabled?
|
139
|
-
self.disabled = !site.incremental? if disabled.nil?
|
140
|
-
disabled
|
141
|
-
end
|
142
|
-
|
143
|
-
private
|
144
|
-
|
145
|
-
# Read metadata from the metadata file, if no file is found,
|
146
|
-
# initialize with an empty hash
|
147
|
-
#
|
148
|
-
# Returns the read metadata.
|
149
|
-
def read_metadata
|
150
|
-
@metadata =
|
151
|
-
if !disabled? && File.file?(metadata_file)
|
152
|
-
content = File.binread(metadata_file)
|
153
|
-
|
154
|
-
begin
|
155
|
-
Marshal.load(content)
|
156
|
-
rescue TypeError
|
157
|
-
YAMLParser.load(content)
|
158
|
-
rescue ArgumentError => e
|
159
|
-
Bridgetown.logger.warn("Failed to load #{metadata_file}: #{e}")
|
160
|
-
{}
|
161
|
-
end
|
162
|
-
else
|
163
|
-
{}
|
164
|
-
end
|
165
|
-
end
|
166
|
-
|
167
|
-
def regenerate_page?(document)
|
168
|
-
document.data["regenerate"] ||
|
169
|
-
source_modified_or_dest_missing?(
|
170
|
-
site.in_source_dir(document.relative_path), document.destination(@site.dest)
|
171
|
-
)
|
172
|
-
end
|
173
|
-
|
174
|
-
def regenerate_document?(document)
|
175
|
-
!document.write? || document.data["regenerate"] ||
|
176
|
-
source_modified_or_dest_missing?(
|
177
|
-
document.path, document.destination(@site.dest)
|
178
|
-
)
|
179
|
-
end
|
180
|
-
|
181
|
-
# TODO: need to manage dependencies, but for now always regenerate
|
182
|
-
def regenerate_resource?(_resource)
|
183
|
-
true
|
184
|
-
end
|
185
|
-
|
186
|
-
def existing_file_modified?(path)
|
187
|
-
# If one of this file dependencies have been modified,
|
188
|
-
# set the regeneration bit for both the dependency and the file to true
|
189
|
-
metadata[path]["deps"].each do |dependency|
|
190
|
-
return cache[dependency] = cache[path] = true if modified?(dependency)
|
191
|
-
end
|
192
|
-
|
193
|
-
if File.exist?(path) && metadata[path]["mtime"].eql?(File.mtime(path))
|
194
|
-
# If this file has not been modified, set the regeneration bit to false
|
195
|
-
cache[path] = false
|
196
|
-
else
|
197
|
-
# If it has been modified, set it to true
|
198
|
-
add(path)
|
199
|
-
end
|
200
|
-
end
|
201
|
-
end
|
202
|
-
end
|
@@ -1,55 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Bridgetown
|
4
|
-
# TODO: to be retired once the Resource engine is made official
|
5
|
-
class RelatedPosts
|
6
|
-
class << self
|
7
|
-
attr_accessor :lsi
|
8
|
-
end
|
9
|
-
|
10
|
-
attr_reader :post, :site
|
11
|
-
|
12
|
-
def initialize(post)
|
13
|
-
@post = post
|
14
|
-
@site = post.site
|
15
|
-
if site.config.lsi
|
16
|
-
Bridgetown::Utils::RequireGems.require_with_graceful_fail("classifier-reborn")
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def build
|
21
|
-
return [] unless site.collections.posts.docs.size > 1
|
22
|
-
|
23
|
-
if site.config.lsi
|
24
|
-
build_index
|
25
|
-
lsi_related_posts
|
26
|
-
else
|
27
|
-
most_recent_posts
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def build_index
|
32
|
-
self.class.lsi ||= begin
|
33
|
-
lsi = ClassifierReborn::LSI.new(auto_rebuild: false)
|
34
|
-
Bridgetown.logger.info("Populating LSI...")
|
35
|
-
|
36
|
-
site.collections.posts.docs.each do |x|
|
37
|
-
lsi.add_item(x)
|
38
|
-
end
|
39
|
-
|
40
|
-
Bridgetown.logger.info("Rebuilding index...")
|
41
|
-
lsi.build_index
|
42
|
-
Bridgetown.logger.info("")
|
43
|
-
lsi
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
def lsi_related_posts
|
48
|
-
self.class.lsi.find_related(post, 11) - [post]
|
49
|
-
end
|
50
|
-
|
51
|
-
def most_recent_posts
|
52
|
-
@most_recent_posts ||= (site.collections.posts.docs.last(11).reverse - [post]).first(10)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
File without changes
|
data/lib/site_template/start.js
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
const concurrently = require('concurrently');
|
2
|
-
|
3
|
-
// By default, configure Bridgetown to use port 4001 so Browsersync can use 4000
|
4
|
-
// See also Browsersync settings in sync.js
|
5
|
-
const port = 4001
|
6
|
-
|
7
|
-
/////////////////
|
8
|
-
// Concurrently
|
9
|
-
/////////////////
|
10
|
-
concurrently([
|
11
|
-
{ command: "yarn webpack-dev", name: "Webpack", prefixColor: "yellow" },
|
12
|
-
{ command: "sleep 4; yarn serve --port " + port, name: "Bridgetown", prefixColor: "green" },
|
13
|
-
{ command: "sleep 8; yarn sync", name: "Live", prefixColor: "blue" }
|
14
|
-
], {
|
15
|
-
restartTries: 3,
|
16
|
-
killOthers: ['failure', 'success'],
|
17
|
-
}).then(() => { console.log("Done.");console.log('\033[0G'); }, () => {});
|
data/lib/site_template/sync.js
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
const browserSync = require("browser-sync").create();
|
2
|
-
|
3
|
-
// You can change these configuration values:
|
4
|
-
const proxy = "http://localhost:4001"
|
5
|
-
const port = 4000
|
6
|
-
const uiPort = 4002
|
7
|
-
|
8
|
-
////////////////
|
9
|
-
// Browsersync
|
10
|
-
////////////////
|
11
|
-
browserSync.init({
|
12
|
-
open: false,
|
13
|
-
notify: false,
|
14
|
-
proxy: proxy,
|
15
|
-
port: port,
|
16
|
-
files: "output/index.html",
|
17
|
-
ghostMode: {
|
18
|
-
clicks: false,
|
19
|
-
forms: false,
|
20
|
-
scroll: false,
|
21
|
-
},
|
22
|
-
reloadDelay: 0,
|
23
|
-
injectChanges: false,
|
24
|
-
ui: {
|
25
|
-
port: uiPort
|
26
|
-
},
|
27
|
-
snippetOptions: {
|
28
|
-
rule: {
|
29
|
-
match: /<\/head>/i,
|
30
|
-
fn: function (snippet, match) {
|
31
|
-
return snippet + match;
|
32
|
-
},
|
33
|
-
},
|
34
|
-
},
|
35
|
-
});
|