Skip to content

Commit

Permalink
some linting + use abe publish date (not file save date)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaslabbe committed Sep 29, 2016
1 parent 67e4d1e commit 18ce39f
Show file tree
Hide file tree
Showing 14 changed files with 34 additions and 55 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Expand Up @@ -24,7 +24,7 @@
"error",
"never"
],
"no-console":["warn"],
"no-console":0,
"no-unused-vars":["warn"],
"no-undef":["warn"],
"no-redeclare":["warn"],
Expand Down
12 changes: 2 additions & 10 deletions src/cli/Create.js
@@ -1,17 +1,9 @@
import fse from 'fs-extra'
import mkdirp from 'mkdirp'
import {Promise} from 'es6-promise'
import slug from 'limax'

import {
config,
cli,
log,
folderUtils,
fileUtils,
FileParser,
fileAttr,
getAttr
config
} from './'

export default class Create {
Expand All @@ -37,7 +29,7 @@ export default class Create {
}

addFolder(folder){
var p = new Promise((resolve, reject) => {
var p = new Promise((resolve) => {
mkdirp(folder)
resolve()
})
Expand Down
13 changes: 7 additions & 6 deletions src/cli/controllers/Save.js
Expand Up @@ -60,7 +60,7 @@ export function save(url, tplPath, json = null, text = '', type = '', previousSa

url = cleanSlug(url)

var p = new Promise((resolve, reject) => {
var p = new Promise((resolve) => {
var isRejectedDoc = false
if(type === 'reject'){
isRejectedDoc = true
Expand Down Expand Up @@ -103,13 +103,14 @@ export function save(url, tplPath, json = null, text = '', type = '', previousSa
if(typeof json[meta].publish !== 'undefined' && json[meta].publish !== null) {
date = json[meta].publish.date
}
}
if(typeof date === 'undefined' || date === null || date === '') {
date = new Date()
}else {
date = new Date(date)
if(typeof date === 'undefined' || date === null || date === '') {
date = new Date()
}else {
date = new Date(date)
}
Util.addMetas(tpl, json, type, {}, date, realType)
}
Util.addMetas(tpl, json, type, {}, date, realType)

if(typeof text === 'undefined' || text === null || text === '') {
text = getTemplate(fullTpl)
Expand Down
7 changes: 3 additions & 4 deletions src/cli/handlebars/abe/abeImport.js
Expand Up @@ -5,23 +5,22 @@ import path from 'path'
import {
Plugins
,fileUtils
,config
,Hooks
} from '../../'

export default function abeImport (file, config, ctx) {
file = Hooks.instance.trigger('beforeImport', file, config, ctx)

var config = JSON.parse(config)
config = JSON.parse(config)
let intlData = config.intlData
var defaultPartials = `${__dirname.replace(/\/$/,'')}/${config.defaultPartials.replace(/\/$/,'')}`
var custom = (config.custom !== '') ? `${config.root.replace(/\/$/,'')}/${config.custom.replace(/\/$/,'')}` : defaultPartials
var pathToPartial = `${custom}/${file}.html`
try{
var stat = fse.statSync(pathToPartial)
fse.statSync(pathToPartial)
}
catch(e){
var pathToPartial = `${defaultPartials}/${file}.html`
pathToPartial = `${defaultPartials}/${file}.html`
}
if (fileUtils.isFile(pathToPartial)) {
var html = fse.readFileSync(pathToPartial, 'utf8')
Expand Down
15 changes: 9 additions & 6 deletions src/cli/handlebars/abe/compileAbe.js
Expand Up @@ -13,12 +13,15 @@ import {
export default function compileAbe(){
var content = abeEngine.instance.content
if(typeof arguments[0].hash['key'] === 'undefined' || arguments[0].hash['key'] === null) return ''
var key
var hash
var value
var testXSS
if(arguments[0].hash['key'].indexOf('}-') > 0){
var key = arguments[0].hash['key'].split('-')
key = arguments[0].hash['key'].split('-')
key = key[key.length - 1]
var hash = arguments[0].hash
hash = arguments[0].hash
hash.key = hash.key.replace(/\{\{@index\}\}/, '[{{@index}}]')
var value
try{
value = content ? content[hash['dictionnary']][arguments[0].data.index][key] : hash.key
}
Expand All @@ -29,7 +32,7 @@ export default function compileAbe(){
value = ''
}
if(typeof hash.type !== 'undefined' && hash.type !== null && hash.type === 'rich'){
var testXSS = xss(value.replace(/"/g, '"'), {
testXSS = xss(value.replace(/"/g, '"'), {
'whiteList': config.htmlWhiteList,
stripIgnoreTag: true
})
Expand All @@ -38,7 +41,7 @@ export default function compileAbe(){
return value.replace(/%27/, '\'')
}

var key = arguments[0].hash['key'].replace('.', '-')
key = arguments[0].hash['key'].replace('.', '-')

var hash = arguments[0].hash
var value = ((content) ? content[hash.key.replace('.', '-')] : hash.key)
Expand All @@ -47,7 +50,7 @@ export default function compileAbe(){
}

if(typeof hash.type !== 'undefined' && hash.type !== null && hash.type === 'rich'){
var testXSS = xss(value.replace(/"/g, '"'), {
testXSS = xss(value.replace(/"/g, '"'), {
'whiteList': config.htmlWhiteList,
stripIgnoreTag: true
})
Expand Down
6 changes: 6 additions & 0 deletions src/cli/helpers/file-parser.js
Expand Up @@ -404,6 +404,12 @@ export default class FileParser {
var cleanFile = file
var json = FileParser.getJson(file.path)

if(typeof json.abe_meta.latest !== 'undefined' && json.abe_meta.latest !== null
&& typeof json.abe_meta.latest !== 'undefined' && json.abe_meta.latest !== null
&& typeof json.abe_meta.latest.date !== 'undefined' && json.abe_meta.latest.date !== null) {
file.date = json.abe_meta.latest.date
}

if(typeof json.abe_meta !== 'undefined' && json.abe_meta !== null) {
var date = null
if (typeof json.abe_meta.latest !== 'undefined' && json.abe_meta.latest !== null
Expand Down
20 changes: 2 additions & 18 deletions src/server/routes/get-main.js
@@ -1,32 +1,16 @@
import express from 'express'
import fs from 'fs'
import fse from 'fs-extra'
import mkdirp from 'mkdirp'
import {minify} from 'html-minifier'
import extend from 'extend'
import * as abe from '../../cli'
import xss from 'xss'
import pkg from '../../../package'
import clc from 'cli-color'
import path from 'path'

import {
fileAttr,
Util,
FileParser,
fileUtils,
folderUtils,
config,
cli,
log,
Page,
Locales,
abeProcess,
getTemplate,
Hooks,
Plugins,
Handlebars,
cleanSlug,
Manager
} from '../../cli'

Expand Down Expand Up @@ -58,7 +42,7 @@ var route = function(req, res, next) {

var isHome = true

let p = new Promise((resolve, reject) => {
let p = new Promise((resolve) => {

if(templatePath !== null && filePath !== null) {
var jsonPath = null
Expand Down Expand Up @@ -174,7 +158,7 @@ var route = function(req, res, next) {
abeVersion: pkg.version,
nonce: '\'nonce-' + res.locals.nonce + '\''
}
var EditorVariables = Hooks.instance.trigger('afterVariables', EditorVariables)
EditorVariables = Hooks.instance.trigger('afterVariables', EditorVariables)

if (debugJson) {
var dj = _json
Expand Down
2 changes: 1 addition & 1 deletion src/server/routes/get-republish.js
Expand Up @@ -2,7 +2,7 @@ import {
abeProcess
} from '../../cli'

var route = function(req, res, next) {
var route = function(req, res) {
abeProcess('publish-all', [''])

var result = {
Expand Down
2 changes: 0 additions & 2 deletions src/server/routes/get-update.js
@@ -1,6 +1,5 @@
import {
abeDuplicate,
log,
Hooks
} from '../../cli'

Expand All @@ -24,7 +23,6 @@ var route = function(req, res, next) {
res.set('Content-Type', 'application/json')
res.send(JSON.stringify(result))
}).catch(function(e) {
reject()
console.error(e)
})
}
Expand Down
2 changes: 1 addition & 1 deletion src/server/routes/post-publish.js
Expand Up @@ -11,7 +11,7 @@ var route = function(req, res, next){
if(typeof res._header !== 'undefined' && res._header !== null) return

var filePath = cleanSlug(req.body.filePath)
var p = new Promise((resolve, reject) => {
var p = new Promise((resolve) => {
save(
fileUtils.getFilePath(filePath),
req.body.tplPath,
Expand Down
2 changes: 1 addition & 1 deletion src/server/routes/post-reject.js
Expand Up @@ -9,7 +9,7 @@ var route = function(req, res, next){
Hooks.instance.trigger('beforeRoute', req, res, next)
if(typeof res._header !== 'undefined' && res._header !== null) return

var p = new Promise((resolve, reject) => {
var p = new Promise((resolve) => {
save(
fileUtils.getFilePath(req.body.filePath),
req.body.tplPath,
Expand Down
2 changes: 0 additions & 2 deletions src/server/routes/post-upload.js
Expand Up @@ -3,7 +3,6 @@ import fse from 'fs-extra'
import mkdirp from 'mkdirp'

import {
fileUtils,
config,
Hooks,
cleanSlug
Expand All @@ -21,7 +20,6 @@ var route = function(req, res, next){
var folderFilePath = path.join(config.root, config.publish.url, folderWebPath)
mkdirp.sync(folderFilePath)
req.pipe(req.busboy)
var size = 0
var hasError = false
req.busboy.on('file', function (fieldname, file, filename, encoding, mimetype) {
var ext = filename.split('.')
Expand Down
2 changes: 0 additions & 2 deletions src/tasks/nodemon.js
@@ -1,6 +1,4 @@
var nodemon = require('nodemon')
var watch = require('watch')
var fs = require('fs')
var clc = require('cli-color')

// NODE_ENV=development nodemon --exec npm run babel-app src/server/app.js --kill-others
Expand Down
2 changes: 1 addition & 1 deletion src/tasks/sass.js
Expand Up @@ -4,7 +4,7 @@ var clc = require('cli-color')

var output = './src/server/public/css/styles.css'

var result = sass.render({
sass.render({
file: './src/server/sass/styles.scss',
outputStyle: 'compressed',
outFile: output,
Expand Down

0 comments on commit 18ce39f

Please sign in to comment.