Added CJK support + MathJax display
This commit is contained in:
@@ -13,7 +13,8 @@ const _ = require('lodash')
|
||||
module.exports = (confPaths) => {
|
||||
confPaths = _.defaults(confPaths, {
|
||||
config: './config.yml',
|
||||
data: './app/data.yml'
|
||||
data: './app/data.yml',
|
||||
dataRegex: '../app/regex.js'
|
||||
})
|
||||
|
||||
let appconfig = {}
|
||||
@@ -22,6 +23,7 @@ module.exports = (confPaths) => {
|
||||
try {
|
||||
appconfig = yaml.safeLoad(fs.readFileSync(confPaths.config, 'utf8'))
|
||||
appdata = yaml.safeLoad(fs.readFileSync(confPaths.data, 'utf8'))
|
||||
appdata.regex = require(confPaths.dataRegex)
|
||||
} catch (ex) {
|
||||
console.error(ex)
|
||||
process.exit(1)
|
||||
|
@@ -5,6 +5,7 @@ const path = require('path')
|
||||
const fs = Promise.promisifyAll(require('fs-extra'))
|
||||
const _ = require('lodash')
|
||||
const crypto = require('crypto')
|
||||
const qs = require('querystring')
|
||||
|
||||
/**
|
||||
* Entries Model
|
||||
@@ -163,7 +164,8 @@ module.exports = {
|
||||
* @return {String} Safe entry path
|
||||
*/
|
||||
parsePath (urlPath) {
|
||||
let wlist = new RegExp('[^a-z0-9/-]', 'g')
|
||||
urlPath = qs.unescape(urlPath)
|
||||
let wlist = new RegExp('(?!([^a-z0-9]|' + appdata.regex.cjk.source + '|[/-]))', 'g')
|
||||
|
||||
urlPath = _.toLower(urlPath).replace(wlist, '')
|
||||
|
||||
|
@@ -152,7 +152,7 @@ module.exports = {
|
||||
*/
|
||||
validateUploadsFilename (f, fld, isImage) {
|
||||
let fObj = path.parse(f)
|
||||
let fname = _.chain(fObj.name).trim().toLower().kebabCase().value().replace(/[^a-z0-9-]+/g, '')
|
||||
let fname = _.chain(fObj.name).trim().toLower().kebabCase().value().replace(new RegExp('(?!([^a-z0-9-]|' + appdata.regex.cjk.source + '))', 'g'), '')
|
||||
let fext = _.toLower(fObj.ext)
|
||||
|
||||
if (isImage && !_.includes(['.jpg', '.jpeg', '.png', '.gif', '.webp'], fext)) {
|
||||
|
@@ -51,6 +51,11 @@ var mkdown = md({
|
||||
})
|
||||
.use(mdAttrs)
|
||||
|
||||
if (appconfig) {
|
||||
const mdMathjax = require('markdown-it-mathjax')
|
||||
mkdown.use(mdMathjax())
|
||||
}
|
||||
|
||||
// Rendering rules
|
||||
|
||||
mkdown.renderer.rules.emoji = function (token, idx) {
|
||||
|
Reference in New Issue
Block a user