Sha256: 7f90250d275ceb03aa82c1a4c6031a7da51eecea02e0e492f4afcd2ea451d29c
Contents?: true
Size: 1.28 KB
Versions: 20
Compression:
Stored size: 1.28 KB
Contents
# frozen_string_literal: true module Bridgetown module Resource class Destination # @return [Bridgetown::Resource::Base] attr_accessor :resource # @return [String] attr_accessor :output_ext # @param resource [Bridgetown::Resource::Base] def initialize(resource) @resource = resource @output_ext = resource.transformer.final_ext end def absolute_url Addressable::URI.parse( resource.site.config.url.to_s + relative_url ).normalize.to_s end def relative_url @processor ||= PermalinkProcessor.new(resource) @processor.transform end def final_ext output_ext || resource.extname end def output_path path = URL.unescape_path(relative_url) if resource.site.base_path.present? path = path.delete_prefix resource.site.base_path(strip_slash_only: true) end path = resource.site.in_dest_dir(path) path = File.join(path, "index.html") if relative_url.end_with? "/" path end def write(output) path = output_path FileUtils.mkdir_p(File.dirname(path)) Bridgetown.logger.debug "Writing:", path File.write(path, output, mode: "wb") end end end end
Version data entries
20 entries across 20 versions & 1 rubygems