Browse Source

add initial implementation

pull/1/head
Cian Butler 4 years ago
parent
commit
573129c45d
Signed by: butlerx GPG Key ID: B37CA765BAA89170
10 changed files with 2885 additions and 27 deletions
  1. +11
    -0
      .babelrc
  2. +3
    -0
      .eslintignore
  3. +66
    -0
      .eslintrc
  4. +27
    -27
      .gitignore
  5. +1
    -0
      bin/eventJS
  6. +39
    -0
      package.json
  7. +160
    -0
      schema.json
  8. +44
    -0
      src/checkEventJson.js
  9. +51
    -0
      src/generate.js
  10. +2483
    -0
      yarn.lock

+ 11
- 0
.babelrc View File

@@ -0,0 +1,11 @@
{
"presets": [
"es2015"
],
"plugins": [
"add-module-exports",
"transform-object-assign",
"es6-promise",
"transform-async-to-generator"
]
}

+ 3
- 0
.eslintignore View File

@@ -0,0 +1,3 @@
node_modules/
lib/
fixture/

+ 66
- 0
.eslintrc View File

@@ -0,0 +1,66 @@
{
"extends": "standard",
"env": {
"es6": true,
"jest": true,
"browser": true,
"node": true,
"jquery": true
},
"plugins": [
"json"
],
"globals": {
"GENTLY": true,
"start": true
},
"rules": {
"no-console": 0,
"no-multi-spaces": 0,
"comma-dangle": [
"error",
"always-multiline"
],
"key-spacing": [
"error",
{
"multiLine": {
"beforeColon": false,
"afterColon": true
},
"align": {
"beforeColon": false,
"afterColon": true,
"on": "colon",
"mode": "strict"
}
}
],
"indent": [
"error",
2
],
"linebreak-style": [
"error",
"unix"
],
"quotes": [
"error",
"single"
],
"semi": [
"error",
"always"
],
"no-var": [
"error"
],
"prefer-const": [
"error",
{
"destructuring": "any",
"ignoreReadBeforeAssign": false
}
]
}
}

+ 27
- 27
.gitignore View File

@@ -57,7 +57,7 @@ typings/

# dotenv environment variables file
.env
lib

# ---> Dropbox
# Dropbox settings and caches
@@ -81,30 +81,30 @@ typings/
.nfs*

# ---> macOS
*.DS_Store
.AppleDouble
.LSOverride
# Icon must end with two \r
Icon
# Thumbnails
._*
# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent
# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
*.DS_Store
.AppleDouble
.LSOverride
# Icon must end with two \r
Icon
# Thumbnails
._*
# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent
# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk


+ 1
- 0
bin/eventJS View File

@@ -0,0 +1 @@
require('../lib/generate')();

+ 39
- 0
package.json View File

@@ -0,0 +1,39 @@
{
"name": "event-js",
"version": "1.0.0",
"description": "simple static site generator for events",
"main": "index.js",
"author": "butlerx",
"license": "MIT",
"scripts": {
"lint": "eslint .",
"fix": "eslint . --fix",
"build": "babel src --source-maps --out-dir lib",
"build:watch": "babel src --watch --source-maps --out-dir lib"
},
"dependencies": {
"glob": "^7.1.2",
"handlebars": "^4.0.10",
"json-front-matter": "^1.0.0",
"jsonschema": "^1.1.1",
"marked": "^0.3.6"
},
"devDependencies": {
"babel-cli": "6.24.1",
"babel-core": "6.24.1",
"babel-eslint": "7.2.3",
"babel-plugin-add-module-exports": "0.2.1",
"babel-plugin-es6-promise": "1.1.1",
"babel-plugin-syntax-async-functions": "6.13.0",
"babel-plugin-transform-async-to-generator": "6.24.1",
"babel-plugin-transform-object-assign": "6.22.0",
"babel-preset-es2015": "6.24.1",
"eslint": "3.19.0",
"eslint-config-standard": "10.2.1",
"eslint-plugin-import": "^2.2.0",
"eslint-plugin-json": "^1.2.0",
"eslint-plugin-node": "^4.2.2",
"eslint-plugin-promise": "3.5.0",
"eslint-plugin-standard": "3.0.1"
}
}

+ 160
- 0
schema.json View File

@@ -0,0 +1,160 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"title": {
"type": "string",
"minLength": 1,
"default": "Home"
},
"template": {
"type": "string",
"minLength": 1,
"default": "schedule"
},
"location": {
"type": "string",
"minLength": 1,
"default": "Dublin City University"
},
"start": {
"type": "integer",
"multipleOf": 1,
"maximum": 10000,
"minimum": 1,
"exclusiveMaximum": false,
"exclusiveMinimum": false,
"default": 15
},
"end": {
"type": "integer",
"multipleOf": 1,
"maximum": 10000,
"minimum": 1,
"exclusiveMaximum": false,
"exclusiveMinimum": false,
"default": 29
},
"month": {
"type": "string",
"minLength": 1,
"default": "March"
},
"year": {
"type": "integer",
"multipleOf": 1,
"maximum": 10000,
"minimum": 1,
"exclusiveMaximum": false,
"exclusiveMinimum": false,
"default": 2017
},
"live": {
"type": "string",
"minLength": 1,
"default": "2017-03-15T17:00:00"
},
"archive": {
"type": "string",
"minLength": 1,
"default": "false"
},
"video": {
"type": "string",
"minLength": 1,
"default": "https://www.youtube.com/embed/videoseries?list=PLPaLJSHTDMFhbDmyUeik6IHXmzVtWQQxu"
},
"days": {
"type": "array",
"uniqueItems": false,
"items": {
"type": "object",
"properties": {
"day": {
"type": "string",
"minLength": 1,
"default": "Wednesday 29th"
},
"description": {
"type": "string",
"minLength": 1,
"default": "Mobile Development"
},
"events": {
"type": "array",
"uniqueItems": false,
"items": {
"type": "object",
"properties": {
"name": {
"type": "string",
"minLength": 1,
"default": "TBA"
},
"by": {
"type": "string",
"minLength": 1,
"default": "TBA"
},
"time": {
"type": "string",
"minLength": 1,
"default": "17:00"
},
"place": {
"type": "object",
"properties": {
"id": {
"type": "string",
"minLength": 1,
"default": "LG26"
},
"map": {
"type": "string",
"minLength": 1,
"default": "Somewhere in DCU"
}
},
"required": [
"id",
"map"
]
},
"description": {
"type": "string",
"minLength": 1,
"default": "TBA"
}
},
"required": [
"name",
"by",
"time",
"place",
"description"
]
}
}
},
"required": [
"day",
"description",
"events"
]
}
}
},
"required": [
"title",
"template",
"location",
"start",
"end",
"month",
"year",
"live",
"archive",
"video",
"days"
]
}

+ 44
- 0
src/checkEventJson.js View File

@@ -0,0 +1,44 @@
const fs = require('fs');
const glob = require('glob');
const fm = require('json-front-matter');
const path = require('path');
const validate = require('jsonschema').validate;
const config = require(path.join(process.cwd(), 'config.json'));
let schemaPath = '../schema.json';
if (config.schema) {
schemaPath = path.join(process.cwd(), config.schema);
}
const schema = require(schemaPath);

module.exports = {
validate () {
glob(
path.join(process.cwd(), config.source, '*'),
{
ignore: 'node_modules',
},
(err, files) => {
if (err) throw err;
for (const i of files) {
fs.readFile(i, 'utf-8', (err, data) => {
if (err) throw err;
const file = fm.parse(data);
const json = file.attributes;
if (json.template === 'schedule') {
checkJson(i, json);
}
});
}
}
);
},
};

function checkJson (filename, json) {
try {
validate(json, schema, { throwError: true });
} catch (err) {
console.error(filename, err);
process.exit(1);
}
}

+ 51
- 0
src/generate.js View File

@@ -0,0 +1,51 @@
const Handlebars = require('handlebars');
const fs = require('fs');
const path = require('path');
const glob = require('glob');
const fm = require('json-front-matter');
const marked = require('marked');
const checkJson = require('./checkEventJson');
const config = require(path.join(process.cwd(), 'config.json'));
const source = path.join(process.cwd(), config.source || 'source');
const outputDir = path.join(process.cwd(), config.output || 'public');

glob.sync(path.join(process.cwd(), config.helper || 'helper', '**', '*.js')).forEach(file => {
Handlebars.registerHelper(require(path.resolve(file)));
});

function render (template, page, url) {
template = `${template}.hbs`;
const output = Handlebars.compile(fs.readFileSync(path.join(process.cwd(), 'templates', template), 'utf-8'))(page);
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir);
}
let dir = outputDir;
if (url !== 'index') {
dir = path.join(dir, url);
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir);
}
}
fs.writeFile(path.join(dir, 'index.html'), output, 'utf8', err => {
if (err) throw err;
});
}

module.exports = () => {
checkJson.validate();
fs.readdir(source, (err, pages) => {
if (err) throw err;
for (const page of pages) {
const url = path.parse(page).name;
fs.readFile(path.join(source, page), 'utf-8', (err, data) => {
if (err) throw err;
const file = fm.parse(data);
const json = file.attributes;
json.site = config;
json.body = marked(file.body);
render(json.template, json, url);
});
}
});
}


+ 2483
- 0
yarn.lock
File diff suppressed because it is too large
View File


Loading…
Cancel
Save