From 3833fee7252ded6a5b32609a519f616ded4ea903 Mon Sep 17 00:00:00 2001 From: Alan Hemmings Date: Thu, 15 Feb 2024 12:00:27 +0000 Subject: [PATCH] Exclude cloudflare server side directories --- .gitignore | 2 ++ packages/nuekit/src/nuefs.js | 4 ++-- packages/nuekit/test/nuekit.test.js | 19 ++++++++++++------- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index a2684b4e..1d2a69b1 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ node_modules dist .idea +.vscode +_test \ No newline at end of file diff --git a/packages/nuekit/src/nuefs.js b/packages/nuekit/src/nuefs.js index 0cadbea2..01c1fca9 100644 --- a/packages/nuekit/src/nuefs.js +++ b/packages/nuekit/src/nuefs.js @@ -67,8 +67,8 @@ export async function fswalk(root, _dir='', _ret=[]) { return _ret } - -const IGNORE = ['node_modules', 'package.json', 'bun.lockb', 'pnpm-lock.yaml'] +const CLOUDFLARE_SERVERSIDE_DIRS = [ `functions` ] +const IGNORE = ['node_modules', 'package.json', 'bun.lockb', 'pnpm-lock.yaml', ... CLOUDFLARE_SERVERSIDE_DIRS] function ignore(name='') { return '._'.includes(name[0]) || IGNORE.includes(name) diff --git a/packages/nuekit/test/nuekit.test.js b/packages/nuekit/test/nuekit.test.js index 30530704..8f4d9c23 100644 --- a/packages/nuekit/test/nuekit.test.js +++ b/packages/nuekit/test/nuekit.test.js @@ -14,11 +14,11 @@ expect.extend({ toMatchPath }) const root = '_test' // setup and teardown -beforeAll(async () => { +beforeEach(async () => { await fs.rm(root, { recursive: true, force: true }) await fs.mkdir(root, { recursive: true }) }) -afterAll(async () => await fs.rm(root, { recursive: true, force: true })) +afterEach(async () => await fs.rm(root, { recursive: true, force: true })) // helper function for creating files to the root directory async function write(path, content='') { @@ -129,18 +129,23 @@ test('content collection', async () => { await write('blog/first-b.md', createFront('Second', '2020-01-04')) await write('blog/nested/hey1.md', createFront('Third', '2020-01-02')) await write('blog/nested/hey2.md', createFront('Fourth', '2020-01-03')) - + // 4. Cloudflare `functions` directory is excluded + await write('blog/functions/contact-us.md', "my secret notes") + // 5. System files starting with '_' or '.' are excluded. + await write('blog/.item6.md', createFront('Sixth', '2020-01-03')) + await write('blog/_item7.md', createFront('Seventh', '2020-01-03')) + const site = await getSite() const coll = await site.getContentCollection('blog') const actual = coll.map(c => { return { pubDate: c.pubDate, url: c.url, title: c.title, dir: c.dir, slug: c.slug } }) - // expected order is : First, Second, Fourth, Third. + // expected order is : First, Second, Fourth, Third expect(actual).toEqual([ { pubDate: undefined, url: '/blog/first-a.html', title: 'First', dir: 'blog', slug: 'first-a.html' }, - { pubDate: new Date('2020-01-04T00:00:00.000Z'), url: '/blog/first-b.html', title: 'Second', dir: 'blog', slug: 'first-b.html' }, - { pubDate: new Date('2020-01-03T00:00:00.000Z'), url: '/blog/nested/hey2.html', title: 'Fourth', dir: 'blog/nested', slug: 'hey2.html' }, - { pubDate: new Date('2020-01-02T00:00:00.000Z'), url: '/blog/nested/hey1.html', title: 'Third', dir: 'blog/nested', slug: 'hey1.html' }, + { pubDate: new Date('2020-01-04'), url: '/blog/first-b.html', title: 'Second', dir: 'blog', slug: 'first-b.html' }, + { pubDate: new Date('2020-01-03'), url: '/blog/nested/hey2.html', title: 'Fourth', dir: 'blog/nested', slug: 'hey2.html' }, + { pubDate: new Date('2020-01-02'), url: '/blog/nested/hey1.html', title: 'Third', dir: 'blog/nested', slug: 'hey1.html' }, ]) })