diff --git a/.eslintrc.json b/.eslintrc.json index 132eab9..bfccf67 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -3,7 +3,8 @@ "json" ], "env": { - "browser": true + "browser": true, + "jquery": true }, "extends": "eslint:recommended", "rules": { diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..76db03f --- /dev/null +++ b/.travis.yml @@ -0,0 +1,6 @@ +language: node_js +node_js: + - "node" + - "6" + - "5" + - "4" diff --git a/README.md b/README.md index 36d2db2..f65edf2 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ # TechWeek Website +[![Build Status](https://travis-ci.org/redbrick/techweek.dcu.ie.svg?branch=master)](https://travis-ci.org/redbrick/techweek.dcu.ie) This repository contains the Techweek website The website was written to have the Google Material Design look and feel. MaterializeCSS was used to speed up the process. diff --git a/bin/check-event-json b/bin/check-event-json index bc98b77..ef42cef 100755 --- a/bin/check-event-json +++ b/bin/check-event-json @@ -1,15 +1,23 @@ #!/usr/bin/env node -var fs = require("fs"); -var filename = process.argv[2]; +var fs = require('fs'); +var file = process.argv[2]; -if (filename) { +if(file !== undefined && file !== null) { + checkJson(file); +} else { + for(const i of ['events.json', '2015/events.json', '2016/events.json']) { + checkJson(i); + } + process.exit(0); +} + +function checkJson (filename) { try { - JSON.parse(fs.readFileSync(filename, "utf8")); - console.log("Look good"); + JSON.parse(fs.readFileSync(filename, 'utf8')); + console.log(filename + ' looks good'); } catch (err) { console.error(err); + process.exit(1); } -} else { - console.log("Usage: check-event-json events.json"); } diff --git a/gulpfile.js b/gulpfile.js index 08d04bb..d15490f 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -4,8 +4,9 @@ var cleanCSS = require('gulp-clean-css'); var minify = require('gulp-minify'); var rename = require('gulp-rename'); var connect = require('gulp-connect'); +var jsonSchema = require('gulp-json-schema'); -gulp.task('dev', ['compress', 'minify-css', 'less', 'webserver'], function () { +gulp.task('dev', ['compress', 'minify-css', 'less', 'webserver', 'validate'], function () { gulp.watch(['./css/*.less', './js/*.js', './**/*.html'], ['less', 'compress', 'html']); }); @@ -49,4 +50,9 @@ gulp.task('html', function () { .pipe(connect.reload()); }); -gulp.task('default', ['compress', 'minify-css', 'less']); +gulp.task('validate', () => { + return gulp.src(['./events.json', './2016/*.json', '.2015/*.json']) + .pipe(jsonSchema('schema.json')); +}); + +gulp.task('default', ['compress', 'minify-css', 'less', 'validate']); diff --git a/js/main.js b/js/main.js index abed777..31ab7cb 100644 --- a/js/main.js +++ b/js/main.js @@ -42,10 +42,10 @@ var _hour = _minute * 60; var _day = _hour * 24; // setInterval allows you to do certain action every period of time (like cronjob) -setInterval(function(){ +setInterval(function() { // Check is current time + 10 minutes smaller than the starting time - if(now+1000*60*10 < start){ + if(now+1000*60*10 < start) { // If it is, show the box and start counting down $('.countdown').show(400); } else { @@ -53,7 +53,7 @@ setInterval(function(){ // Otherwise, show the livestream and abjust the height of it to be in // 19:6 aspect ratio // When done hiding the countdown show the livestream, make it take 400ms so there is a smooth transition - if(liveActive){ + if(liveActive) { showLive(); } } @@ -74,10 +74,10 @@ setInterval(function(){ }, 1000); // Set the time of the interval, in ms, so 1000 (1s) // Show the livefeed -function showLive(){ +function showLive() { if(!liveShown){ - $('.countdown').hide(400, function(){ - $('.livestream').show(0, function(){ + $('.countdown').hide(400, function() { + $('.livestream').show(0, function() { $('video').height(0); $('video').animate({height: $('video').width() * (9 / 16), display: 'block'}, 1000); }); @@ -87,13 +87,15 @@ function showLive(){ } // Load the events from the file and add them to the page -function loadEvents(days){ +function loadEvents(days) { var ce = $('.card-container__events'); for(var i = 0; i < days.length; i++) { var day = days[i]; - var ds = day.day+'-event'; - var ul = day.day+'-events'; - var de = $('
  • ' + day.day + ' - ' + day.description + '
      ').appendTo(ce); + var ul = day.day + '-events'; + var de = $('
    • +
      ' + day.day + ' - ' + day.description + '
      +
        '); + de.appendTo(ce); for(var j = 0; j < day.events.length; j++) { var event = day.events[j]; @@ -114,7 +116,7 @@ function loadEvents(days){ } } - $('h5').each( function( c ){ + $('h5').each( function( c ) { $(this).css({color: colors[(v+c) % 5]}); }); diff --git a/package.json b/package.json index cda0b3c..01f0dc2 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "This repository contains the Techweek website", "main": "gulpfile.js", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1", + "test": "eslint js/main,js && bin/check-event-json && gulp", "postinstall": "gulp" }, "repository": { @@ -24,6 +24,7 @@ "gulp": "^3.9.1", "gulp-clean-css": "^2.0.12", "gulp-connect": "^5.0.0", + "gulp-json-schema": "^1.0.0", "gulp-less": "^3.1.0", "gulp-minify": "0.0.14", "gulp-rename": "^1.2.2" diff --git a/schema.json b/schema.json new file mode 100644 index 0000000..b272b9f --- /dev/null +++ b/schema.json @@ -0,0 +1,72 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "type": "array", + "uniqueItems": false, + "items": { + "type": "object", + "properties": { + "day": { + "type": "string", + "minLength": 1 + }, + "description": { + "type": "string", + "minLength": 1 + }, + "events": { + "type": "array", + "uniqueItems": false, + "items": { + "type": "object", + "properties": { + "name": { + "type": "string", + "minLength": 1 + }, + "by": { + "type": "string", + "minLength": 1 + }, + "time": { + "type": "string", + "minLength": 1 + }, + "place": { + "type": "object", + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "map": { + "type": "string", + "minLength": 1 + } + }, + "required": [ + "id", + "map" + ] + }, + "description": { + "type": "string", + "minLength": 1 + } + }, + "required": [ + "name", + "by", + "time", + "place", + "description" + ] + } + } + }, + "required": [ + "day", + "description", + "events" + ] + } +}