-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauto.js
43 lines (34 loc) · 1.21 KB
/
auto.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
const fs = require('fs').promises
const path = require('path')
async function splitMarkdown(inputFile, outputDir, chunkSize = 3) {
try {
const content = await fs.readFile(inputFile, 'utf-8')
// 각 편을 분리
const sections = content.split(/(?=# 제 \d+ 편)/).filter((s) => s.trim())
// 청크로 나누기
for (let i = 0; i < sections.length; i += chunkSize) {
const chunk = sections.slice(i, i + chunkSize)
// 파일 이름 생성
// const startNum = parseInt(chunk[0].match(/제 (\d+) 편/)[1])
// const endNum = parseInt(chunk[chunk.length - 1].match(/제 (\d+) 편/)[1])
const index = Math.floor(i / 3) + 1
const filename = `${index}.md`
// 파일 작성
await fs.writeFile(path.join(outputDir, filename), chunk.join('\n\n'))
}
console.log('파일 분할이 완료되었습니다.')
} catch (error) {
console.error('에러 발생:', error)
}
}
// 사용 예
const inputFile = './bible/psalm.md' // 입력 파일 이름
const outputDir = './bible' // 출력 디렉토리
async function main() {
try {
await splitMarkdown(inputFile, outputDir)
} catch (error) {
console.error('메인 함수 에러:', error)
}
}
main()