Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/master'
Browse files Browse the repository at this point in the history
Conflicts:
	src/cli/cms/operations/post.js
	src/cli/cms/operations/save.js
  • Loading branch information
nicolaslabbe committed Nov 7, 2016
2 parents 5a74115 + 7fb6c55 commit bcef172
Show file tree
Hide file tree
Showing 31 changed files with 308 additions and 94 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[![Develop Branch Build Status](https://travis-ci.org/AdFabConnect/abejs.svg)](https://travis-ci.org/AdFabConnect/abejs)
[![Build status](https://ci.appveyor.com/api/projects/status/dv6yt84497wseuxc?svg=true)](https://ci.appveyor.com/project/gregorybesson/abejs)
[![Scrutinizer Quality Score](https://scrutinizer-ci.com/g/AdFabConnect/abejs/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/AdFabConnect/abejs/)
[![Coverage Status](https://coveralls.io/repos/github/AdFabConnect/abejs/badge.svg?branch=master)](https://coveralls.io/github/AdFabConnect/abejs?branch=master)
[![Dependency Status](https://www.versioneye.com/user/projects/57ea4badbd6fa600316f9f6c/badge.svg?style=flat-square)](https://www.versioneye.com/user/projects/57ea4badbd6fa600316f9f6c)
Expand All @@ -10,6 +11,11 @@

> Abe is your __static websites generator__ with revolutionnary __self-descriptive__ templates
# Demo
Deploy your own Abe demo on Heroku

[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy?template=https://github.com/abejs/demo)

# Presentation
I've designed this CMS because I wanted to simplify and optimize the way we're creating content. Wordpress is way too complex for what it does. Welcome to ABE (A Better Engine) : This CMS will make you create content in a snap and publish it on the web in no time !

Expand Down
18 changes: 18 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
environment:
matrix:
- nodejs_version: '4'
- nodejs_version: '5'
- nodejs_version: '6'
- nodejs_version: '7'
install:
- ps: Install-Product node $env:nodejs_version
- set CI=true
- npm -g install npm@latest
- set NODE_ENV=PROD
- npm install
matrix:
fast_finish: true
build: off
shallow_clone: true
test_script:
- npm test
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@
"express-secure-handlebars": "^2.1.0",
"express-session": "^1.13.0",
"extend": "^3.0.0",
"fs-extra": "^0.30.0",
"fs-extra": "^1.0.0",
"git-exec": "^0.2.1",
"handlebars": "^4.0.3",
"handlebars-helper-slugify": "^0.3.2",
"handlebars-intl": "^1.1.1",
"helmet": "^2.3.0",
"helmet": "^3.1.0",
"html-minifier": "^3.1.0",
"https": "^1.0.0",
"limax": "^1.4.0",
Expand Down
20 changes: 11 additions & 9 deletions src/cli/cms/data/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,15 @@ export function fromUrl(url) {
}

if(url != null) {

var dir = path.dirname(url).replace(config.root, '')
var filename = path.basename(url)
var link = url.replace(config.root, '')
link = link.replace(/^\//, '').split('/')
link.shift()
link = cmsData.fileAttr.delete('/' + link.join('/').replace(/\/$/, ''))
const dir = path.dirname(url).replace(config.root, '')
const filename = path.basename(url)
const pathDraft = path.join(config.root,config.draft.url,path.sep)
const pathPublish = path.join(config.root,config.publish.url,path.sep)

let link = url.replace(pathDraft, '')
link = link.replace(pathPublish, '')
link = link.replace(new RegExp('\\' + path.sep, 'g'), '/')
link = cmsData.fileAttr.delete('/'+link)

let draft = config.draft.url
let publish = config.publish.url
Expand Down Expand Up @@ -175,10 +177,10 @@ export function getFileObject(pathFile) {
const templateExtension = '.' + config.files.templates.extension

const name = path.basename(pathFile)
const relativePath = pathFile.replace(pathData + '/', '')
const relativePath = pathFile.replace(pathData + path.sep, '')

const parentName = cmsData.fileAttr.delete(name)
const parentRelativePath = cmsData.fileAttr.delete(pathFile).replace(pathData + '/', '')
const parentRelativePath = cmsData.fileAttr.delete(pathFile).replace(pathData + path.sep, '')

const fileData = cmsData.fileAttr.get(name)

Expand Down
48 changes: 21 additions & 27 deletions src/cli/cms/operations/duplicate.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,40 @@ import {
abeExtend,
Manager,
config,
coreUtils,
cmsData,
cmsOperations
} from '../../'

var duplicate = function(oldFilePath, template, newPath, name, req, isUpdate = false) {
var p = new Promise((resolve, reject) => {
abeExtend.hooks.instance.trigger('beforeDuplicate', oldFilePath, template, newPath, name, req, isUpdate)

var json = {}
var revisions = []
var newFilePath = path.join(newPath, name) + '.' + config.files.templates.extension
if(oldFilePath != null) {
var files = Manager.instance.getList()
var fileWithoutExtension = oldFilePath.replace('.' + config.files.templates.extension, '.json')

var doc = null
Array.prototype.forEach.call(files, (file) => {
if (file.path.indexOf(fileWithoutExtension) > -1) {
doc = file
}
})

if(doc.revisions != null) {
revisions = doc.revisions

const duplicate = function(oldPostUrl, template, newPath, name, req, isUpdate = false) {
const p = new Promise((resolve, reject) => {
abeExtend.hooks.instance.trigger('beforeDuplicate', oldPostUrl, template, newPath, name, req, isUpdate)

let json = {}
let revisions = []
const newPostUrl = path.join(newPath, name) + '.' + config.files.templates.extension
if(oldPostUrl != null) {
const files = Manager.instance.getList()
const oldPostDataPath = path.join(config.root, config.data.url, oldPostUrl.replace('.' + config.files.templates.extension, '.json'))
let posts = []
posts = coreUtils.array.filter(files, 'path', oldPostDataPath)

if(posts.length > 0 && posts[0].revisions != null) {
revisions = posts[0].revisions
if(revisions != null && revisions[0] != null) {
json = cmsData.file.get(revisions[0].path)
delete json.abe_meta
}
}

delete json.abe_meta
}

abeExtend.hooks.instance.trigger('afterDuplicate', json, oldFilePath, template, newPath, name, req, isUpdate)
abeExtend.hooks.instance.trigger('afterDuplicate', json, oldPostUrl, template, newPath, name, req, isUpdate)

var pCreate = cmsOperations.create(template, newPath, name, req, json, (isUpdate) ? false : true)
pCreate.then((resSave) => {
if (isUpdate && oldFilePath !== newFilePath) {
abeExtend.hooks.instance.trigger('beforeUpdate', json, oldFilePath, template, newPath, name, req, isUpdate)
cmsOperations.remove.remove(oldFilePath)
if (isUpdate && oldPostUrl !== newPostUrl) {
abeExtend.hooks.instance.trigger('beforeUpdate', json, oldPostUrl, template, newPath, name, req, isUpdate)
cmsOperations.remove.remove(oldPostUrl)
}
resolve(resSave)
},
Expand Down
1 change: 0 additions & 1 deletion src/cli/cms/operations/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ export function publish(filePath, tplPath, json) {

export function unpublish(filePath) {
abeExtend.hooks.instance.trigger('beforeUnpublish', filePath)

var tplUrl = cmsData.file.fromUrl(path.join(config.publish.url, filePath))
if(coreUtils.file.exist(tplUrl.json.path)) {
var json = JSON.parse(JSON.stringify(cmsData.file.get(tplUrl.json.path)))
Expand Down
2 changes: 1 addition & 1 deletion src/cli/cms/operations/remove.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function remove(filePath) {
cmsOperations.remove.removeFile(revision.path, revision.htmlPath)
})

Manager.instance.removePostFromList(filePath)
Manager.instance.removePostFromList(filePath.replace(new RegExp('\\/', 'g'), path.sep))
}

export function removeFile(file, json) {
Expand Down
2 changes: 1 addition & 1 deletion src/cli/cms/reference/reference.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function getFiles(name = '') {
else {
const files = coreUtils.file.getFilesSync(pathToReferences, true, '.json')
Array.prototype.forEach.call(files, (pathFile) => {
var fileName = pathFile.split('/')
const fileName = pathFile.split(path.sep)
res[fileName[fileName.length - 1]] = cmsData.file.get(pathFile)
})
}
Expand Down
5 changes: 2 additions & 3 deletions src/cli/core/manager/Manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ class Manager {
* @param {String} pathFile The full path to the post
*/
updatePostInList(pathFile){
const parentRelativePath = cmsData.fileAttr.delete(pathFile).replace(this._pathData + '/', '')
const parentRelativePath = cmsData.fileAttr.delete(pathFile).replace(this._pathData + path.sep, '')
const found = coreUtils.array.find(this._list, 'parentRelativePath', parentRelativePath)
const json = cmsData.file.get(pathFile)
let merged = {}
Expand Down Expand Up @@ -235,9 +235,8 @@ class Manager {
*/
removePostFromList(pathFile){
let parentRelativePath = cmsData.fileAttr.delete(pathFile)
parentRelativePath = (pathFile.indexOf('/') === 0) ? parentRelativePath.substring(1):parentRelativePath
parentRelativePath = (pathFile.indexOf(path.sep) === 0) ? parentRelativePath.substring(1):parentRelativePath
parentRelativePath = parentRelativePath.replace('.' + config.files.templates.extension, '.json')

this._list = coreUtils.array.removeByAttr(this._list, 'parentRelativePath', parentRelativePath)
}

Expand Down
20 changes: 10 additions & 10 deletions src/cli/core/utils/array.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
* @return {Array} the filtered array
*/
export function filter(arr, attr, value) {
var result = []
var i = 0
var len = arr.length
const len = arr.length
let result = []
let i = 0

for (; i < len; i += 1) {
var elt = arr[i]
let elt = arr[i]

if (elt[attr] == value) {
result.push(element)
result.push(elt)
}
}
return result
Expand All @@ -28,12 +28,12 @@ export function filter(arr, attr, value) {
* @return {Array} the filtered array of indexes
*/
export function find(arr, attr, value) {
var result = []
var i = 0
var len = arr.length
const len = arr.length
let result = []
let i = 0

for (; i < len; i += 1) {
var elt = arr[i]
let elt = arr[i]

if (elt[attr] == value) {
result.push(i)
Expand All @@ -50,7 +50,7 @@ export function find(arr, attr, value) {
* @return {Array} the array with corresponding objects removed
*/
export function removeByAttr(arr, attr, value){
var i = arr.length
let i = arr.length
while (i--){
if(
arr[i] &&
Expand Down
3 changes: 1 addition & 2 deletions src/cli/core/utils/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ export function exist(pathFile) {
}

export function changePath(pathEnv, change) {
pathEnv = pathEnv.replace(config.root, '').replace(/^\//, '').split('/')
pathEnv = pathEnv.split(path.sep).join('/').replace(config.root, '').replace(/^\//, '').split('/')
pathEnv[0] = change

return path.join(config.root, pathEnv.join('/'))
}

Expand Down
2 changes: 1 addition & 1 deletion src/server/public/scripts/modules/EditorInputs.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export default class EditorInputs {
* @return {[type]} [description]
*/
_inputReloadBlur(e) {
if (e.currentTarget.getAttribute('data-autocomplete') !== 'true') {
if (!e.target.parentNode.classList.contains('upload-wrapper') && e.currentTarget.getAttribute('data-autocomplete') !== 'true') {
this.onReload._fire()
}
}
Expand Down
31 changes: 22 additions & 9 deletions src/server/public/scripts/modules/EditorReload.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,36 +53,49 @@ export default class Reload {
}

inject(str) {
var iframe = document.querySelector('#page-template')
var currentIframe = document.querySelector('#page-template')
var sibling = currentIframe.nextElementSibling
var parent = sibling.parentNode
var iframe = document.createElement('iframe')
var scrollTop = (IframeDocument('#page-template').body) ? IframeDocument('#page-template').body.scrollTop : 0;

parent.classList.add('reloading')

iframe.id = 'page-template'
iframe.src = 'about:blank'
iframe.sandbox = 'allow-same-origin allow-scripts allow-popups allow-forms'
iframe.setAttribute('data-iframe-src', document.querySelector('#page-template').getAttribute('data-iframe-src'))

var initIframe = function () {
var iframeBody = IframeDocument('#page-template').body
var scrollTop = iframeBody.scrollTop

var doc = iframe.contentWindow.document
str = str.replace(/<\/head>/, '<base href="/" /></head>')
var template = Handlebars.compile(str, {noEscape: true})
str = template(json)
doc.open()
doc.open('text/html', 'replace')
doc.write(str)
doc.close()

setTimeout(function () {
var iframeDoc = IframeDocument('#page-template')
if(typeof iframeDoc !== 'undefined' && iframeDoc !== null
&& typeof iframeDoc.body !== 'undefined' && iframeDoc.body !== null) {
if(typeof iframeDoc !== 'undefined' && iframeDoc !== null && typeof iframeDoc.body !== 'undefined' && iframeDoc.body !== null) {
iframeDoc.body.scrollTop = scrollTop
}
}, 1000)
}

if(IframeDocument('#page-template').body) initIframe()
else iframe.onload = initIframe;
iframe.onload = function () {
initIframe()
setTimeout(function () { parent.classList.remove('reloading') }, 350)
}

currentIframe.remove()
parent.insertBefore(iframe, sibling);
}

reload() {
var iframe = document.querySelector('#page-template')
var json = JSON.parse(JSON.stringify(this._json.data))
iframe.parentNode.classList.add('reloading')

delete json.abe_source
var data = qs.stringify({
Expand Down
20 changes: 11 additions & 9 deletions src/server/routes/get-main.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import path from 'path'
import xss from 'xss'
import pkg from '../../../package'

Expand Down Expand Up @@ -43,15 +44,10 @@ var route = function(req, res, next) {
let p = new Promise((resolve) => {

if(filePath != null) {
fileName = filePath.split('/')
fileName = fileName[fileName.length-1].replace(`.${config.files.templates.extension}`, '')

folderPath = filePath.split('/')
folderPath.pop()
folderPath = folderPath.join('/')
fileName = path.basename(filePath)
folderPath = path.dirname(filePath)

isHome = false

var filePathTest = cmsData.revision.getDocumentRevision(filePath)
if(typeof filePathTest !== 'undefined' && filePathTest !== null) {
jsonPath = filePathTest.path
Expand Down Expand Up @@ -112,7 +108,12 @@ var route = function(req, res, next) {
var page = new Page(_json.abe_meta.template, text, _json, false)
pageHtml = page.html.replace(/"/g, '"').replace(/'/g, '\'').replace(/<!--/g, '<ABE!--').replace(/-->/g, '--ABE>')
}


var editorWidth = '33%'
req.headers && req.headers.cookie.split(';').forEach(function(cookie) {
var parts = cookie.match(/(.*?)=(.*)$/)
if(parts[1] === 'editorWidth') editorWidth = parts[2]
})
var EditorVariables = {
pageHtml: pageHtml,
isHome: isHome,
Expand All @@ -134,7 +135,8 @@ var route = function(req, res, next) {
req: req
},
abeVersion: pkg.version,
nonce: '\'nonce-' + res.locals.nonce + '\''
nonce: '\'nonce-' + res.locals.nonce + '\'',
editorWidth: editorWidth
}
EditorVariables = abeExtend.hooks.instance.trigger('afterVariables', EditorVariables)

Expand Down
Loading

0 comments on commit bcef172

Please sign in to comment.