Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature - Allow for layouts to have different CSS files via prefix workflow, enables you to have different/multiple template styles in same project #25

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
54 changes: 48 additions & 6 deletions gulpfile.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,38 @@ import colors from 'colors';

const $ = plugins();

/* Enable/disable prefix workflow - allows for layouts to have different css references
but page names prefix must match css file name
e.g.
> scss/__invite.scss
.invite { background-color:#333333; ... }
...

> scss/invite.scss
@import 'settings';
@import 'foundation-emails';
@import '_invite';
...

> layouts/invite.html
...
<link rel="stylesheet" type="text/css" href="css/invite.css">
...

> pages/invite.html, invite2.html, invite_audience1.html
---
layout: invite
---
...

//So all the pages with the prefix "invite" will be inlined with the css from invite.css
*/
var PREFIX_WORKFLOW=true;

// Look for the --production flag
const PRODUCTION = !!(yargs.argv.production);

// Declar var so that both AWS and Litmus task can use it.
// Declare var so that both AWS and Litmus task can use it.
var CONFIG;

// Build the "dist" folder by running all of the above tasks
Expand Down Expand Up @@ -65,7 +93,7 @@ function resetPages(done) {

// Compile Sass into CSS
function sass() {
return gulp.src('src/assets/scss/app.scss')
return gulp.src('src/assets/scss/*.scss')
.pipe($.if(!PRODUCTION, $.sourcemaps.init()))
.pipe($.sass({
includePaths: ['node_modules/foundation-emails/scss']
Expand All @@ -82,10 +110,24 @@ function images() {
}

// Inline CSS and minify HTML
function inline() {
return gulp.src('dist/**/*.html')
.pipe($.if(PRODUCTION, inliner('dist/css/app.css')))
.pipe(gulp.dest('dist'));
function inline(done) {

if (PREFIX_WORKFLOW) {
var files = fs.readdirSync('./dist/css');
var prefix = '';
var result = done();
for(var i in files) {
prefix = files[i].slice(0, -4);
result = gulp.src('dist/**/' + prefix + '*.html')
.pipe($.if(PRODUCTION, inliner('dist/css/' + prefix + '.css')))
.pipe(gulp.dest('dist'));
}
return result;
} else {
return gulp.src('dist/**/*.html')
.pipe($.if(PRODUCTION, inliner('dist/css/app.css')))
.pipe(gulp.dest('dist'));
}
}

// Start a server with LiveReload to preview the site in
Expand Down