0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-03-24 23:21:57 -05:00

fix(content): helpful message for DuplicateContentEntry ()

* helpful message for DuplicateContentEntry

* add changeset
This commit is contained in:
Arsh 2023-12-27 17:56:42 +00:00 committed by GitHub
parent 7f7a7f1aea
commit 89a2a07c2e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 3 deletions
.changeset
packages/astro/src

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Improves error message for the case where two similarly named files result in the same content entry.

View file

@ -261,7 +261,12 @@ export async function generateLookupMap({
if (lookupMap[collection]?.entries?.[slug]) {
throw new AstroError({
...AstroErrorData.DuplicateContentEntrySlugError,
message: AstroErrorData.DuplicateContentEntrySlugError.message(collection, slug),
message: AstroErrorData.DuplicateContentEntrySlugError.message(
collection,
slug,
lookupMap[collection]!.entries[slug],
rootRelativePath(root, filePath),
),
hint:
slug !== generatedSlug
? `Check the \`slug\` frontmatter property in **${id}**.`

View file

@ -1292,8 +1292,12 @@ export const DataCollectionEntryParseError = {
export const DuplicateContentEntrySlugError = {
name: 'DuplicateContentEntrySlugError',
title: 'Duplicate content entry slug.',
message: (collection: string, slug: string) => {
return `**${collection}** contains multiple entries with the same slug: \`${slug}\`. Slugs must be unique.`;
message: (collection: string, slug: string, preExisting: string, alsoFound: string) => {
return `**${collection}** contains multiple entries with the same slug: \`${slug}\`. ` +
`Slugs must be unique.\n\n` +
`Entries: \n` +
`- ${preExisting}\n` +
`- ${alsoFound}`;
},
} satisfies ErrorData;