bridgetown-core 0.10.2 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/bridgetown-core/configuration.rb +1 -0
- data/lib/bridgetown-core/drops/url_drop.rb +5 -1
- data/lib/bridgetown-core/generators/prototype_generator.rb +126 -0
- data/lib/bridgetown-core/version.rb +1 -1
- data/lib/site_template/package.json +1 -0
- data/lib/site_template/webpack.config.js +9 -3
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 86af5c191c5ec6097a971ccbb66489d6d71effb8a48ffe19736a7ee8319fa672
|
4
|
+
data.tar.gz: 2d68656ef593e5d2ed3aa1e2a3b0f3de7e1e45e1ac29b439089e0d4419c61657
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: caf6380687cbab8f43986faf41b3c2ca42013e4d4157ffe714b6d89f4e81f8f1b51089636c6b6360b5033699a1f9f2cda5a46650f5686058d6c92efba81fff23
|
7
|
+
data.tar.gz: a8d429d08d30a12efe6138e8444954a7243606c1b29fe39c44d5c3882c7fe3fddac29711b1e39b7ecededd30880ecff31b2f3d1d636d5c9ead3f4b41d3999229
|
@@ -30,7 +30,11 @@ module Bridgetown
|
|
30
30
|
def categories
|
31
31
|
category_set = Set.new
|
32
32
|
Array(@obj.data["categories"]).each do |category|
|
33
|
-
category_set <<
|
33
|
+
category_set << if @obj.site.config["slugify_categories"]
|
34
|
+
Utils.slugify(category.to_s)
|
35
|
+
else
|
36
|
+
category.to_s.downcase
|
37
|
+
end
|
34
38
|
end
|
35
39
|
category_set.to_a.join("/")
|
36
40
|
end
|
@@ -0,0 +1,126 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Bridgetown
|
4
|
+
class PrototypeGenerator < Generator
|
5
|
+
priority :low
|
6
|
+
|
7
|
+
def generate(site)
|
8
|
+
@site = site
|
9
|
+
@configured_collection = "posts"
|
10
|
+
|
11
|
+
prototype_pages = site.pages.select do |page|
|
12
|
+
page.data["prototype"].is_a?(Hash)
|
13
|
+
end
|
14
|
+
|
15
|
+
if prototype_pages.length.positive?
|
16
|
+
site.pages.reject! do |page|
|
17
|
+
prototype_pages.include? page
|
18
|
+
end
|
19
|
+
|
20
|
+
prototype_pages.each do |prototype_page|
|
21
|
+
search_term = validate_search_term(prototype_page)
|
22
|
+
next if search_term.nil?
|
23
|
+
|
24
|
+
terms_matching_pages(search_term).each do |term|
|
25
|
+
generate_new_page_from_prototype(prototype_page, search_term, term).data
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def validate_search_term(prototype_page)
|
32
|
+
search_term = prototype_page.data["prototype"]["term"]
|
33
|
+
return nil unless search_term.is_a?(String)
|
34
|
+
|
35
|
+
if prototype_page.data["prototype"]["collection"]
|
36
|
+
@configured_collection = prototype_page.data["prototype"]["collection"]
|
37
|
+
end
|
38
|
+
|
39
|
+
# Categories and Tags are unique in that singular and plural front matter
|
40
|
+
# can be present for each
|
41
|
+
search_term.sub(%r!^category$!, "categories").sub(%r!^tag$!, "tags")
|
42
|
+
end
|
43
|
+
|
44
|
+
def generate_new_page_from_prototype(prototype_page, search_term, term)
|
45
|
+
new_page = PrototypePage.new(prototype_page)
|
46
|
+
# Use the original specified term so we get "tag" back, not "tags":
|
47
|
+
new_page.data[prototype_page.data["prototype"]["term"]] = term
|
48
|
+
|
49
|
+
process_title_data_placeholder(new_page, prototype_page, search_term, term)
|
50
|
+
process_title_simple_placeholders(new_page, prototype_page, term)
|
51
|
+
|
52
|
+
new_page.data["pagination"] = {} unless new_page.data["pagination"].is_a?(Hash)
|
53
|
+
new_page.data["pagination"]["enabled"] = true
|
54
|
+
new_page.data["pagination"]["collection"] = @configured_collection
|
55
|
+
new_page.data["pagination"]["where_query"] = [search_term, term]
|
56
|
+
new_page.slugify_term(term)
|
57
|
+
@site.pages << new_page
|
58
|
+
new_page
|
59
|
+
end
|
60
|
+
|
61
|
+
def terms_matching_pages(search_term)
|
62
|
+
selected_docs = @site.documents.select do |document|
|
63
|
+
document.respond_to?(:collection) && document.collection.label == @configured_collection
|
64
|
+
end
|
65
|
+
|
66
|
+
Bridgetown::Paginate::Generator::PaginationIndexer.index_documents_by(
|
67
|
+
selected_docs, search_term
|
68
|
+
).keys
|
69
|
+
end
|
70
|
+
|
71
|
+
def process_title_data_placeholder(new_page, prototype_page, search_term, term)
|
72
|
+
if prototype_page["prototype"]["data"]
|
73
|
+
if new_page.data["title"]&.include?(":prototype-data-label")
|
74
|
+
related_data = @site.data[prototype_page["prototype"]["data"]].dig(term)
|
75
|
+
if related_data
|
76
|
+
new_page.data["#{search_term}_data"] = related_data
|
77
|
+
data_label = related_data[prototype_page["prototype"]["data_label"]]
|
78
|
+
new_page.data["title"] = new_page.data["title"].gsub(
|
79
|
+
":prototype-data-label", data_label
|
80
|
+
)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def process_title_simple_placeholders(new_page, _prototype_page, term)
|
87
|
+
if new_page.data["title"]&.include?(":prototype-term-titleize")
|
88
|
+
new_page.data["title"] = new_page.data["title"].gsub(
|
89
|
+
":prototype-term-titleize", Bridgetown::Utils.titleize_slug(term)
|
90
|
+
)
|
91
|
+
end
|
92
|
+
|
93
|
+
if new_page.data["title"]&.include?(":prototype-term")
|
94
|
+
new_page.data["title"] = new_page.data["title"].gsub(
|
95
|
+
":prototype-term", term
|
96
|
+
)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
class PrototypePage < Page
|
102
|
+
def initialize(prototype_page)
|
103
|
+
@site = prototype_page.site
|
104
|
+
@url = ""
|
105
|
+
@name = "index.html"
|
106
|
+
@path = prototype_page.path
|
107
|
+
|
108
|
+
process(@name)
|
109
|
+
|
110
|
+
self.data = Bridgetown::Utils.deep_merge_hashes prototype_page.data, {}
|
111
|
+
self.content = prototype_page.content
|
112
|
+
|
113
|
+
# Perform some validation that is also performed in Bridgetown::Page
|
114
|
+
validate_data! prototype_page.path
|
115
|
+
validate_permalink! prototype_page.path
|
116
|
+
|
117
|
+
@dir = Pathname.new(prototype_page.relative_path).dirname.to_s
|
118
|
+
@path = site.in_source_dir(@dir, @name)
|
119
|
+
end
|
120
|
+
|
121
|
+
def slugify_term(term)
|
122
|
+
term_slug = Bridgetown::Utils.slugify(term)
|
123
|
+
@url = "/#{@dir}/#{term_slug}/"
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
@@ -17,7 +17,7 @@ module.exports = {
|
|
17
17
|
filename: "all.[contenthash].js"
|
18
18
|
},
|
19
19
|
resolve: {
|
20
|
-
extensions: [".js"]
|
20
|
+
extensions: [".js", ".jsx"]
|
21
21
|
},
|
22
22
|
plugins: [
|
23
23
|
new MiniCssExtractPlugin({
|
@@ -30,7 +30,7 @@ module.exports = {
|
|
30
30
|
module: {
|
31
31
|
rules: [
|
32
32
|
{
|
33
|
-
test: /\.js/,
|
33
|
+
test: /\.(js|jsx)/,
|
34
34
|
use: {
|
35
35
|
loader: "babel-loader",
|
36
36
|
options: {
|
@@ -38,7 +38,13 @@ module.exports = {
|
|
38
38
|
"@babel/preset-env"
|
39
39
|
],
|
40
40
|
plugins: [
|
41
|
-
"@babel/plugin-proposal-class-properties"
|
41
|
+
"@babel/plugin-proposal-class-properties",
|
42
|
+
[
|
43
|
+
"@babel/plugin-transform-runtime",
|
44
|
+
{
|
45
|
+
"helpers": false
|
46
|
+
}
|
47
|
+
]
|
42
48
|
]
|
43
49
|
}
|
44
50
|
}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bridgetown-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bridgetown Team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-04-
|
11
|
+
date: 2020-04-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|
@@ -231,6 +231,7 @@ files:
|
|
231
231
|
- lib/bridgetown-core/filters/url_filters.rb
|
232
232
|
- lib/bridgetown-core/frontmatter_defaults.rb
|
233
233
|
- lib/bridgetown-core/generator.rb
|
234
|
+
- lib/bridgetown-core/generators/prototype_generator.rb
|
234
235
|
- lib/bridgetown-core/hooks.rb
|
235
236
|
- lib/bridgetown-core/layout.rb
|
236
237
|
- lib/bridgetown-core/liquid_extensions.rb
|