mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-16 19:21:52 +00:00
fix issue #2894: sort alphabetical will now parse float values starting at all titles and compare these.
This commit is contained in:
committed by
Junyoung Choi
parent
12229a1719
commit
5b63bedc0d
@@ -26,11 +26,30 @@ const { remote } = require('electron')
|
|||||||
const { dialog } = remote
|
const { dialog } = remote
|
||||||
const WP_POST_PATH = '/wp/v2/posts'
|
const WP_POST_PATH = '/wp/v2/posts'
|
||||||
|
|
||||||
|
const matchStartingTitleNumber = new RegExp('^([0-9]*\.?[0-9]+).*$')
|
||||||
|
|
||||||
function sortByCreatedAt (a, b) {
|
function sortByCreatedAt (a, b) {
|
||||||
return new Date(b.createdAt) - new Date(a.createdAt)
|
return new Date(b.createdAt) - new Date(a.createdAt)
|
||||||
}
|
}
|
||||||
|
|
||||||
function sortByAlphabetical (a, b) {
|
function sortByAlphabetical (a, b) {
|
||||||
|
const matchA = matchStartingTitleNumber.exec(a.title)
|
||||||
|
const matchB = matchStartingTitleNumber.exec(b.title)
|
||||||
|
|
||||||
|
if (matchA && matchA.length === 2 && matchB && matchB.length === 2) {
|
||||||
|
// Both note titles are starting with a float. We will compare it now.
|
||||||
|
const floatA = parseFloat(matchA[1])
|
||||||
|
const floatB = parseFloat(matchB[1])
|
||||||
|
|
||||||
|
if (floatA < floatB) {
|
||||||
|
return -1
|
||||||
|
} else if (floatA > floatB) {
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
// The float values are equal. We will compare the full title.
|
||||||
|
}
|
||||||
|
|
||||||
return a.title.localeCompare(b.title)
|
return a.title.localeCompare(b.title)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user