Add banner text to main.min.js (#880)

- Add `---` YAML Front Matter as a workaround to allow the theme gem's version to be overridden locally.
- Adjust page scope in Front Matter default to avoid adding a layout to `main.min.js`
- Fixes #874, Fixes #722
This commit is contained in:
Michael Rose 2017-02-28 10:06:18 -05:00 committed by GitHub
parent dbdf5c2f25
commit b9d86f3989
6 changed files with 43 additions and 3 deletions

File diff suppressed because one or more lines are too long

21
banner.js Normal file
View file

@ -0,0 +1,21 @@
const fs = require('fs');
const pkg = require('./package.json');
const filename = 'assets/js/main.min.js';
const script = fs.readFileSync(filename);
const padStart = str => ('0' + str).slice(-2)
const dateObj = new Date;
const date = `${dateObj.getFullYear()}-${padStart(dateObj.getMonth() + 1)}-${padStart(dateObj.getDate())}`;
const banner = `---
layout:
---
/*!
* Minimal Mistakes Jekyll Theme ${pkg.version} by ${pkg.author}
* Copyright ${dateObj.getFullYear()} Michael Rose - mademistakes.com | @mmistakes
* Licensed under ${pkg.license}
*/
`;
if (script.slice(0, 3) != '/**') {
fs.writeFileSync(filename, banner + script);
}

View file

@ -195,7 +195,7 @@ defaults:
related: true
# _pages
- scope:
path: ""
path: "_pages"
type: pages
values:
layout: single

File diff suppressed because one or more lines are too long

View file

@ -27,7 +27,8 @@
},
"scripts": {
"uglify": "uglifyjs assets/js/vendor/jquery/jquery-1.12.4.min.js assets/js/plugins/jquery.fitvids.js assets/js/plugins/jquery.greedy-navigation.js assets/js/plugins/jquery.magnific-popup.js assets/js/plugins/jquery.smooth-scroll.min.js assets/js/_main.js -c -m -o assets/js/main.min.js",
"add-banner": "node banner.js",
"watch:js": "onchange \"assets/js/**/*.js\" -e \"assets/js/main.min.js\" -- npm run build:js",
"build:js": "npm run uglify"
"build:js": "npm run uglify && npm run add-banner"
}
}

View file

@ -258,7 +258,7 @@ defaults:
related: true
# _pages
- scope:
path: ""
path: "_pages"
type: pages
values:
layout: single