bridgetown-core 0.18.6 → 0.20.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. checksums.yaml +4 -4
  2. data/bin/bridgetown +6 -0
  3. data/bridgetown-core.gemspec +4 -4
  4. data/lib/bridgetown-core.rb +46 -13
  5. data/lib/bridgetown-core/cleaner.rb +7 -1
  6. data/lib/bridgetown-core/collection.rb +173 -77
  7. data/lib/bridgetown-core/commands/apply.rb +4 -3
  8. data/lib/bridgetown-core/commands/base.rb +9 -0
  9. data/lib/bridgetown-core/commands/concerns/actions.rb +0 -5
  10. data/lib/bridgetown-core/commands/configure.rb +66 -0
  11. data/lib/bridgetown-core/commands/console.rb +4 -0
  12. data/lib/bridgetown-core/commands/new.rb +28 -1
  13. data/lib/bridgetown-core/commands/plugins.rb +1 -0
  14. data/lib/bridgetown-core/concerns/data_accessible.rb +1 -0
  15. data/lib/bridgetown-core/concerns/site/configurable.rb +7 -3
  16. data/lib/bridgetown-core/concerns/site/content.rb +57 -15
  17. data/lib/bridgetown-core/concerns/site/processable.rb +1 -0
  18. data/lib/bridgetown-core/concerns/site/renderable.rb +26 -0
  19. data/lib/bridgetown-core/concerns/site/writable.rb +11 -1
  20. data/lib/bridgetown-core/concerns/validatable.rb +1 -0
  21. data/lib/bridgetown-core/configuration.rb +39 -19
  22. data/lib/bridgetown-core/configurations/.keep +0 -0
  23. data/lib/bridgetown-core/configurations/bt-postcss.rb +26 -0
  24. data/lib/bridgetown-core/configurations/bt-postcss/postcss.config.js +21 -0
  25. data/lib/bridgetown-core/configurations/minitesting.rb +95 -0
  26. data/lib/bridgetown-core/configurations/netlify.rb +6 -0
  27. data/lib/bridgetown-core/configurations/netlify/netlify.sh +14 -0
  28. data/lib/bridgetown-core/configurations/netlify/netlify.toml +44 -0
  29. data/lib/bridgetown-core/configurations/purgecss.rb +49 -0
  30. data/lib/bridgetown-core/configurations/stimulus.rb +49 -0
  31. data/lib/bridgetown-core/configurations/swup.rb +37 -0
  32. data/lib/bridgetown-core/configurations/tailwindcss.rb +29 -0
  33. data/lib/bridgetown-core/configurations/tailwindcss/css_imports.css +4 -0
  34. data/lib/bridgetown-core/configurations/tailwindcss/postcss.config.js +12 -0
  35. data/lib/bridgetown-core/configurations/turbo.rb +16 -0
  36. data/lib/bridgetown-core/converter.rb +14 -0
  37. data/lib/bridgetown-core/converters/erb_templates.rb +6 -13
  38. data/lib/bridgetown-core/converters/identity.rb +0 -9
  39. data/lib/bridgetown-core/converters/markdown.rb +14 -4
  40. data/lib/bridgetown-core/converters/markdown/kramdown_parser.rb +3 -0
  41. data/lib/bridgetown-core/current.rb +10 -0
  42. data/lib/bridgetown-core/document.rb +6 -14
  43. data/lib/bridgetown-core/drops/collection_drop.rb +1 -1
  44. data/lib/bridgetown-core/drops/page_drop.rb +4 -0
  45. data/lib/bridgetown-core/drops/resource_drop.rb +81 -0
  46. data/lib/bridgetown-core/drops/site_drop.rb +33 -8
  47. data/lib/bridgetown-core/drops/unified_payload_drop.rb +4 -0
  48. data/lib/bridgetown-core/entry_filter.rb +10 -23
  49. data/lib/bridgetown-core/errors.rb +0 -2
  50. data/lib/bridgetown-core/filters.rb +4 -3
  51. data/lib/bridgetown-core/generator.rb +2 -1
  52. data/lib/bridgetown-core/generators/prototype_generator.rb +37 -19
  53. data/lib/bridgetown-core/layout.rb +2 -2
  54. data/lib/bridgetown-core/liquid_renderer/file.rb +1 -0
  55. data/lib/bridgetown-core/liquid_renderer/table.rb +1 -0
  56. data/lib/bridgetown-core/model/base.rb +138 -0
  57. data/lib/bridgetown-core/model/builder_origin.rb +40 -0
  58. data/lib/bridgetown-core/model/file_origin.rb +119 -0
  59. data/lib/bridgetown-core/model/origin.rb +38 -0
  60. data/lib/bridgetown-core/page.rb +9 -1
  61. data/lib/bridgetown-core/plugin.rb +2 -26
  62. data/lib/bridgetown-core/plugin_manager.rb +0 -2
  63. data/lib/bridgetown-core/publisher.rb +7 -1
  64. data/lib/bridgetown-core/reader.rb +25 -12
  65. data/lib/bridgetown-core/readers/data_reader.rb +3 -4
  66. data/lib/bridgetown-core/readers/post_reader.rb +1 -1
  67. data/lib/bridgetown-core/regenerator.rb +8 -1
  68. data/lib/bridgetown-core/related_posts.rb +1 -1
  69. data/lib/bridgetown-core/renderer.rb +5 -12
  70. data/lib/bridgetown-core/resource/base.rb +275 -0
  71. data/lib/bridgetown-core/resource/destination.rb +49 -0
  72. data/lib/bridgetown-core/resource/permalink_processor.rb +179 -0
  73. data/lib/bridgetown-core/resource/taxonomy_term.rb +25 -0
  74. data/lib/bridgetown-core/resource/taxonomy_type.rb +47 -0
  75. data/lib/bridgetown-core/resource/transformer.rb +173 -0
  76. data/lib/bridgetown-core/ruby_template_view.rb +13 -2
  77. data/lib/bridgetown-core/site.rb +9 -1
  78. data/lib/bridgetown-core/static_file.rb +33 -10
  79. data/lib/bridgetown-core/url.rb +1 -0
  80. data/lib/bridgetown-core/utils.rb +40 -40
  81. data/lib/bridgetown-core/utils/platforms.rb +1 -0
  82. data/lib/bridgetown-core/version.rb +2 -2
  83. data/lib/site_template/README.md +70 -0
  84. data/lib/site_template/frontend/javascript/index.js.erb +11 -0
  85. data/lib/site_template/frontend/styles/index.css +19 -0
  86. data/lib/site_template/{package.json → package.json.erb} +14 -8
  87. data/lib/site_template/postcss.config.js.erb +11 -0
  88. data/lib/site_template/src/_components/footer.liquid +1 -1
  89. data/lib/site_template/src/_posts/0000-00-00-welcome-to-bridgetown.md.erb +1 -1
  90. data/lib/site_template/{webpack.config.js → webpack.config.js.erb} +47 -5
  91. metadata +67 -42
  92. data/lib/bridgetown-core/page_without_a_file.rb +0 -14
  93. data/lib/bridgetown-core/readers/collection_reader.rb +0 -23
  94. data/lib/bridgetown-core/utils/exec.rb +0 -26
  95. data/lib/bridgetown-core/utils/internet.rb +0 -37
  96. data/lib/bridgetown-core/utils/win_tz.rb +0 -75
  97. data/lib/site_template/frontend/javascript/index.js +0 -3
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ # rubocop:disable all
4
+
5
+ packages = "swup @swup/body-class-plugin @swup/scroll-plugin @swup/fade-theme"
6
+ say_status :swup, "Adding the following yarn packages: #{packages}"
7
+ system("yarn add #{packages}")
8
+
9
+ javascript_import do
10
+ <<~JS
11
+ import Swup from "swup"
12
+ import SwupBodyClassPlugin from "@swup/body-class-plugin"
13
+ import SwupScrollPlugin from "@swup/scroll-plugin"
14
+ import SwupFadeTheme from "@swup/fade-theme"
15
+ const swup = new Swup({
16
+ plugins: [
17
+ new SwupBodyClassPlugin(),
18
+ new SwupScrollPlugin(),
19
+ new SwupFadeTheme(),
20
+ ]
21
+ })
22
+ JS
23
+ end
24
+
25
+ css_index = File.exist?(File.expand_path("frontend/styles/index.scss", destination_root)) ? "frontend/styles/index.scss" : "frontend/styles/index.css"
26
+ append_to_file css_index do
27
+ <<~CSS
28
+ .swup-transition-main {
29
+ transition: opacity .2s;
30
+ }
31
+ CSS
32
+ end
33
+
34
+ say_status :swup, "All done! Edit .swup-transition-main in #{css_index} if you wish to adjust the transition animation"
35
+ say_status :swup, "Make sure you add id=\"swup\" to the primary container of your HTML layout (perhaps <main>)"
36
+
37
+ # rubocop:enable all
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ # rubocop:disable all
4
+
5
+ TEMPLATE_PATH = File.expand_path("./tailwindcss", __dir__)
6
+
7
+ begin
8
+ find_in_source_paths("postcss.config.js")
9
+ rescue Thor::Error
10
+ error_message = "#{"postcss.config.js".bold} not found. Please configure postcss in your project."
11
+
12
+ @logger.error "\nError:".red, "🚨 #{error_message}"
13
+ @logger.info "\nFor new projects, you can use #{"bridgetown new my_project --use-postcss".bold.blue}\n"
14
+
15
+ return
16
+ end
17
+
18
+ run "yarn add -D tailwindcss"
19
+ run "npx tailwindcss init"
20
+
21
+ remove_file "postcss.config.js"
22
+ copy_file "#{TEMPLATE_PATH}/postcss.config.js", "postcss.config.js"
23
+
24
+ prepend_to_file "frontend/styles/index.css",
25
+ File.read("#{TEMPLATE_PATH}/css_imports.css")
26
+
27
+ run "bundle exec bridgetown configure purgecss"
28
+
29
+ # rubocop:enable all
@@ -0,0 +1,4 @@
1
+ @tailwind base;
2
+ @tailwind components;
3
+ @tailwind utilities;
4
+
@@ -0,0 +1,12 @@
1
+ module.exports = {
2
+ plugins: {
3
+ 'tailwindcss': {},
4
+ 'postcss-flexbugs-fixes': {},
5
+ 'postcss-preset-env': {
6
+ autoprefixer: {
7
+ flexbox: 'no-2009'
8
+ },
9
+ stage: 3
10
+ }
11
+ }
12
+ }
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ say "Installing Turbo...", :green
4
+
5
+ run("yarn add @hotwired/turbo")
6
+
7
+ say 'Adding Turbo to "frontend/javascript/index.js"...', :magenta
8
+
9
+ javascript_import do
10
+ <<~JS
11
+ import Turbo from "@hotwired/turbo"
12
+ JS
13
+ end
14
+
15
+ say "Turbo successfully added", :green
16
+ say 'For further reading, check out "https://turbo.hotwire.dev/"', :blue
@@ -23,6 +23,16 @@ module Bridgetown
23
23
  @config = config
24
24
  end
25
25
 
26
+ # Logic to do the content conversion.
27
+ #
28
+ # @param content [String] content of file (without front matter).
29
+ # @param convertible [Bridgetown::Document, Bridgetown::Layout, Bridgetown::Resource::Base]
30
+ #
31
+ # @return [String] the converted content.
32
+ def convert(content, convertible = nil) # rubocop:disable Lint/UnusedMethodArgument
33
+ content
34
+ end
35
+
26
36
  # Does the given extension match this converter's list of acceptable extensions?
27
37
  #
28
38
  # @param [String] ext
@@ -42,5 +52,9 @@ module Bridgetown
42
52
  def output_ext(_ext)
43
53
  ".html"
44
54
  end
55
+
56
+ def inspect
57
+ "#<#{self.class}#{self.class.extname_list ? " #{self.class.extname_list.join(", ")}" : nil}>"
58
+ end
45
59
  end
46
60
  end
@@ -65,24 +65,17 @@ module Bridgetown
65
65
  block.nil? ? input.to_s : capture(&block)
66
66
  )
67
67
  converter = site.find_converter_instance(Bridgetown::Converters::Markdown)
68
- converter.convert(content).strip
68
+ result = converter.convert(content).strip
69
+ result.respond_to?(:html_safe) ? result.html_safe : result
69
70
  end
70
71
 
71
- def capture(obj = nil, &block)
72
+ def capture(*args, &block)
73
+ return capture_in_view_component(*args, &block) if @in_view_component
74
+
72
75
  previous_buffer_state = @_erbout
73
76
  @_erbout = ERBBuffer.new
74
-
75
- # For compatibility with ActionView, not used by Bridgetown normally
76
- previous_ob_state = @output_buffer
77
- @output_buffer = ERBBuffer.new
78
-
79
- result = instance_exec(obj, &block)
80
- if @output_buffer != ""
81
- # use Rails' ActionView buffer if present
82
- result = @output_buffer
83
- end
77
+ result = yield(*args)
84
78
  @_erbout = previous_buffer_state
85
- @output_buffer = previous_ob_state
86
79
 
87
80
  result.respond_to?(:html_safe) ? result.html_safe : result
88
81
  end
@@ -25,15 +25,6 @@ module Bridgetown
25
25
  def output_ext(ext)
26
26
  ext
27
27
  end
28
-
29
- # Logic to do the content conversion.
30
- #
31
- # content - String content of file (without front matter).
32
- #
33
- # Returns a String of the converted content.
34
- def convert(content)
35
- content
36
- end
37
28
  end
38
29
  end
39
30
  end
@@ -22,7 +22,9 @@ module Bridgetown
22
22
  raise Errors::FatalException, "Invalid Markdown processor given: #{@config["markdown"]}"
23
23
  end
24
24
 
25
- @cache = Bridgetown::Cache.new("Bridgetown::Converters::Markdown")
25
+ unless @config.cache_markdown == false || @config.kramdown.input == "GFMExtractions"
26
+ @cache = Bridgetown::Cache.new("Bridgetown::Converters::Markdown")
27
+ end
26
28
  @setup = true
27
29
  end
28
30
 
@@ -59,10 +61,18 @@ module Bridgetown
59
61
  # content - String content of file (without front matter).
60
62
  #
61
63
  # Returns a String of the converted content.
62
- def convert(content)
64
+ def convert(content, convertible = nil)
63
65
  setup
64
- @cache.getset(content) do
65
- @parser.convert(content)
66
+ if @cache
67
+ @cache.getset(content) do
68
+ @parser.convert(content)
69
+ end
70
+ else
71
+ output = @parser.convert(content)
72
+ if @parser.respond_to?(:extractions)
73
+ convertible.data.markdown_extractions = @parser.extractions
74
+ end
75
+ output
66
76
  end
67
77
  end
68
78
 
@@ -69,6 +69,8 @@ module Bridgetown
69
69
  module Converters
70
70
  class Markdown
71
71
  class KramdownParser
72
+ attr_reader :extractions
73
+
72
74
  def initialize(config)
73
75
  @main_fallback_highlighter = config["highlighter"] || "rouge"
74
76
  @config = config["kramdown"] || {}
@@ -95,6 +97,7 @@ module Bridgetown
95
97
  Bridgetown.logger.warn "Kramdown warning:", warning
96
98
  end
97
99
  end
100
+ @extractions = document.root.options[:extractions] # could be nil
98
101
  html_output
99
102
  end
100
103
 
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bridgetown
4
+ class Current < ActiveSupport::CurrentAttributes
5
+ # @!method self.site
6
+ # @return [Bridgetown::Site]
7
+
8
+ attribute :site
9
+ end
10
+ end
@@ -52,7 +52,7 @@ module Bridgetown
52
52
  @has_yaml_header = nil
53
53
 
54
54
  data.default_proc = proc do |_, key|
55
- site.frontmatter_defaults.find(relative_path, type, key)
55
+ site.frontmatter_defaults.find(relative_path, type, key.to_s)
56
56
  end
57
57
 
58
58
  trigger_hooks(:post_init)
@@ -81,7 +81,7 @@ module Bridgetown
81
81
  #
82
82
  # Return document date string.
83
83
  def date
84
- data["date"] ||= site.time
84
+ data["date"] ||= site.time # TODO: this doesn't reflect documented behavior
85
85
  end
86
86
 
87
87
  # Return document file modification time in the form of a Time object.
@@ -402,21 +402,13 @@ module Bridgetown
402
402
  end
403
403
 
404
404
  def populate_categories
405
- categories = Array(data["categories"]) + Utils.pluralized_array_from_hash(
406
- data, "category", "categories"
407
- )
408
- categories.map!(&:to_s)
409
- categories.flatten!
410
- categories.uniq!
411
-
412
- merge_data!({ "categories" => categories })
405
+ data.categories = Utils.pluralized_array_from_hash(
406
+ data, :category, :categories
407
+ ).map(&:to_s)
413
408
  end
414
409
 
415
410
  def populate_tags
416
- tags = Utils.pluralized_array_from_hash(data, "tag", "tags")
417
- tags.flatten!
418
-
419
- merge_data!({ "tags" => tags })
411
+ data.tags = Utils.pluralized_array_from_hash(data, :tag, :tags)
420
412
  end
421
413
 
422
414
  def determine_locale
@@ -8,7 +8,7 @@ module Bridgetown
8
8
  mutable false
9
9
 
10
10
  def_delegator :@obj, :write?, :output
11
- def_delegators :@obj, :label, :docs, :files, :relative_path
11
+ def_delegators :@obj, :label, :docs, :files, :relative_path, :resources, :static_files
12
12
 
13
13
  private def_delegator :@obj, :metadata, :fallback_data
14
14
 
@@ -9,6 +9,10 @@ module Bridgetown
9
9
 
10
10
  def_delegators :@obj, :content, :dir, :name, :path, :url, :pager
11
11
  private def_delegator :@obj, :data, :fallback_data
12
+
13
+ def relative_url
14
+ @obj.relative_url
15
+ end
12
16
  end
13
17
  end
14
18
  end
@@ -0,0 +1,81 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bridgetown
4
+ module Drops
5
+ class ResourceDrop < Drop
6
+ extend Forwardable
7
+
8
+ NESTED_OBJECT_FIELD_BLACKLIST = %w(
9
+ content output excerpt next previous
10
+ ).freeze
11
+
12
+ mutable false
13
+
14
+ def_delegator :@obj, :relative_path, :path
15
+ def_delegators :@obj,
16
+ :id,
17
+ :output,
18
+ :content,
19
+ :to_s,
20
+ :absolute_url,
21
+ :relative_path,
22
+ :relative_url,
23
+ :date,
24
+ :taxonomies
25
+
26
+ private def_delegator :@obj, :data, :fallback_data
27
+
28
+ def collection
29
+ @collection ||= @obj.collection.to_liquid
30
+ end
31
+
32
+ def excerpt
33
+ fallback_data["excerpt"].to_s
34
+ end
35
+
36
+ def <=>(other)
37
+ return nil unless other.is_a? ResourceDrop
38
+
39
+ cmp = self["date"] <=> other["date"]
40
+ cmp = self["path"] <=> other["path"] if cmp.nil? || cmp.zero?
41
+ cmp
42
+ end
43
+
44
+ def previous
45
+ @previous ||= @obj.previous_resource.to_liquid
46
+ end
47
+
48
+ def next
49
+ @next ||= @obj.previous_resource.to_liquid
50
+ end
51
+
52
+ # Generate a Hash for use in generating JSON.
53
+ # This is useful if fields need to be cleared before the JSON can generate.
54
+ #
55
+ # state - the JSON::State object which determines the state of current processing.
56
+ #
57
+ # Returns a Hash ready for JSON generation.
58
+ def hash_for_json(state = nil)
59
+ to_h.tap do |hash|
60
+ # use collection label in the hash
61
+ hash["collection"] = hash["collection"]["label"] if hash["collection"]
62
+
63
+ if state && state.depth >= 2
64
+ hash["previous"] = collapse_document(hash["previous"]) if hash["previous"]
65
+ hash["next"] = collapse_document(hash["next"]) if hash["next"]
66
+ end
67
+ end
68
+ end
69
+
70
+ # Generate a Hash which breaks the recursive chain.
71
+ # Certain fields which are normally available are omitted.
72
+ #
73
+ # Returns a Hash with only non-recursive fields present.
74
+ def collapse_document(doc)
75
+ doc.keys.each_with_object({}) do |(key, _), result|
76
+ result[key] = doc[key] unless NESTED_OBJECT_FIELD_BLACKLIST.include?(key)
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
@@ -7,35 +7,53 @@ module Bridgetown
7
7
 
8
8
  mutable false
9
9
 
10
- def_delegator :@obj, :data
11
- def_delegators :@obj, :locale, :time, :pages, :static_files, :tags, :categories
10
+ def_delegators :@obj,
11
+ :data,
12
+ :locale,
13
+ :time,
14
+ :pages,
15
+ :generated_pages,
16
+ :static_files,
17
+ :tags,
18
+ :categories,
19
+ :taxonomies,
20
+ :taxonomy_types
12
21
 
13
22
  private def_delegator :@obj, :config, :fallback_data
14
23
 
15
24
  attr_writer :current_document
16
25
 
17
26
  def [](key)
18
- if key != "posts" && @obj.collections.key?(key)
19
- @obj.collections[key].docs
20
- else
21
- super(key)
27
+ if !@obj.uses_resource? && !%w(posts data).freeze.include?(key) &&
28
+ @obj.collections.key?(key)
29
+ return @obj.collections[key].docs
22
30
  end
31
+
32
+ super(key)
23
33
  end
24
34
 
25
35
  def key?(key)
26
- (key != "posts" && @obj.collections.key?(key)) || super
36
+ (!@obj.uses_resource? && key != "posts" && @obj.collections.key?(key)) || super
37
+ end
38
+
39
+ def uses_resource
40
+ @obj.uses_resource?
27
41
  end
28
42
 
29
43
  def posts
30
- @site_posts ||= @obj.posts.docs.sort { |a, b| b <=> a }
44
+ unless @obj.uses_resource?
45
+ @site_posts ||= @obj.collections.posts.docs.sort { |a, b| b <=> a }
46
+ end
31
47
  end
32
48
 
49
+ # TODO: deprecate before v1.0
33
50
  def html_pages
34
51
  @site_html_pages ||= @obj.pages.select do |page|
35
52
  page.html? || page.url.end_with?("/")
36
53
  end
37
54
  end
38
55
 
56
+ # TODO: deprecate before v1.0
39
57
  def collections
40
58
  @site_collections ||= @obj.collections.values.sort_by(&:label).map(&:to_liquid)
41
59
  end
@@ -50,6 +68,10 @@ module Bridgetown
50
68
  @documents ||= @obj.documents
51
69
  end
52
70
 
71
+ def resources
72
+ @resources ||= @obj.resources
73
+ end
74
+
53
75
  def contents
54
76
  @contents ||= @obj.contents
55
77
  end
@@ -58,6 +80,9 @@ module Bridgetown
58
80
  @site_metadata ||= @obj.data["site_metadata"]
59
81
  end
60
82
 
83
+ # TODO: change this so you *do* use site.config...aka site.config.timezone,
84
+ # not site.timezone
85
+ #
61
86
  # return nil for `{{ site.config }}` even if --config was passed via CLI
62
87
  def config; end
63
88
  end