feat: new page UI + db fixes + installer improvements

This commit is contained in:
Nicolas Giard
2018-08-19 01:22:59 -04:00
parent 04c972c1d0
commit 4bb522f9d9
21 changed files with 357 additions and 182 deletions

View File

@@ -1,60 +0,0 @@
/* global appdata, ROOTPATH */
const crypto = require('crypto')
const path = require('path')
const qs = require('querystring')
const _ = require('lodash')
module.exports = {
/**
* Parse raw url path and make it safe
*
* @param {String} urlPath The url path
* @return {String} Safe entry path
*/
parsePath (urlPath) {
urlPath = qs.unescape(urlPath)
let wlist = new RegExp('[^a-z0-9' + appdata.regex.cjk + appdata.regex.arabic + '/-]', 'g')
urlPath = _.toLower(urlPath).replace(wlist, '')
if (urlPath === '/') {
urlPath = 'home'
}
let urlParts = _.filter(_.split(urlPath, '/'), (p) => { return !_.isEmpty(p) })
return _.join(urlParts, '/')
},
/**
* Gets the full original path of a document.
*
* @param {String} entryPath The entry path
* @return {String} The full path.
*/
getFullPath (entryPath) {
return path.join(appdata.repoPath, entryPath + '.md')
},
/**
* Gets the full cache path of a document.
*
* @param {String} entryPath The entry path
* @return {String} The full cache path.
*/
getCachePath (entryPath) {
return path.join(appdata.cachePath, crypto.createHash('md5').update(entryPath).digest('hex') + '.json')
},
/**
* Gets the entry path from full path.
*
* @param {String} fullPath The full path
* @return {String} The entry path
*/
getEntryPathFromFullPath (fullPath) {
let absRepoPath = path.resolve(ROOTPATH, appdata.repoPath)
return _.chain(fullPath).replace(absRepoPath, '').replace('.md', '').replace(new RegExp('\\\\', 'g'), '/').value()
}
}

30
server/helpers/page.js Normal file
View File

@@ -0,0 +1,30 @@
const qs = require('querystring')
const _ = require('lodash')
module.exports = {
/**
* Parse raw url path and make it safe
*/
parsePath (rawPath) {
let pathObj = {
locale: 'en',
path: 'home',
private: false,
privateNS: ''
}
// Clean Path
rawPath = _.trim(qs.unescape(rawPath))
if (_.startsWith(rawPath, '/')) { rawPath = rawPath.substring(1) }
if (rawPath === '') { rawPath = 'home' }
// Extract Info
let pathParts = _.filter(_.split(rawPath, '/'), p => !_.isEmpty(p))
if (pathParts[0].length === 2) {
pathObj = pathParts[0]
pathParts.shift()
}
pathObj.path = _.join(pathParts, '/')
return pathObj
}
}