fix: search not indexing properly + cjk/arabic validators

This commit is contained in:
NGPixel 2017-05-14 11:24:05 -04:00
parent 8f974a3ac7
commit f5aa726cd5
12 changed files with 26 additions and 23 deletions

View File

@ -1,8 +1,8 @@
'use strict' 'use strict'
module.exports = { module.exports = {
arabic: /([\u0600-\u06ff]|[\u0750-\u077f]|[\ufb50-\ufc3f]|[\ufe70-\ufefc])/, arabic: '\u0600-\u06ff\u0750-\u077f\ufb50-\ufc3f\ufe70-\ufefc',
cjk: /([\u4E00-\u9FBF]|[\u3040-\u309F\u30A0-\u30FF]|[ㄱ-ㅎ가-힣ㅏ-ㅣ])/, cjk: '\u4E00-\u9FBF\u3040-\u309F\u30A0-\u30FFㄱ-ㅎ가-힣ㅏ-ㅣ',
youtube: /(?:(?:youtu\.be\/|v\/|vi\/|u\/\w\/|embed\/)|(?:(?:watch)?\?v(?:i)?=|&v(?:i)?=))([^#&?]*).*/, youtube: /(?:(?:youtu\.be\/|v\/|vi\/|u\/\w\/|embed\/)|(?:(?:watch)?\?v(?:i)?=|&v(?:i)?=))([^#&?]*).*/,
vimeo: /vimeo.com\/(?:channels\/(?:\w+\/)?|groups\/(?:[^/]*)\/videos\/|album\/(?:\d+)\/video\/|)(\d+)(?:$|\/|\?)/, vimeo: /vimeo.com\/(?:channels\/(?:\w+\/)?|groups\/(?:[^/]*)\/videos\/|album\/(?:\d+)\/video\/|)(\d+)(?:$|\/|\?)/,
dailymotion: /(?:dailymotion\.com(?:\/embed)?(?:\/video|\/hub)|dai\.ly)\/([0-9a-z]+)(?:[-_0-9a-zA-Z]+(?:#video=)?([a-z0-9]+)?)?/ dailymotion: /(?:dailymotion\.com(?:\/embed)?(?:\/video|\/hub)|dai\.ly)\/([0-9a-z]+)(?:[-_0-9a-zA-Z]+(?:#video=)?([a-z0-9]+)?)?/

View File

@ -12,7 +12,7 @@ const fs = Promise.promisifyAll(require('fs-extra'))
const path = require('path') const path = require('path')
const _ = require('lodash') const _ = require('lodash')
const validPathRe = new RegExp('^(([a-z0-9/-]|' + appdata.regex.cjk.source + ')+\\.[a-z0-9]+)$') const validPathRe = new RegExp('^([a-z0-9/-' + appdata.regex.cjk + appdata.regex.arabic + ']+\\.[a-z0-9]+)$')
const validPathThumbsRe = new RegExp('^([a-z0-9]+\\.png)$') const validPathThumbsRe = new RegExp('^([a-z0-9]+\\.png)$')
// ========================================== // ==========================================

View File

@ -14,7 +14,7 @@ module.exports = {
*/ */
parsePath (urlPath) { parsePath (urlPath) {
urlPath = qs.unescape(urlPath) urlPath = qs.unescape(urlPath)
let wlist = new RegExp('(?!([^a-z0-9]|' + appdata.regex.cjk.source + '|[/-]))', 'g') let wlist = new RegExp('[^a-z0-9' + appdata.regex.cjk + appdata.regex.arabic + '/-]', 'g')
urlPath = _.toLower(urlPath).replace(wlist, '') urlPath = _.toLower(urlPath).replace(wlist, '')

View File

@ -6,7 +6,7 @@ const _ = require('lodash')
module.exports = { module.exports = {
sanitizeCommitUser (user) { sanitizeCommitUser (user) {
let wlist = new RegExp('(?!([^a-zA-Z0-9-_.\',& ]|' + appdata.regex.cjk.source + '))', 'g') let wlist = new RegExp('[^a-zA-Z0-9-_.\',& ' + appdata.regex.cjk + appdata.regex.arabic + ']', 'g')
return { return {
name: _.chain(user.name).replace(wlist, '').trim().value(), name: _.chain(user.name).replace(wlist, '').trim().value(),
email: appconfig.git.showUserEmail ? user.email : appconfig.git.serverEmail email: appconfig.git.showUserEmail ? user.email : appconfig.git.serverEmail

View File

@ -266,6 +266,10 @@ module.exports = {
}, { }, {
new: true, new: true,
upsert: true upsert: true
}).then(result => {
let plainResult = result.toObject()
plainResult.text = content.text
return plainResult
}) })
}).then(result => { }).then(result => {
return self.updateTreeInfo().then(() => { return self.updateTreeInfo().then(() => {

View File

@ -154,7 +154,7 @@ module.exports = {
*/ */
validateUploadsFilename (f, fld, isImage) { validateUploadsFilename (f, fld, isImage) {
let fObj = path.parse(f) let fObj = path.parse(f)
let fname = _.chain(fObj.name).trim().toLower().kebabCase().value().replace(new RegExp('(?!([^a-z0-9-]|' + appdata.regex.cjk.source + '))', 'g'), '') let fname = _.chain(fObj.name).trim().toLower().kebabCase().value().replace(new RegExp('[^a-z0-9-' + appdata.regex.cjk + appdata.regex.arabic + ']', 'g'), '')
let fext = _.toLower(fObj.ext) let fext = _.toLower(fObj.ext)
if (isImage && !_.includes(['.jpg', '.jpeg', '.png', '.gif', '.webp'], fext)) { if (isImage && !_.includes(['.jpg', '.jpeg', '.png', '.gif', '.webp'], fext)) {

View File

@ -87,6 +87,10 @@ const videoRules = [
} }
] ]
// Non-markdown filter
const textRegex = new RegExp('\\b[a-z0-9-.,' + appdata.regex.cjk + appdata.regex.arabic + ']+\\b', 'g')
/** /**
* Parse markdown content and build TOC tree * Parse markdown content and build TOC tree
* *
@ -290,20 +294,15 @@ const parseMeta = (content) => {
* @return {String} Text-only version * @return {String} Text-only version
*/ */
const removeMarkdown = (content) => { const removeMarkdown = (content) => {
return mdRemove(_.chain(content) return _.join(mdRemove(_.chain(content)
.replace(/<!-- ?([a-zA-Z]+):(.*)-->/g, '') .replace(/<!-- ?([a-zA-Z]+):(.*)-->/g, '')
.replace(/```[^`]+```/g, '') .replace(/```([^`]|`)+?```/g, '')
.replace(/`[^`]+`/g, '') .replace(/`[^`]+`/g, '')
.replace(new RegExp('(?!mailto:)(?:(?:http|https|ftp)://)(?:\\S+(?::\\S*)?@)?(?:(?:(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[0-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)(?:\\.(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)*(?:\\.(?:[a-z\\u00a1-\\uffff]{2,})))|localhost)(?::\\d{2,5})?(?:(/|\\?|#)[^\\s]*)?', 'g'), '') .replace(new RegExp('(?!mailto:)(?:(?:http|https|ftp)://)(?:\\S+(?::\\S*)?@)?(?:(?:(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[0-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)(?:\\.(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)*(?:\\.(?:[a-z\\u00a1-\\uffff]{2,})))|localhost)(?::\\d{2,5})?(?:(/|\\?|#)[^\\s]*)?', 'g'), '')
.replace(/\r?\n|\r/g, ' ')
.deburr() .deburr()
.toLower() .toLower()
.replace(/(\b([^a-z]+)\b)/g, ' ')
.replace(/[^a-z]+/g, ' ')
.replace(/(\b(\w{1,2})\b(\W|$))/g, '')
.replace(/\s\s+/g, ' ')
.value() .value()
) ).replace(/\r?\n|\r/g, ' ').match(textRegex), ' ')
} }
module.exports = { module.exports = {

View File

@ -92,7 +92,7 @@ module.exports = {
title: content.title, title: content.title,
subtitle: content.subtitle || '', subtitle: content.subtitle || '',
parent: content.parent || '', parent: content.parent || '',
content: content.content || '' content: content.text || ''
}]).then(() => { }]).then(() => {
winston.log('verbose', 'Entry ' + content._id + ' added/updated to search index.') winston.log('verbose', 'Entry ' + content._id + ' added/updated to search index.')
return true return true
@ -160,7 +160,7 @@ module.exports = {
.deburr() .deburr()
.toLower() .toLower()
.trim() .trim()
.replace(/[^a-z0-9 ]/g, '') .replace(/[^a-z0-9 ]/g, ' ')
.value() .value()
let arrTerms = _.chain(terms) let arrTerms = _.chain(terms)
.split(' ') .split(' ')

View File

@ -45,9 +45,9 @@ block adminContent
default: i.icon-warning default: i.icon-warning
= t('auth:providers.' + user.provider) = t('auth:providers.' + user.provider)
label.label= t('admin:profile.membersince') label.label= t('admin:profile.membersince')
p.control= userMoment(user.createdAt).format('LL') p.control= moment(user.createdAt).format('LL')
label.label= t('admin:profile.lastprofileupdate') label.label= t('admin:profile.lastprofileupdate')
p.control= userMoment(user.updatedAt).format('LL') p.control= moment(user.updatedAt).format('LL')
script(type='text/javascript'). script(type='text/javascript').
var usrDataName = "!{user.name}"; var usrDataName = "!{user.name}";

View File

@ -12,7 +12,7 @@ block adminContent
.section-block .section-block
p #{t('admin:settings.currentversion')}: #[strong= sysversion.current] p #{t('admin:settings.currentversion')}: #[strong= sysversion.current]
if sysversion.latest if sysversion.latest
p #{t('admin:settings.latestversion')}: #[strong= sysversion.latest] #[em (Published #{userMoment(sysversion.latestPublishedAt).fromNow()})] p #{t('admin:settings.latestversion')}: #[strong= sysversion.latest] #[em (Published #{moment(sysversion.latestPublishedAt).fromNow()})]
p p
if sysversion.current !== sysversion.latest if sysversion.current !== sysversion.latest
button.button.is-deep-orange(v-on:click='upgrade')= t('admin:settings.upgrade') button.button.is-deep-orange(v-on:click='upgrade')= t('admin:settings.upgrade')

View File

@ -34,8 +34,8 @@ block adminContent
when 'ldap': i.icon-arrow-repeat-outline when 'ldap': i.icon-arrow-repeat-outline
default: i.icon-warning default: i.icon-warning
= t('auth:providers.' + usr.provider) = t('auth:providers.' + usr.provider)
td.is-centered= userMoment(usr.createdAt).format('lll') td.is-centered= moment(usr.createdAt).format('lll')
td.is-centered= userMoment(usr.updatedAt).format('lll') td.is-centered= moment(usr.updatedAt).format('lll')
.form-sections .form-sections
section section
label.label= t('admin:profile.email') label.label= t('admin:profile.email')

View File

@ -41,7 +41,7 @@ block adminContent
when 'ldap': i.icon-arrow-repeat-outline when 'ldap': i.icon-arrow-repeat-outline
default: i.icon-warning default: i.icon-warning
= t('auth:providers.' + usr.provider) = t('auth:providers.' + usr.provider)
td.is-centered= userMoment(usr.createdAt).format('lll') td.is-centered= moment(usr.createdAt).format('lll')
td.is-centered= userMoment(usr.updatedAt).format('lll') td.is-centered= moment(usr.updatedAt).format('lll')
include ../../modals/admin-createuser.pug include ../../modals/admin-createuser.pug