Skip to content

Commit

Permalink
Clean up entry sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
kyoshino committed Dec 18, 2024
1 parent 4f201c9 commit 442c034
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions src/lib/services/contents/collection/view.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { IndexedDB } from '@sveltia/utils/storage';
import { compare } from '@sveltia/utils/string';
import equal from 'fast-deep-equal';
import { flatten } from 'flat';
import { _, locale as appLocale } from 'svelte-i18n';
import { derived, get, writable } from 'svelte/store';
import { backend } from '$lib/services/backends';
Expand All @@ -10,7 +9,7 @@ import { selectedCollection } from '$lib/services/contents/collection';
import { getEntriesByCollection, selectedEntries } from '$lib/services/contents/collection/entries';
import { getFilesByEntry } from '$lib/services/contents/collection/files';
import { getFieldConfig, getPropertyValue } from '$lib/services/contents/entry/fields';
import { getEntrySummaryFromContent } from '$lib/services/contents/entry/summary';
import { getEntrySummary } from '$lib/services/contents/entry/summary';
import { getDate } from '$lib/services/contents/widgets/date-time/helper';
import { prefs } from '$lib/services/prefs';

Expand Down Expand Up @@ -50,15 +49,13 @@ const sortEntries = (entries, collection, { key, order } = {}) => {
} = collection;

if (key === undefined) {
/**
* Determine the given entry’s title.
* @param {Entry} entry - Entry.
* @returns {string} Determined title.
*/
const getTitle = ({ locales, slug }) =>
getEntrySummaryFromContent(flatten(locales?.[locale]?.content ?? {})) || slug;
const options = { useTemplate: true, allowMarkdown: true };

return _entries.sort((a, b) => getTitle(a).localeCompare(getTitle(b)));
return _entries.sort((a, b) =>
getEntrySummary(collection, a, options).localeCompare(
getEntrySummary(collection, b, options),
),
);
}

const type =
Expand Down

0 comments on commit 442c034

Please sign in to comment.