-
Notifications
You must be signed in to change notification settings - Fork 0
/
content.js
59 lines (44 loc) · 1.82 KB
/
content.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const fs = require("fs")
console.log("Starting content export")
const photos = []
const photosSourceFullPath = "./content/photos/full"
const photosSourcePreviewsPath = "./content/photos/previews"
const photosTargetFullPath = "./src/images/full"
const photosTargetPreviewsPath = "./src/images/previews"
const photosExportPath = "./src/_photos.json"
if (!fs.existsSync(photosTargetFullPath)) {
fs.mkdirSync(photosTargetFullPath)
}
if (!fs.existsSync(photosTargetPreviewsPath)) {
fs.mkdirSync(photosTargetPreviewsPath)
}
fs.readdirSync(photosSourceFullPath).forEach(filename => {
fs.writeFileSync(`${photosTargetFullPath}/${filename}`, fs.readFileSync(`${photosSourceFullPath}/${filename}`))
fs.writeFileSync(`${photosTargetPreviewsPath}/${filename}`, fs.readFileSync(`${photosSourcePreviewsPath}/${filename}`))
})
fs.readdirSync(photosSourceFullPath).forEach(filename => {
console.log(`Found photo: ${filename}`)
const baseFileName = filename.replace(/.jpg/g, "")
const slug = baseFileName.replace(/_/g, "-")
let name = baseFileName.replace(/_/g, " ")
name = name.charAt(0).toUpperCase() + name.slice(1)
photos.push({
"slug": slug,
"name": name,
"filename": filename,
})
})
console.log(`Exporting photos to file: ${photosExportPath}`)
fs.writeFileSync(photosExportPath, JSON.stringify(photos))
const projects = []
const projectsPath = "./content/projects"
const projectsExportPath = "./src/_projects.json"
fs.readdirSync(projectsPath).forEach(filename => {
console.log(`Found project: ${filename}`)
const projectPath = `${projectsPath}/${filename}`
const projectObj = JSON.parse(fs.readFileSync(projectPath, "utf8"))
projects.push(projectObj)
})
console.log(`Exporting projects to file: ${projectsExportPath}`)
fs.writeFileSync(projectsExportPath, JSON.stringify(projects))
console.log("Finished content export")