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:
parent
d834ae5fed
commit
8fd32c3399
40
Gruntfile.js
40
Gruntfile.js
@ -6,13 +6,13 @@ module.exports = function(grunt){
|
||||
src: '_src',
|
||||
site: '_site',
|
||||
build: '_build',
|
||||
cdnurl: 'https://d2jlreog722xe2.cloudfront.net',
|
||||
assets: {
|
||||
stylus: 'assets/styl',
|
||||
css: 'assets/css',
|
||||
js: 'assets/js',
|
||||
img: 'assets/img',
|
||||
fonts: 'assets/fonts',
|
||||
cdnurl: 'https://d2jlreog722xe2.cloudfront.net/assets/'
|
||||
fonts: 'assets/fonts'
|
||||
}
|
||||
};
|
||||
|
||||
@ -51,8 +51,7 @@ module.exports = function(grunt){
|
||||
},
|
||||
production: {
|
||||
options: {
|
||||
lsi: true,
|
||||
raw: 'enable_cdnurl: true\n'
|
||||
lsi: true
|
||||
}
|
||||
},
|
||||
development: {
|
||||
@ -207,15 +206,30 @@ module.exports = function(grunt){
|
||||
}
|
||||
},
|
||||
|
||||
// CDN some assets
|
||||
cdn: {
|
||||
options: {
|
||||
cdn: '<%= config.assets.cdnurl %>',
|
||||
flatten: true
|
||||
// insert CDN url by replacing text strings
|
||||
replace: {
|
||||
html: {
|
||||
src: ['<%= config.build %>/**/*.html'],
|
||||
overwrite: true,
|
||||
replacements: [
|
||||
{
|
||||
from: '/assets/js/',
|
||||
to: '<%= config.cdnurl %>/assets/js/'
|
||||
},
|
||||
dist: {
|
||||
src: [
|
||||
'<%= config.build %>/assets/**/*.css' // CDN all assets called from css files
|
||||
{
|
||||
from: '/media/',
|
||||
to: '<%= config.cdnurl %>/media/'
|
||||
}
|
||||
]
|
||||
},
|
||||
css: {
|
||||
src: ['<%= config.build %>/<%= config.assets.css %>/*.css'],
|
||||
overwrite: true,
|
||||
replacements: [
|
||||
{
|
||||
from: '../',
|
||||
to: '<%= config.cdnurl %>/assets/'
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
@ -303,7 +317,7 @@ module.exports = function(grunt){
|
||||
'rsync:copy_build',
|
||||
'rev',
|
||||
'usemin',
|
||||
'cdn'
|
||||
'replace'
|
||||
]);
|
||||
|
||||
// Optimze media
|
||||
|
@ -15,8 +15,6 @@ 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
|
||||
|
@ -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['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
|
||||
@ -169,7 +169,7 @@ module Jekyll
|
||||
picture_tag
|
||||
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]))
|
||||
digest = Digest::MD5.hexdigest(image.to_blob).slice!(0..5)
|
||||
|
||||
@ -230,11 +230,7 @@ module Jekyll
|
||||
end
|
||||
|
||||
# Return path relative to the site root for html
|
||||
if enable_cdnurl == true
|
||||
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
|
||||
|
@ -10,7 +10,6 @@
|
||||
"dependencies": {},
|
||||
"devDependencies": {
|
||||
"grunt": ">=0.4.5",
|
||||
"grunt-cdn": ">=0.5.6",
|
||||
"grunt-combine-media-queries": ">=1.0.8",
|
||||
"grunt-contrib-clean": ">=0.5.0",
|
||||
"grunt-contrib-connect": ">=0.5.0",
|
||||
@ -22,6 +21,7 @@
|
||||
"grunt-jekyll": ">=0.4.0",
|
||||
"grunt-rev": ">=0.1.0",
|
||||
"grunt-rsync": ">=0.2.1",
|
||||
"grunt-text-replace": ">=0.3.12",
|
||||
"grunt-usemin": ">=2.0.2",
|
||||
"nib": ">=1.0.3",
|
||||
"stylus": ">=0.45.0"
|
||||
|
Loading…
Reference in New Issue
Block a user