-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathadd-template.js
More file actions
80 lines (76 loc) · 2.69 KB
/
add-template.js
File metadata and controls
80 lines (76 loc) · 2.69 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
const { readFileSync, writeFileSync, readdirSync } = require("fs");
const { join, resolve } = require("path");
const { format } = require("prettier");
const marked = require("marked");
let templateHtml = `<!DOCTYPE html>
<html>
<head>
<title><!-- Title --> · Uppload</title>
<link
rel="stylesheet"
href="https://unpkg.com/purecss@1.0.1/build/pure-min.css"
integrity="sha384-oAOxQR6DkCoMliIh8yFnu25d7Eq/PHS21PClpwjOTeU2jRSq11vu66rf90/cZr47"
crossorigin="anonymous"
/>
<style>
a {
color: #0078e7;
}
.uppload-image {
display: block;
margin-bottom: 1rem;
}
</style>
</head>
<body>
<div
style="padding: 2rem; max-width: 800px; margin: auto; line-height: 1.5"
>
<main>
<!-- Contents -->
<p style="opacity: 0.5">Click on the button below to try this demo.</p>
<img alt="" class="uppload-image" />
<button class="pure-button pure-button-primary">
Upload
</button>
</main>
<footer style="margin-top: 4rem">
<h2>Uppload</h2>
<p>
Uppload is a better JavaScript image uploader. It's highly
customizable with 30+ plugins, completely free and open-source, and
can be used with any file uploading backend.
</p>
<a href="https://github.com/elninotech/uppload" class="pure-button"
>GitHub</a
>
<a href="https://uppload.js.org" class="pure-button">Docs</a>
</footer>
</div>
<script src="index.ts"></script>
</body>
</html>`;
const examples = readdirSync(join(__dirname, "examples"));
examples.forEach(example => {
const readmePath = join(__dirname, "examples", example, "README.md");
try {
const readmeMd = readFileSync(readmePath, { encoding: "utf8" });
const readmeHtml = marked(readmeMd.toString())
.split("\n", 2)
.join("\n");
templateHtml = templateHtml
.toString()
.replace(
"<!-- Contents -->",
readmeHtml +
`<p>You can <strong><a href="https://github.com/elninotech/uppload-examples/tree/master/examples/${example}">view the source code</a></strong> of this example or <a href="https://codesandbox.io/s/github/elninotech/uppload-examples/tree/master/examples/${example}">try it on CodeSandbox</a></p>`
);
const readmeTitle = readmeMd.split("\n", 1)[0].replace("# ", "");
templateHtml = templateHtml.replace("<!-- Title -->", readmeTitle);
} catch (error) {
console.log(error);
}
const indexPath = join(__dirname, "examples", example, "index.html");
writeFileSync(indexPath, format(templateHtml, { parser: "html" }));
console.log(`Written examples/${example}/index.html`);
});