-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathbuild.js
More file actions
121 lines (107 loc) · 3.06 KB
/
build.js
File metadata and controls
121 lines (107 loc) · 3.06 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
const fs = require("fs");
const data = require("./data.js");
const path = require("path");
const dir = "./dist";
const template = (sketch) => `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>${sketch.title}</title>
<script src="https://cdn.jsdelivr.net/npm/p5@1.1.9/lib/p5.js"></script>
<style>
body {
display: grid;
place-items: center;
height: 100vh;
margin: 0;
background: black;
}
${sketch.dynamic ? "" : `
@media (orientation: landscape) {
canvas {
width: initial !important;
height: 100vh !important;
}
}
@media (orientation: portrait) {
canvas {
width: 100vw !important;
height: initial !important;
}
}
`}
</style>
<script src="/${sketch.path}"></script>
</head>
<body></body>
</html>
`;
const pathToHtmlPath = (filePath) =>
path.join(
path.dirname(filePath),
path.basename(filePath, path.extname(filePath)) + ".html"
);
data.map((entry) => {
console.log(`Building ${entry.title}`);
const filePath = `${dir}/${entry.path}`;
fs.mkdirSync(path.dirname(filePath), { recursive: true });
fs.copyFileSync(`./${entry.path}`, filePath);
const finalFilePath = pathToHtmlPath(filePath);
fs.writeFileSync(finalFilePath, template(entry), function (err) {
if (err) throw err;
console.log("Saved!");
});
});
console.log("Copying style files");
fs.copyFileSync("reset.css", "dist/reset.css");
fs.copyFileSync("style.css", "dist/style.css");
const frontpageTemplate = (entries) => `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Generative Processing</title>
<link
href="https://fonts.googleapis.com/css2?family=Montserrat&family=Open+Sans&display=swap"
rel="stylesheet"
/>
<link rel="stylesheet" href="reset.css" />
<link rel="stylesheet" href="style.css" />
</head>
<body>
<main>
${entries
.map(
(entry) => entry.ignore ? "" : `
<a class="sketch-entrance" href="/${pathToHtmlPath(entry.path)}">
<div>${entry.title}</div>
<img src=${entry.img} alt=${entry.title} />
</a>
`
)
.join("")}
</main>
<footer>
<a href="https://www.instagram.com/anders.larsen.96/"
><img
src="https://res.cloudinary.com/plusk/image/upload/v1604152555/instagram_r6guib.svg"
alt="Instagram"
/></a>
<a href="https://github.com/plusk"
><img
src="https://res.cloudinary.com/plusk/image/upload/v1604152555/github_avgksu.svg"
alt="GitHub"
/></a>
</footer>
</body>
</html>
`;
console.log("Writing index.html");
fs.writeFileSync(`${dir}/index.html`, frontpageTemplate(data), function (err) {
if (err) throw err;
console.log("Generated index");
});
fs.copyFileSync("palettes.json", "dist/palettes.json");