Copy generated files to _site and add output directory to keep_files

This commit is contained in:
Joseph Wynn 2015-11-04 22:55:32 +00:00
parent 2847c083b3
commit 1917b905ff
7 changed files with 36 additions and 10 deletions

View File

@ -46,7 +46,8 @@ responsive_image:
quality: 90 quality: 90
# [Optional, Default: assets/resized/%{filename}-%{width}x%{height}.%{extension}] # [Optional, Default: assets/resized/%{filename}-%{width}x%{height}.%{extension}]
# The template used when generating filenames for resized images. # The template used when generating filenames for resized images. Must be a
# relative path.
# #
# Parameters available are: # Parameters available are:
# %{basename} Basename of the file (assets/some-file.jpg => some-file.jpg) # %{basename} Basename of the file (assets/some-file.jpg => some-file.jpg)

View File

@ -9,6 +9,7 @@ require 'jekyll/responsive_image/defaults'
require 'jekyll/responsive_image/utils' require 'jekyll/responsive_image/utils'
require 'jekyll/responsive_image/image_processor' require 'jekyll/responsive_image/image_processor'
require 'jekyll/responsive_image/resize_handler' require 'jekyll/responsive_image/resize_handler'
require 'jekyll/responsive_image/common'
require 'jekyll/responsive_image/tag' require 'jekyll/responsive_image/tag'
require 'jekyll/responsive_image/block' require 'jekyll/responsive_image/block'

View File

@ -1,9 +1,10 @@
module Jekyll module Jekyll
class ResponsiveImage class ResponsiveImage
class Block < Liquid::Block class Block < Liquid::Block
include Jekyll::ResponsiveImage::Common
def render(context) def render(context)
config = ResponsiveImage.defaults.dup config = make_config(context.registers[:site])
config.merge!(context.registers[:site].config['responsive_image'])
attributes = YAML.load(super) attributes = YAML.load(super)
image_template = attributes['template'] || config['template'] image_template = attributes['template'] || config['template']

View File

@ -0,0 +1,17 @@
module Jekyll
class ResponsiveImage
module Common
include Jekyll::ResponsiveImage::Utils
def make_config(site)
config = ResponsiveImage.defaults.dup.merge(site.config['responsive_image']).merge(:site_dest => site.dest)
# Not very nice, but this is needed to create a clean path to add to keep_files
output_dir = format_output_path(config['output_path_format'], '*', '*', '*')
site.config['keep_files'] << output_dir unless site.config['keep_files'].include?(output_dir)
config
end
end
end
end

View File

@ -28,17 +28,17 @@ module Jekyll
f.quality = size['quality'] || config['default_quality'] f.quality = size['quality'] || config['default_quality']
end end
# Ensure the generated file is copied to the _site directory
site_dest_filepath = File.expand_path(filepath, config[:site_dest])
ensure_output_dir_exists!(File.dirname(site_dest_filepath))
FileUtils.copy(filepath, site_dest_filepath)
i.destroy! i.destroy!
end end
resized resized
end end
def format_output_path(format, path, width, height)
params = symbolize_keys(image_hash(path, width, height))
format % params
end
def needs_resizing?(img, width) def needs_resizing?(img, width)
img.columns > width img.columns > width
end end

View File

@ -1,6 +1,8 @@
module Jekyll module Jekyll
class ResponsiveImage class ResponsiveImage
class Tag < Liquid::Tag class Tag < Liquid::Tag
include Jekyll::ResponsiveImage::Common
def initialize(tag_name, markup, tokens) def initialize(tag_name, markup, tokens)
super super
@ -13,8 +15,7 @@ module Jekyll
end end
def render(context) def render(context)
config = ResponsiveImage.defaults.dup config = make_config(context.registers[:site])
config.merge!(context.registers[:site].config['responsive_image'])
image = ImageProcessor.process(@attributes['path'], config) image = ImageProcessor.process(@attributes['path'], config)
@attributes['original'] = image[:original] @attributes['original'] = image[:original]

View File

@ -9,6 +9,11 @@ module Jekyll
result result
end end
def format_output_path(format, path, width, height)
params = symbolize_keys(image_hash(path, width, height))
format % params
end
# Build a hash containing image information # Build a hash containing image information
def image_hash(path, width, height) def image_hash(path, width, height)
{ {