Compare commits

...

2 Commits

Author SHA1 Message Date
d7d205f502 Problem: we don't support natural language dates in page search
All checks were successful
continuous-integration/drone/push Build is passing
Solution: add natural language date parser and allow to create new pages
2022-01-07 20:58:43 +01:00
3c53e14229 Problem: there are no easy ways to create a page from search
Solution: add create new page option to search results
2022-01-07 20:37:44 +01:00
3 changed files with 33 additions and 1 deletions

View File

@ -1895,6 +1895,14 @@
"integrity": "sha512-p3KULyQg4S7NIHixdwbGX+nFHkoBiA4YQmyWtjb8XngSKV124nJmRysgAeujbUVb15vh+RvFUfCPqU7rXk+hZg==", "integrity": "sha512-p3KULyQg4S7NIHixdwbGX+nFHkoBiA4YQmyWtjb8XngSKV124nJmRysgAeujbUVb15vh+RvFUfCPqU7rXk+hZg==",
"dev": true "dev": true
}, },
"chrono-node": {
"version": "2.3.5",
"resolved": "https://registry.npmjs.org/chrono-node/-/chrono-node-2.3.5.tgz",
"integrity": "sha512-QIWEgXYVn55/Nsgdqbe6inqW+GoK3B6Qtga8AWdpq+nd+mOZVMxa+SGwPq/XjY+nKN+toQGu8KifCPwUkmz2sg==",
"requires": {
"dayjs": "^1.10.0"
}
},
"class-utils": { "class-utils": {
"version": "0.3.6", "version": "0.3.6",
"resolved": "https://registry.npmjs.org/class-utils/-/class-utils-0.3.6.tgz", "resolved": "https://registry.npmjs.org/class-utils/-/class-utils-0.3.6.tgz",
@ -2655,6 +2663,11 @@
"assert-plus": "^1.0.0" "assert-plus": "^1.0.0"
} }
}, },
"dayjs": {
"version": "1.10.7",
"resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.10.7.tgz",
"integrity": "sha512-P6twpd70BcPK34K26uJ1KT3wlhpuOAPoMwJzpsIWUxHZ7wpmbdZL/hQqBDfz7hGurYSa5PhzdhDHtt319hL3ig=="
},
"debug": { "debug": {
"version": "2.6.9", "version": "2.6.9",
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",

View File

@ -8,6 +8,7 @@
"@egjs/hammerjs": "^2.0.17", "@egjs/hammerjs": "^2.0.17",
"axios": "^0.19.2", "axios": "^0.19.2",
"bulma": "^0.7.5", "bulma": "^0.7.5",
"chrono-node": "^2.3.5",
"clipboard": "^2.0.8", "clipboard": "^2.0.8",
"copy-text-to-clipboard": "^2.2.0", "copy-text-to-clipboard": "^2.2.0",
"css-loader": "^3.6.0", "css-loader": "^3.6.0",

View File

@ -1,5 +1,7 @@
import $ from 'jquery' import $ from 'jquery'
import qs from 'querystring'; import qs from 'querystring'
import * as chrono from 'chrono-node'
import moment from 'moment';
function search(element) { function search(element) {
return { return {
@ -20,6 +22,22 @@ function startQuery(query) {
.then(res => res.json()) .then(res => res.json())
.then(data => { .then(data => {
let actualResult = []; let actualResult = [];
actualResult.push({
ref: query,
title: 'Create new page "' + query + '"',
line: 'New page',
text: 'New page',
})
let parseResult = chrono.nl.casual.parse(query)
if (parseResult.length) {
let m = moment(parseResult[0].start.date())
actualResult.push({
ref: m.format('LL').replace(/\s+/g, '_'),
title: m.format('LL'),
line: 'Suggested page',
text: 'Suggested page'
})
}
$.each(data.hits, (key, value) => { $.each(data.hits, (key, value) => {
actualResult.push({ actualResult.push({
ref: value.fields.page, ref: value.fields.page,