jekyll: allow to set a file as destination for fetch remote plugin

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax 2022-06-29 16:06:43 +02:00
parent f540f58541
commit ce74d35241
No known key found for this signature in database
GPG Key ID: 3248E46B6BB8C7F7
3 changed files with 33 additions and 27 deletions

View File

@ -6,6 +6,9 @@ require 'open-uri'
require 'rake'
module Jekyll
class FetchRemote < Octopress::Hooks::Site
priority :highest
def self.download(url, dest)
uri = URI.parse(url)
result = File.join(dest, File.basename(uri.path))
@ -30,14 +33,13 @@ module Jekyll
end
end
class FetchRemote < Octopress::Hooks::Site
def pre_read(site)
beginning_time = Time.now
puts "Starting plugin fetch_remote.rb..."
site.config['fetch-remote'].each do |entry|
puts " Repo #{entry['repo']} (#{entry['ref']})"
Dir.mktmpdir do |tmpdir|
tmpfile = Jekyll.download("#{entry['repo']}/archive/#{entry['ref']}.zip", tmpdir)
tmpfile = FetchRemote.download("#{entry['repo']}/archive/#{entry['ref']}.zip", tmpdir)
Dir.mktmpdir do |ztmpdir|
puts " Extracting #{tmpfile}"
Archive::Zip.extract(
@ -46,7 +48,15 @@ module Jekyll
:create => true
)
entry['paths'].each do |path|
if File.extname(path['dest']) != ""
if path['src'].size > 1
raise "Cannot use file destination #{path['dest']} with multiple sources"
end
FileUtils.mkdir_p File.dirname(path['dest'])
else
FileUtils.mkdir_p path['dest']
end
puts " Copying files"
# prepare file list to be copied
@ -60,7 +70,7 @@ module Jekyll
end
files.each do |file|
Jekyll.copy(file, path['dest']) do |s, d|
FetchRemote.copy(file, path['dest']) do |s, d|
s = File.realpath(s)
# traverse source directory
FileUtils::Entry_.new(s, nil, false).wrap_traverse(proc do |ent|

View File

@ -2,7 +2,6 @@ require 'jekyll'
require 'octopress-hooks'
module Jekyll
class FetchRemote < Octopress::Hooks::Site
def post_read(site)
beginning_time = Time.now
@ -20,5 +19,4 @@ module Jekyll
Jekyll.logger.info "done in #{(end_time - beginning_time)} seconds"
end
end
end

View File

@ -2,7 +2,6 @@ require 'jekyll'
require 'octopress-hooks'
module Jekyll
class UpdateApiToc < Octopress::Hooks::Site
def pre_read(site)
beginning_time = Time.now
@ -22,5 +21,4 @@ module Jekyll
Jekyll.logger.info "done in #{(end_time - beginning_time)} seconds"
end
end
end