Skip to content

Commit

Permalink
Fix sort settings sometimes not working
Browse files Browse the repository at this point in the history
Fix #304
kyoshino committed Jan 31, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 9ae3320 commit cbedff5
Showing 3 changed files with 8 additions and 5 deletions.
5 changes: 4 additions & 1 deletion src/lib/components/global/main-router.svelte
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@
import WorkflowPage from '$lib/components/workflow/workflow-page.svelte';
import { parseLocation, selectedPageName } from '$lib/services/app/navigation';
import { showAssetOverlay } from '$lib/services/assets';
import { siteConfig } from '$lib/services/config';
import { selectedCollection } from '$lib/services/contents/collection';
import { showContentOverlay } from '$lib/services/contents/draft/editor';
@@ -43,7 +44,9 @@
if (!pageName) {
// Redirect any invalid page to the contents page
window.location.replace(`#/collections/${$selectedCollection?.name}`);
window.location.replace(
`#/collections/${$selectedCollection?.name ?? $siteConfig?.collections[0].name}`,
);
} else if ($selectedPageName !== pageName) {
$selectedPageName = pageName;
}
4 changes: 1 addition & 3 deletions src/lib/services/config/index.js
Original file line number Diff line number Diff line change
@@ -7,7 +7,6 @@ import { get, writable } from 'svelte/store';
import YAML from 'yaml';
import { prefs } from '$lib/services/user/prefs';
import { getI18nConfig } from '$lib/services/contents/i18n';
import { getCollection, selectedCollection } from '$lib/services/contents/collection';
import { allEntryFolders } from '$lib/services/contents';
import { allBackendServices } from '$lib/services/backends';
import { allAssetFolders } from '$lib/services/assets';
@@ -322,10 +321,9 @@ siteConfig.subscribe((config) => {

const _allAssetFolders = [globalAssetFolder, ...collectionAssetFolders];

// `getCollection` depends on `allAssetFolders`
allEntryFolders.set(_allEntryFolders);
allAssetFolders.set(_allAssetFolders);
// `getCollection` depends on `allAssetFolders`
selectedCollection.set(getCollection(collections[0].name));

if (get(prefs).devModeEnabled) {
// eslint-disable-next-line no-console
4 changes: 3 additions & 1 deletion src/lib/services/contents/collection/view.js
Original file line number Diff line number Diff line change
@@ -326,7 +326,9 @@ export const sortFields = derived(

const _collection = /** @type {EntryCollection} */ (collection);
const { fields, default: defaultSort } = getSortableFields(_collection);
const view = get(entryListSettings)?.[_collection.name] ?? { type: 'list', sort: defaultSort };
const view = get(entryListSettings)?.[_collection.name] ?? { type: 'list' };

view.sort ??= defaultSort;

if (_allEntries.every((entry) => !!entry.commitAuthor) && !fields.includes('author')) {
fields.push('commit_author');

0 comments on commit cbedff5

Please sign in to comment.