Skip to content

Commit

Permalink
Merge pull request #206 from otoyo/update-public-notion-copier
Browse files Browse the repository at this point in the history
Update public-notion-copier
  • Loading branch information
otoyo authored Aug 7, 2024
2 parents a73ab65 + 7ac20b8 commit 734c758
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions src/integrations/public-notion-copier.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,40 @@
import fs from 'node:fs'
import { execSync } from 'child_process'
import path from 'path'
import { fileURLToPath } from 'url'
import type { AstroIntegration } from 'astro'

const copyFiles = (src: string, dest: string) => {
const entries = fs.readdirSync(src, { withFileTypes: true })
if (!fs.existsSync(dest)) {
fs.mkdirSync(dest, { recursive: true })
}

for (const entry of entries) {
const srcPath = path.join(src, entry.name)
const destPath = path.join(dest, entry.name)

if (entry.isDirectory()) {
copyFiles(srcPath, destPath)
} else {
if (!fs.existsSync(destPath)) {
fs.copyFileSync(srcPath, destPath)
}
}
}
}

export default (): AstroIntegration => ({
name: 'public-notion-copier',
hooks: {
'astro:build:done': async ({ dir }) => {
const outDir = new URL('notion', dir.href).pathname
const dirPath = fileURLToPath(dir)
const outDir = path.join(dirPath, 'notion')
if (!fs.existsSync(outDir)) {
fs.mkdirSync(outDir)
fs.mkdirSync(outDir, { recursive: true })
}

execSync(`cp -n -r public/notion/* ${outDir} || true`)
copyFiles('public/notion', outDir)
console.log('Finished copying notion files to root!')
},
},
})

0 comments on commit 734c758

Please sign in to comment.