Skip to content

Commit

Permalink
Merge pull request nuejs#205 from goblinfactory-forks/feature/204-sup…
Browse files Browse the repository at this point in the history
…port-cloudflare-functions

Exclude cloudflare server side directories, closes nuejs#204
  • Loading branch information
tipiirai committed Feb 18, 2024
2 parents afb3af3 + 3833fee commit 671c930
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
node_modules
dist
.idea
.vscode
_test
4 changes: 2 additions & 2 deletions packages/nuekit/src/nuefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
19 changes: 12 additions & 7 deletions packages/nuekit/test/nuekit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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='') {
Expand Down Expand Up @@ -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' },
])
})

Expand Down

0 comments on commit 671c930

Please sign in to comment.