5

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.

Hassan Yousuf
  • 751
  • 6
  • 12
  • 24
  • +1 for DirtyF's answer - more detail here: [Jekyll site works locally but not on Github Pages](https://stackoverflow.com/questions/42450554/jekyll-site-works-locally-but-not-on-github-pages/47530487) – naaman Nov 28 '17 at 11:37

1 Answers1

7

In _config.yml, set :

baseurl: /project

Then call your assets with :

<link rel="stylesheet" href="{{ "/assets/css/main.css, " | prepend: site.baseurl }}">
David Jacquel
  • 51,670
  • 6
  • 121
  • 147
  • Well, yes it works locally on GitHub but not locally, if I launch the website locally via `gulp`, I get a "Cannot GET /project-name". How do I make them work for both local and global? – Hassan Yousuf Nov 22 '15 at 16:54
  • What is your github repository url ? – David Jacquel Nov 22 '15 at 17:48
  • 1
    what if you set baseurl to `baseurl: http://name.github.io`? Or, if you are using a project website, you should do this: `baseurl: http://name.github.io/project` AND upload your site to a branch called `gh-pages`, not `master`. Otherwise, GitHub will not build your site. To see the build locally, you can set an empty baseurl: `baseurl: ""` – Virtua Creative Nov 23 '15 at 02:37
  • 1
    Starting from Jekyll 3.3 you can use an URL filter that will automatically prepend `baseurl`: `` – DirtyF Oct 07 '16 at 20:40