Skip to content

Commit 62b0998

Browse files
committed
Ignore Markdown characters when sorting entries
Fix #245 again
1 parent e420c76 commit 62b0998

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/lib/services/contents/view.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ const defaultSortableFields = ['title', 'name', 'date', 'author', 'description']
2626
*/
2727
export const currentView = writable({ type: 'list' });
2828

29+
/**
30+
* Remove some Markdown syntax characters at the beginning of the string for proper sorting. This
31+
* includes bold, italic and code that are parsed if included in the entry summary/title.
32+
* @param {string} str - Original string.
33+
* @returns {string} Modified string.
34+
*/
35+
const removeMarkdownChars = (str) => str.replace(/^[_*`]+/, '');
36+
2937
/**
3038
* Sort the given entries.
3139
* @param {Entry[]} entries - Entry list.
@@ -80,7 +88,7 @@ const sortEntries = (entries, collection, { key, order }) => {
8088
}
8189

8290
if (type === String) {
83-
return compare(aValue, bValue);
91+
return compare(removeMarkdownChars(aValue), removeMarkdownChars(bValue));
8492
}
8593

8694
if (type === Date) {

0 commit comments

Comments
 (0)