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

use only grunt to insert cdnurl

This commit is contained in:
Matthias Kretschmann 2014-09-07 20:31:47 +02:00
parent d834ae5fed
commit 8fd32c3399
4 changed files with 33 additions and 25 deletions

View File

@ -6,13 +6,13 @@ module.exports = function(grunt){
src: '_src', src: '_src',
site: '_site', site: '_site',
build: '_build', build: '_build',
cdnurl: 'https://d2jlreog722xe2.cloudfront.net',
assets: { assets: {
stylus: 'assets/styl', stylus: 'assets/styl',
css: 'assets/css', css: 'assets/css',
js: 'assets/js', js: 'assets/js',
img: 'assets/img', img: 'assets/img',
fonts: 'assets/fonts', fonts: 'assets/fonts'
cdnurl: 'https://d2jlreog722xe2.cloudfront.net/assets/'
} }
}; };
@ -51,8 +51,7 @@ module.exports = function(grunt){
}, },
production: { production: {
options: { options: {
lsi: true, lsi: true
raw: 'enable_cdnurl: true\n'
} }
}, },
development: { development: {
@ -206,16 +205,31 @@ module.exports = function(grunt){
assetsDirs: ['<%= config.build %>', '<%= config.build %>/assets/{css,js,img,fonts}'] assetsDirs: ['<%= config.build %>', '<%= config.build %>/assets/{css,js,img,fonts}']
} }
}, },
// CDN some assets // insert CDN url by replacing text strings
cdn: { replace: {
options: { html: {
cdn: '<%= config.assets.cdnurl %>', src: ['<%= config.build %>/**/*.html'],
flatten: true overwrite: true,
replacements: [
{
from: '/assets/js/',
to: '<%= config.cdnurl %>/assets/js/'
},
{
from: '/media/',
to: '<%= config.cdnurl %>/media/'
}
]
}, },
dist: { css: {
src: [ src: ['<%= config.build %>/<%= config.assets.css %>/*.css'],
'<%= config.build %>/assets/**/*.css' // CDN all assets called from css files overwrite: true,
replacements: [
{
from: '../',
to: '<%= config.cdnurl %>/assets/'
}
] ]
} }
}, },
@ -303,7 +317,7 @@ module.exports = function(grunt){
'rsync:copy_build', 'rsync:copy_build',
'rev', 'rev',
'usemin', 'usemin',
'cdn' 'replace'
]); ]);
// Optimze media // Optimze media

View File

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

View File

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

View File

@ -10,7 +10,6 @@
"dependencies": {}, "dependencies": {},
"devDependencies": { "devDependencies": {
"grunt": ">=0.4.5", "grunt": ">=0.4.5",
"grunt-cdn": ">=0.5.6",
"grunt-combine-media-queries": ">=1.0.8", "grunt-combine-media-queries": ">=1.0.8",
"grunt-contrib-clean": ">=0.5.0", "grunt-contrib-clean": ">=0.5.0",
"grunt-contrib-connect": ">=0.5.0", "grunt-contrib-connect": ">=0.5.0",
@ -22,6 +21,7 @@
"grunt-jekyll": ">=0.4.0", "grunt-jekyll": ">=0.4.0",
"grunt-rev": ">=0.1.0", "grunt-rev": ">=0.1.0",
"grunt-rsync": ">=0.2.1", "grunt-rsync": ">=0.2.1",
"grunt-text-replace": ">=0.3.12",
"grunt-usemin": ">=2.0.2", "grunt-usemin": ">=2.0.2",
"nib": ">=1.0.3", "nib": ">=1.0.3",
"stylus": ">=0.45.0" "stylus": ">=0.45.0"