From 2eaecc948efd7623529db44e9fe08455d148d9cd Mon Sep 17 00:00:00 2001 From: Daniel Lautzenheiser Date: Mon, 17 Apr 2023 11:07:39 -0400 Subject: [PATCH] fix: collection page title for nested paths --- packages/core/dev-test/index.html | 11 +++++++++++ .../src/components/collections/CollectionHeader.tsx | 8 +++----- .../src/components/collections/CollectionRoute.tsx | 1 - 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/packages/core/dev-test/index.html b/packages/core/dev-test/index.html index e7342977..af17dc8c 100644 --- a/packages/core/dev-test/index.html +++ b/packages/core/dev-test/index.html @@ -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', diff --git a/packages/core/src/components/collections/CollectionHeader.tsx b/packages/core/src/components/collections/CollectionHeader.tsx index 34678df2..ab229061 100644 --- a/packages/core/src/components/collections/CollectionHeader.tsx +++ b/packages/core/src/components/collections/CollectionHeader.tsx @@ -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); - 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) { diff --git a/packages/core/src/components/collections/CollectionRoute.tsx b/packages/core/src/components/collections/CollectionRoute.tsx index d746990e..c575a3f1 100644 --- a/packages/core/src/components/collections/CollectionRoute.tsx +++ b/packages/core/src/components/collections/CollectionRoute.tsx @@ -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 ; }