fix: collection page title for nested paths

This commit is contained in:
Daniel Lautzenheiser 2023-04-17 11:07:39 -04:00
parent eae0e49642
commit 2eaecc948e
3 changed files with 14 additions and 6 deletions

View File

@ -150,6 +150,17 @@
'index.md': {
content: '---\ntitle: Posts\n---\n',
},
news: {
'hello-world-news': {
'index.md': {
content:
'---\ntitle: Hello World News\n---\nCoffee is a small tree or shrub that grows in the forest understory in its wild form, and traditionally was grown commercially under other trees that provided shade. The forest-like structure of shade coffee farms provides habitat for a great number of migratory and resident species.\n',
},
},
'index.md': {
content: '---\ntitle: News Articles\n---\n',
},
},
},
'index.md': {
content: '---\ntitle: Pages\n---\n',

View File

@ -8,6 +8,7 @@ import {
selectEntryCollectionTitle,
selectFolderEntryExtension,
} from '@staticcms/core/lib/util/collection.util';
import { isNotEmpty } from '@staticcms/core/lib/util/string.util';
import { addFileTemplateFields } from '@staticcms/core/lib/widgets/stringTemplate';
import Button from '../common/button/Button';
@ -47,15 +48,12 @@ const CollectionHeader = ({
return acc;
}, {} as Record<string, Entry>);
const path = filterTerm.split('/');
if (path.length > 0) {
if (isNotEmpty(filterTerm)) {
const extension = selectFolderEntryExtension(collection);
const finalPathPart = path[path.length - 1];
let entry =
entriesByPath[
`${collection.folder}/${finalPathPart}/${collection.nested.path.index_file}.${extension}`
`${collection.folder}/${filterTerm}/${collection.nested.path.index_file}.${extension}`
];
if (entry) {

View File

@ -33,7 +33,6 @@ const CollectionRoute = ({ isSearchResults, isSingleSearchResult }: CollectionRo
const href = window.location.href;
if (!href.includes('noredirect')) {
window.history.replaceState(null, document.title, `${href}?noredirect`);
console.log('REPLACE STATE', document.title, `${href}?noredirect`);
}
return <Navigate to={`/collections/${collection.name}/entries/${collection.files[0].name}`} />;
}