Skip to content

Commit

Permalink
fix: apply Inspectors to Generated Pages as well
Browse files Browse the repository at this point in the history
**Breaking change from beta2**
  • Loading branch information
jaredcwhite committed Jun 12, 2022
1 parent f6100da commit a44b5df
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
16 changes: 14 additions & 2 deletions bridgetown-builder/lib/bridgetown-builder/dsl/inspectors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module HTML
# Are there inspectors available? Is it an .htm* file?
def self.can_run?(resource, inspectors)
inspectors &&
resource.destination&.output_ext&.starts_with?(".htm") &&
resource.output_ext&.starts_with?(".htm") &&
!resource.data.bypass_inspectors
end

Expand All @@ -42,7 +42,7 @@ def self.call(resource, inspectors)
module XML
# Strip the resource's initial extension dot. `.rss` => `rss`
def self.resource_ext(resource)
resource.destination&.output_ext&.delete_prefix(".")
resource.output_ext&.delete_prefix(".")
end

# Are there any inspectors available which match the resource extension?
Expand Down Expand Up @@ -103,6 +103,12 @@ def inspect_html(&block)

resource.output = Inspectors.process_html(resource, @_html_inspectors)
end

hook :generated_pages, :post_render do |page|
next unless HTML.can_run?(page, @_html_inspectors)

page.output = Inspectors.process_html(page, @_html_inspectors)
end
end

@_html_inspectors << block
Expand All @@ -123,6 +129,12 @@ def inspect_xml(extension = "xml", &block)

resource.output = Inspectors.process_xml(resource, @_xml_inspectors)
end

hook :generated_pages, :post_render do |page|
next unless Inspectors::XML.can_run?(page, @_xml_inspectors)

page.output = Inspectors.process_xml(page, @_xml_inspectors)
end
end

(@_xml_inspectors[extension.to_s] ||= []).tap do |arr|
Expand Down
5 changes: 5 additions & 0 deletions bridgetown-core/lib/bridgetown-core/resource/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,11 @@ def id
model.origin.id
end

# @return [String]
def output_ext
destination&.output_ext
end

def date
data["date"] ||= site.time
end
Expand Down

0 comments on commit a44b5df

Please sign in to comment.