-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Content collections] Fix "underscore to ignore" warnings (#6122)
* refactor: fix underscore check * fix: add "ignore list" to always silence log * fix: hide log on file deleted * refactor: move getEntryType to util * test: getEntryType unit * fix: handle all unsupported cases * chore: changeset
- Loading branch information
1 parent
f7f4721
commit 9f22ac3
Showing
5 changed files
with
117 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'astro': patch | ||
--- | ||
|
||
Content collections: Fix accidental "use underscore to ignore" logs for `.DS_Store` files and underscored directory names. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
packages/astro/test/units/content-collections/get-entry-type.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { getEntryType } from '../../../dist/content/utils.js'; | ||
import { expect } from 'chai'; | ||
import { fileURLToPath } from 'node:url'; | ||
|
||
describe('Content Collections - getEntryType', () => { | ||
const contentDir = new URL('src/content/', import.meta.url); | ||
const contentPaths = { | ||
config: new URL('src/content/config.ts', import.meta.url), | ||
}; | ||
|
||
it('Returns "content" for Markdown files', () => { | ||
for (const entryPath of ['blog/first-post.md', 'blog/first-post.mdx']) { | ||
const entry = fileURLToPath(new URL(entryPath, contentDir)); | ||
const type = getEntryType(entry, contentPaths); | ||
expect(type).to.equal('content'); | ||
} | ||
}); | ||
|
||
it('Returns "content" for Markdown files in nested directories', () => { | ||
for (const entryPath of ['blog/2021/01/01/index.md', 'blog/2021/01/01/index.mdx']) { | ||
const entry = fileURLToPath(new URL(entryPath, contentDir)); | ||
const type = getEntryType(entry, contentPaths); | ||
expect(type).to.equal('content'); | ||
} | ||
}); | ||
|
||
it('Returns "config" for config files', () => { | ||
const entry = fileURLToPath(contentPaths.config); | ||
const type = getEntryType(entry, contentPaths); | ||
expect(type).to.equal('config'); | ||
}); | ||
|
||
it('Returns "unsupported" for non-Markdown files', () => { | ||
const entry = fileURLToPath(new URL('blog/robots.txt', contentDir)); | ||
const type = getEntryType(entry, contentPaths); | ||
expect(type).to.equal('unsupported'); | ||
}); | ||
|
||
it('Returns "ignored" for .DS_Store', () => { | ||
const entry = fileURLToPath(new URL('blog/.DS_Store', contentDir)); | ||
const type = getEntryType(entry, contentPaths); | ||
expect(type).to.equal('ignored'); | ||
}); | ||
|
||
it('Returns "ignored" for unsupported files using an underscore', () => { | ||
const entry = fileURLToPath(new URL('blog/_draft-robots.txt', contentDir)); | ||
const type = getEntryType(entry, contentPaths); | ||
expect(type).to.equal('ignored'); | ||
}); | ||
|
||
it('Returns "ignored" when using underscore on file name', () => { | ||
const entry = fileURLToPath(new URL('blog/_first-post.md', contentDir)); | ||
const type = getEntryType(entry, contentPaths); | ||
expect(type).to.equal('ignored'); | ||
}); | ||
|
||
it('Returns "ignored" when using underscore on directory name', () => { | ||
const entry = fileURLToPath(new URL('blog/_draft/first-post.md', contentDir)); | ||
const type = getEntryType(entry, contentPaths); | ||
expect(type).to.equal('ignored'); | ||
}); | ||
}); |