mirror of
https://github.com/withastro/astro.git
synced 2025-01-27 22:19:04 -05:00
Refine content collection warnings (#10001)
* feat: remove nonexistent collection warning * fix: remove markdown syntax from console.warn * fix: respect configured collections in types when dir is missing * chore: changeset * chore: revert test schema * docs: "Removes" Co-authored-by: Chris Swithinbank <swithinbank@gmail.com> --------- Co-authored-by: Chris Swithinbank <swithinbank@gmail.com>
This commit is contained in:
parent
5759fd9947
commit
748b2e87cd
3 changed files with 13 additions and 29 deletions
7
.changeset/hip-hotels-divide.md
Normal file
7
.changeset/hip-hotels-divide.md
Normal file
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
"astro": minor
|
||||
---
|
||||
|
||||
Removes content collection warning when a configured collection does not have a matching directory name. This should resolve `i18n` collection warnings for Starlight users.
|
||||
|
||||
This also ensures configured collection names are always included in `getCollection()` and `getEntry()` types even when a matching directory is absent. We hope this allows users to discover typos during development by surfacing type information.
|
|
@ -62,7 +62,9 @@ export function createGetCollection({
|
|||
} else {
|
||||
// eslint-disable-next-line no-console
|
||||
console.warn(
|
||||
`The collection **${collection}** does not exist or is empty. Ensure a collection directory with this name exists.`
|
||||
`The collection ${JSON.stringify(
|
||||
collection
|
||||
)} does not exist or is empty. Ensure a collection directory with this name exists.`
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -312,13 +312,6 @@ export async function createContentTypesGenerator({
|
|||
viteServer,
|
||||
});
|
||||
invalidateVirtualMod(viteServer);
|
||||
if (observable.status === 'loaded') {
|
||||
warnNonexistentCollections({
|
||||
logger,
|
||||
contentConfig: observable.config,
|
||||
collectionEntryMap,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
return { init, queueEvent };
|
||||
|
@ -370,6 +363,9 @@ async function writeContentFiles({
|
|||
}) {
|
||||
let contentTypesStr = '';
|
||||
let dataTypesStr = '';
|
||||
for (const [collection, config] of Object.entries(contentConfig?.collections ?? {})) {
|
||||
collectionEntryMap[JSON.stringify(collection)] ??= { type: config.type, entries: {} };
|
||||
}
|
||||
for (const collectionKey of Object.keys(collectionEntryMap).sort()) {
|
||||
const collectionConfig = contentConfig?.collections[JSON.parse(collectionKey)];
|
||||
const collection = collectionEntryMap[collectionKey];
|
||||
|
@ -455,24 +451,3 @@ async function writeContentFiles({
|
|||
typeTemplateContent
|
||||
);
|
||||
}
|
||||
|
||||
function warnNonexistentCollections({
|
||||
contentConfig,
|
||||
collectionEntryMap,
|
||||
logger,
|
||||
}: {
|
||||
contentConfig: ContentConfig;
|
||||
collectionEntryMap: CollectionEntryMap;
|
||||
logger: Logger;
|
||||
}) {
|
||||
for (const configuredCollection in contentConfig.collections) {
|
||||
if (!collectionEntryMap[JSON.stringify(configuredCollection)]) {
|
||||
logger.warn(
|
||||
'content',
|
||||
`The ${bold(configuredCollection)} collection is defined but no ${bold(
|
||||
'content/' + configuredCollection
|
||||
)} folder exists in the content directory. Create a new folder for the collection, or check your content configuration file for typos.`
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue