File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -26,11 +26,30 @@ const { remote } = require('electron')
26
26
const { dialog } = remote
27
27
const WP_POST_PATH = '/wp/v2/posts'
28
28
29
+ const matchStartingTitleNumber = new RegExp ( '^([0-9]*\.?[0-9]+).*$' )
30
+
29
31
function sortByCreatedAt ( a , b ) {
30
32
return new Date ( b . createdAt ) - new Date ( a . createdAt )
31
33
}
32
34
33
35
function sortByAlphabetical ( a , b ) {
36
+ const matchA = matchStartingTitleNumber . exec ( a . title )
37
+ const matchB = matchStartingTitleNumber . exec ( b . title )
38
+
39
+ if ( matchA && matchA . length === 2 && matchB && matchB . length === 2 ) {
40
+ // Both note titles are starting with a float. We will compare it now.
41
+ const floatA = parseFloat ( matchA [ 1 ] )
42
+ const floatB = parseFloat ( matchB [ 1 ] )
43
+
44
+ if ( floatA < floatB ) {
45
+ return - 1
46
+ } else if ( floatA > floatB ) {
47
+ return 1
48
+ }
49
+
50
+ // The float values are equal. We will compare the full title.
51
+ }
52
+
34
53
return a . title . localeCompare ( b . title )
35
54
}
36
55
You can’t perform that action at this time.
0 commit comments