Skip to content

Commit

Permalink
Merge pull request #47 from pipocadigital/proposal-inline-css
Browse files Browse the repository at this point in the history
Task to load custom critical/first-view css as Internal
  • Loading branch information
thompsonemerson authored May 7, 2018
2 parents d42796d + 695b6f7 commit 7e8de24
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 13 deletions.
4 changes: 3 additions & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ gulp.task('watch', () => {
const paths = Object.keys(developmentPaths);

paths.map(path => {
const task = path;

// Combine each development path with a task
return gulp.watch(gulp.paths[path], [path]);
return gulp.watch(gulp.paths[path], [task]);
});
});
44 changes: 44 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
"start": "npm install && bower install && npm run init",
"wp": "gulp wp-install && gulp wp-pre-build && npm run wp:plugins",
"wp:dev": "npm run wp && gulp",
"wp:build": "npm run wp && gulp build && npm run assets-version",
"wp:build": "npm run wp && gulp build && npm run assets-version && npm run inline-css",
"wp:plugins": "cp -r ./plugins ./wordpress/wp-content",
"inline-css": "gulp inline-css",
"assets-version": "gulp asssets-new-version"
},
"sasslintConfig": "sass-lint.yml",
Expand All @@ -46,6 +47,7 @@
"gulp-main-bower-files": "^1.6.2",
"gulp-plumber": "^1.2.0",
"gulp-rename": "^1.2.2",
"gulp-replace": "^0.6.1",
"gulp-sass": "^4.0.1",
"gulp-sass-lint": "^1.3.4",
"gulp-sourcemaps": "^2.6.4",
Expand Down
9 changes: 9 additions & 0 deletions src/css/first-view.sass
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// tools
@import "tools/mixins"

// settings
@import "settings/colors"
@import "settings/measures"

// components
@import "components/header"
1 change: 0 additions & 1 deletion src/css/main.sass
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
@import "elements/buttons"

// components
@import "components/header"
@import "components/footer"
@import "components/menu"

Expand Down
4 changes: 4 additions & 0 deletions src/footer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<script src="<?php echo get_bloginfo('template_url') ?>/js/libs.min.js" defer></script>
<script src="<?php echo get_bloginfo('template_url') ?>/js/main.min.js" defer></script>
</body>
</html>
14 changes: 14 additions & 0 deletions src/header.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<title>Grão de Milho</title>

<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

<link inject-first-view-css href="<?php echo get_bloginfo('template_url') ?>/css/first-view.min.css" rel="stylesheet">

<link href="<?php echo get_bloginfo('template_url') ?>/css/libs.min.css" rel="stylesheet"/>
<link href="<?php echo get_bloginfo('template_url') ?>/css/main.min.css" rel="stylesheet"/>
</head>
<body>
17 changes: 7 additions & 10 deletions src/index.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<strong>It works!</strong>
</body>
</html>
<?php get_header() ?>

<main>

</main>

<?php get_footer() ?>
22 changes: 22 additions & 0 deletions tasks/inline-css.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const fs = require('fs');
const gulp = require('gulp');
const replace = require('gulp-replace');
const browserSync = require('browser-sync');

gulp.task('inline-css', function() {
const file = `${gulp.paths.stylesDest}/first-view.min.css`;

if (!fs.existsSync(file)) {
return false;
}

const inject = /<link\s*inject-first-view-css\s*(.*\>?)>/gi;
const comments = /\/\*[^*]*.*?\*\//;

const css = fs.readFileSync(file, 'utf8');
const style = css.replace(comments, '').trim();

return gulp.src([`${gulp.paths.pagesDest}**/*.php`])
.pipe(replace(inject, () => `<style>${style}</style>`))
.pipe(gulp.dest(gulp.paths.themesWp));
});

0 comments on commit 7e8de24

Please sign in to comment.