CSS not loading correctly on Jekyll (GitHub) - css

My github page's css is being generated as
http://name.github.io/project/assets/css/main.css, but in the index.html it points to http://name.github.io/assets/css/main.css
I am using Jekyll with Gulp and SASS. I know this would work fine on a real .com domain but how do I make it correct on GitHub Pages?
My gulpfile.js
var gulp = require('gulp');
var browserSync = require('browser-sync');
var sass = require('gulp-sass');
var prefix = require('gulp-autoprefixer');
var plumber = require('gulp-plumber');
var cp = require('child_process');
var jade = require('gulp-jade');
var messages = {
jekyllBuild: '<span style="color: grey">Running:</span> $ jekyll build'
};
/**
* Build the Jekyll Site
*/
gulp.task('jekyll-build', function (done) {
browserSync.notify(messages.jekyllBuild);
return cp.spawn('jekyll.bat', ['build'], {stdio: 'inherit'})
.on('close', done);
});
/**
* Rebuild Jekyll & do page reload
*/
gulp.task('jekyll-rebuild', ['jekyll-build'], function () {
browserSync.reload();
});
/**
* Wait for jekyll-build, then launch the Server
*/
gulp.task('browser-sync', ['sass', 'jekyll-build'], function() {
browserSync({
server: {
baseDir: '_site'
}
});
});
/**
* Compile files from _scss into both _site/css (for live injecting) and site (for future jekyll builds)
*/
gulp.task('sass', function () {
return gulp.src('assets/css/main.scss')
.pipe(sass({
includePaths: ['css'],
onError: browserSync.notify
}))
.pipe(plumber())
.pipe(prefix(['last 15 versions', '> 1%', 'ie 8', 'ie 7'], { cascade: true }))
.pipe(gulp.dest('_site/assets/css'))
.pipe(browserSync.reload({stream:true}))
.pipe(gulp.dest('assets/css'));
});
/*
* trying to Gulp stuff
*/
gulp.task('jade', function() {
return gulp.src('_jadefiles/*.jade')
.pipe(jade())
.pipe(gulp.dest('_includes'));
})
/**
* Watch scss files for changes & recompile
* Watch html/md files, run jekyll & reload BrowserSync
*/
gulp.task('watch', function () {
gulp.watch('assets/css/**', ['sass']);
gulp.watch('assets/js/**', ['jekyll-rebuild']);
gulp.watch(['index.html', '_layouts/*.html', '_includes/*'], ['jekyll-rebuild']);
gulp.watch(['assets/js/**'], ['jekyll-rebuild']);
gulp.watch('_jadefiles/*.jade', ['jade']);
});
/**
* Default task, running just `gulp` will compile the sass,
* compile the jekyll site, launch BrowserSync & watch files.
*/
gulp.task('default', ['browser-sync', 'watch']);
The _site folder is where all the generated HTML and CSS is. The only solution I can think of is moving the contents from the _site folder to the root of my git repo and deleting everything else that was there before.
In my _config.yml, the basedir is even set to baseurl: github-project-name but still doesn't load.

In _config.yml, set :
baseurl: /project
Then call your assets with :
<link rel="stylesheet" href="{{ "/assets/css/main.css, " | prepend: site.baseurl }}">

Related

Gulp + SASS + BrowserSync don’t work on newly created partials

I’m using a pretty simple setup for Gulp with SASS and BrowserSync.
//require plugins here
// Paths
var styleSRC = './assets/css/style.scss'; // Path to main .scss file.
var styleDestination = './ ';
var styleWatchFiles = './assets/css/**/*.scss';
// BrowserSync
gulp.task('browser-sync', function () {
browserSync.init({
proxy: projectURL,
open: false,
injectChanges: true
});
});
//Task
gulp.task('styles', function () {
gulp.src(styleSRC)
.pipe(sass({
errLogToConsole: true,
}))
.on('error', console.error.bind(console)).pipe(autoprefixer(AUTOPREFIXER_BROWSERS))
.pipe(gulp.dest(styleDestination))
.pipe(browserSync.reload({
stream: true
}));
});
// Watch
gulp.task('default', ['styles', 'browser-sync'], function () {
gulp.watch(styleWatchFiles, ['styles']);
});
The issue is though this setup doesn’t recognize when new partial file is created. So if I create a partial and then add it to style.scss nothing is happening, Sass is not compiled -> so you have manually call the task from the console.
Is it possible to automatically compile Sass when new partial is added?
if you remove './' from the source path it will work the way you would expect it
as far as i know this is a windows only problem
here is a github issue that describes the problem : https://github.com/gulpjs/gulp/issues/1422
should be fixed in gulp 4.x , but thats still in alpha

Why is gulp injecting the css styles in the wrong directory?

I am pretty new to Gulp.
I'm working in a project that uses gulp and when I run gulp serve in the console and make some changes in my sass files, gulp inject the styles in the wrong directory:
[09:39:26] gulp-ruby-sass: write ../../../../../cjdelgado/AppData/Local/Temp/gulp-ruby-sass/index.css
[09:39:26] gulp-ruby-sass: write ../../../../../cjdelgado/AppData/Local/Temp/gulp-ruby-sass/index.css.
And this doesn't happen to my coworkers.
Could this be happening because my node or ruby versions?
Can I change that path manually? And, Should I change it?
This is my gulp file:
/**
* Welcome to your gulpfile!
* The gulp tasks are split into several files in the gulp directory
* because putting it all here was too long
*/
'use strict';
var fs = require('fs');
var gulp = require('gulp');
/**
* This will load all js or coffee files in the gulp directory
* in order to load all gulp tasks
*/
fs.readdirSync('./gulp').filter(function(file) {
return (/\.(js|coffee)$/i).test(file);
}).map(function(file) {
require('./gulp/' + file);
});
/**
* Default task clean temporaries directories and launch the
* main optimization build task
*/
gulp.task('default', ['clean'], function () {
gulp.start('build');
});
And I am running it from:
/c/Users/cjdelgado/Documents/Gitlab/register
And this is my gulp/inject.js file, wich I think the problem could be solved from:
'use strict';
var path = require('path');
var gulp = require('gulp');
var conf = require('./conf');
var $ = require('gulp-load-plugins')();
var wiredep = require('wiredep').stream;
var _ = require('lodash');
var browserSync = require('browser-sync');
gulp.task('inject-reload', ['inject'], function() {
browserSync.reload();
});
gulp.task('inject', ['scripts', 'styles'], function () {
var injectStyles = gulp.src([
path.join(conf.paths.tmp, '/serve/app/**/*.css'),
path.join('!' + conf.paths.tmp, '/serve/app/vendor.css')
], { read: false });
var injectScripts = gulp.src([
path.join(conf.paths.src, '/app/**/*.module.js'),
path.join(conf.paths.src, '/app/**/*.js'),
path.join('!' + conf.paths.src, '/app/**/*.spec.js'),
path.join('!' + conf.paths.src, '/app/**/*.mock.js'),
])
.pipe($.angularFilesort()).on('error', conf.errorHandler('AngularFilesort'));
var injectOptions = {
ignorePath: [conf.paths.src, path.join(conf.paths.tmp, '/serve')],
addRootSlash: false
};
return gulp.src(path.join(conf.paths.src, '/*.html'))
.pipe($.inject(injectStyles, injectOptions))
.pipe($.inject(injectScripts, injectOptions))
.pipe(wiredep(_.extend({}, conf.wiredep)))
.pipe(gulp.dest(path.join(conf.paths.tmp, '/serve')));
});

CSS folder not appearing in sources with Gulp

I'm building a React page and using Gulp. My styles compile correctly to CSS and get saved locally in my destination folder (./build/css) as they should. However, when I inspect the page in the browser, the CSS folder isn't in the build folder, and none of my styles are showing up. Here's my app structure:
| build
|- css
|- style.css
|- images
|- main.js
| css
|- style.styl
| resources
|- images
| scripts
|- components
|- App.js
|- etc...
|- main.js
| gulpfile.js
| index.html
| package.json
And here's my gulpfile:
/*
Styles Task
*/
gulp.task('styles',function() {
// Compiles CSS
gulp.src('css/style.styl')
.pipe(stylus())
.pipe(autoprefixer())
.pipe(gulp.dest('./build/css/'))
.pipe(reload({stream:true}))
});
/*
Images
*/
gulp.task('images',function(){
gulp.src('resources/images/**')
.pipe(cache(imagemin({ optimizationLevel: 5, progressive: true, interlaced: true })))
.pipe(gulp.dest('./build/images/'))
});
/*
Browser Sync
*/
gulp.task('browser-sync', function() {
browserSync({
// we need to disable clicks and forms for when we test multiple rooms
server : {},
middleware : [ historyApiFallback() ],
ghostMode: false
});
});
function handleErrors() {
var args = Array.prototype.slice.call(arguments);
notify.onError({
title: 'Compile Error',
message: '<%= error.message %>'
}).apply(this, args);
this.emit('end'); // Keep gulp from hanging on this task
}
function buildScript(file, watch) {
var props = {
entries: ['./scripts/' + file],
debug : true,
cache: {},
packageCache: {},
transform: [babelify.configure({stage : 0 })]
};
// watchify() if watch requested, otherwise run browserify() once
var bundler = watch ? watchify(browserify(props)) : browserify(props);
function rebundle() {
var stream = bundler.bundle();
return stream
.on('error', handleErrors)
.pipe(source(file))
.pipe(gulp.dest('./build/'))
.pipe(reload({stream:true}))
}
// listen for an update and run rebundle
bundler.on('update', function() {
rebundle();
gutil.log('Rebundle...');
});
// run it once the first time buildScript is called
return rebundle();
}
gulp.task('scripts', function() {
return buildScript('main.js', false); // this will run once because we set watch to false
});
// run 'scripts' task first, then watch for future changes
gulp.task('default', ['images','styles','scripts','resources','browser-sync'], function() {
gulp.watch('css/**/*', ['styles']); // gulp watch for CSS changes
return buildScript('main.js', true); // browserify watch for JS changes
});
Any insight would be greatly appreciated!

Enabling live reload with Grunt on a Vagrant-hosted project

My project uses Vagrant; it's served as https://domain.dev:8443.
The goal is to reload the CSS into the page whenever the CSS changes, without requiring a full page reload.
I am trying to achieve this without any manual action, this means I do not want to use a browser-plugin. Everything should be able to get up and running using the task grunt develop.
grunt-contrib-watch is used to watch 3 different targets, namely css, scss and js. Because these tasks are concurrent, but sadly blocking, I also use grunt-focus to run these 3 tasks at the same time, which correctly works. Whenever changing any file that should be watched, I get a notification in my console that it changed. Awesome.
grunt-contrib-watch recommends connect-livereload, which is middleware for grunt-contrib-connect. This would enable me to get the desired behaviour, but I do not know how to set it up properly.
This is my Gruntfile, note that I did leave out a lot of tasks that are not related to this issue, so it will not run.
module.exports = function(grunt) {
'use strict';
//Load all dependencies that we need
var ConnectLiveReload = require('connect-livereload')();
//Load all packages that we need into Grunt
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-focus');
//The watcher needs a clean object to store data to
var files = Object.create(null);
//Initialize Grunt with the options for all tasks
grunt.initConfig({
connect: {
options: {
port: 0
},
develop: {
options: {
middleware: function(connect) {
return [ConnectLiveReload];
}
}
}
},
focus: {
develop: {}
},
watch: {
scss: {
tasks: ['build'],
files: ['app/webroot/**/*.scss'],
options: {
spawn: false
}
},
css: {
files: ['app/webroot/**/*.css'],
options: {
spawn: false,
livereload: true
}
},
js: {
tasks: ['jasmine:test', 'eslint'],
files: dictionary.javascript,
options: {
spawn: false
}
}
}
});
//Sets the target config for specific tasks 200ms after the last change
var onChange = grunt.util._.debounce(function() {
var target = getTarget();
grunt.config('eslint.target', target);
}, 200);
//Listen to changed files using the watcher
grunt.event.on('watch', function(action, filepath, target) {
files[filepath] = action;
onChange();
});
/**
* Gets the path from the dictionary and adds a JavaScript file selector to it.
*
* #method getPath
* #param [pathkey=webroot]
* #return {String}
*/
function getPath(pathkey) {
pathkey = pathkey || 'webroot';
return (dictionary[pathkey] || pathkey) + '/*.js';
}
/**
* Gets an array of the last-changed files as detected by the watcher.
*
* #method getTarget
* #return {Array}
*/
function getTarget() {
var target = Object.keys(files);
files = Object.create(null);
return target;
}
/**
* #task develop
* #runs watch:css
* #runs watch:scss
* #runs watch:js
*/
grunt.registerTask('develop', 'Start the automated development tasks', function() {
grunt.task.run(['connect:develop', 'focus:develop']);
});
};
http://localhost:35729/livereload.js is a valid file and I can visit in my browser, but the script is not being added to the page. How would I do this?

BrowserSync to inject css into a live Wordpress page via proxy

I am trying to use BrowserSync & sass to edit the style.css from a Wordpress site.
I'd like to inject the changes into the page and reload it automatically.
So far I tried a lot of variants to the gulpfile.js code without success -- the scss files compile into style.css (ok), but the page doesn't reflect the changes.
Here is my code:
var gulp = require('gulp'),
sass = require('gulp-sass'),
bs = require('browser-sync');
// -- sass
//
gulp.task('sass', function () {
return gulp
.src('src/scss/*.scss')
.pipe(sass({ includePaths: [ 'src/scss/include' ] }))
.pipe(gulp.dest('wp-content/themes/my-theme'))
.pipe(bs.reload({ stream: true }));
});
// -- serve
//
gulp.task('serve', [ 'sass' ], function() {
bs({
proxy: "http://my-site.com",
files: "wp-content/themes/my-theme/style.css"
});
gulp.watch( "src/scss/**/*.scss", ['sass'] );
});
For the moment, I resorted to use the awkward Chrome workspace override, but the workflow is not as smooth as it could be.
Thanks in advance

Resources