6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/jekyll_og_image/generator.rb', line 6
def generate(site)
base_path = File.join(JekyllOgImage.config.output_dir, "posts")
FileUtils.mkdir_p File.join(site.config["source"], base_path)
site.posts.docs.each do |post|
next if post.draft? && JekyllOgImage.config.skip_drafts?
path = File.join(site.config["source"], base_path, "#{post.data['slug']}.png")
if !File.exist?(path) || JekyllOgImage.config.force?
Jekyll.logger.info "Jekyll Og Image:", "Generating image #{path}" if JekyllOgImage.config.verbose?
generate_image_for_post(site, post, path)
else
Jekyll.logger.info "Jekyll Og Image:", "Skipping image generation #{path} as it already exists." if JekyllOgImage.config.verbose?
end
post.data["image"] ||= {
"path" => File.join(base_path, "#{post.data['slug']}.png"),
"width" => 1200,
"height" => 600,
"alt" => post.data["title"]
}
end
end
|