1
0
mirror of https://github.com/kremalicious/blog.git synced 2024-11-22 09:56:51 +01:00

Merge pull request #19 from kremalicious/cdn

CDN for /media assets
This commit is contained in:
Matthias Kretschmann 2014-09-06 16:45:44 +02:00
commit 10680cbd7a
6 changed files with 32 additions and 8 deletions

View File

@ -11,7 +11,8 @@ module.exports = function(grunt){
css: 'assets/css',
js: 'assets/js',
img: 'assets/img',
fonts: 'assets/fonts'
fonts: 'assets/fonts',
cdnurl: 'https://d2jlreog722xe2.cloudfront.net/assets/'
}
};
@ -50,7 +51,8 @@ module.exports = function(grunt){
},
production: {
options: {
lsi: true
lsi: true,
raw: 'enable_cdnurl: true\n'
}
},
development: {
@ -204,6 +206,19 @@ module.exports = function(grunt){
assetsDirs: ['<%= config.build %>', '<%= config.build %>/assets/{css,js,img,fonts}']
}
},
// CDN some assets
cdn: {
options: {
cdn: '<%= config.cdnurl %>',
flatten: true
},
dist: {
src: [
'<%= config.build %>/assets/**/*.css' // CDN all assets called from css files
]
}
},
// rsync stuff around
rsync: {
@ -287,7 +302,8 @@ module.exports = function(grunt){
'imagemin:touchicons',
'rsync:copy_build',
'rev',
'usemin'
'usemin',
'cdn'
]);
// Optimze media

View File

@ -15,6 +15,8 @@ description: 'Blog of designer & developer Matthias Kretschmann'
url: https://kremalicious.com
author: Matthias Kretschmann
email: m@kretschmann.io
cdnurl: https://d2jlreog722xe2.cloudfront.net
enable_cdnurl: false
# Urls

View File

@ -65,7 +65,6 @@
<!-- Picturefill -->
<script src="/assets/js/picturefill.min.js" defer></script>
<!-- Canonical URL -->
<link rel="canonical" href="{{ site.url}}{{ page.url | replace:'index.html','' }}">

View File

@ -142,7 +142,7 @@ module Jekyll
# Generate resized images
instance.each { |key, source|
instance[key][:generated_src] = generate_image(source, site.source, site.dest, settings['source'], settings['output'], site.config["baseurl"])
instance[key][:generated_src] = generate_image(source, site.source, site.dest, settings['source'], settings['output'], site.config['cdnurl'], site.config["baseurl"], site.config['enable_cdnurl'])
}
# Construct and return tag
@ -169,7 +169,7 @@ module Jekyll
picture_tag
end
def generate_image(instance, site_source, site_dest, image_source, image_dest, baseurl)
def generate_image(instance, site_source, site_dest, image_source, image_dest, cdnurl, baseurl, enable_cdnurl)
image = MiniMagick::Image.open(File.join(site_source, image_source, instance[:src]))
digest = Digest::MD5.hexdigest(image.to_blob).slice!(0..5)
@ -230,7 +230,12 @@ module Jekyll
end
# Return path relative to the site root for html
Pathname.new(File.join(baseurl, image_dest, image_dir, gen_name)).cleanpath
if enable_cdnurl == true
Pathname.new(File.join(cdnurl, baseurl, image_dest, image_dir, gen_name)).cleanpath
else
Pathname.new(File.join(baseurl, image_dest, image_dir, gen_name)).cleanpath
end
end
end
end

View File

@ -10,6 +10,7 @@ pre,
samp
font-family: $font-family-monospace
font-size: $font-size-small
hyphens: none
code,
kbd

View File

@ -23,7 +23,8 @@
"grunt-jekyll": ">=0.4.0",
"grunt-rsync": ">=0.2.1",
"grunt-rev": ">=0.1.0",
"grunt-usemin": ">=2.0.2"
"grunt-usemin": ">=2.0.2",
"grunt-cdn": ">=0.5.6"
},
"engines": {
"node": ">=0.10.29"