-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathempty.html
168 lines (135 loc) · 5.82 KB
/
empty.html
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<!DOCTYPE html>
<html lang="en">
<head>
<title>Glossary</title>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="generator" content="https://glossary.page/template" />
<link rel="preconnect" href="https://glstatic.net" crossorigin>
<link rel="apple-touch-icon" sizes="180x180" href="https://glstatic.net/glossary-page-template-favicons/apple-touch-icon.png?v=2">
<link rel="icon" type="image/png" sizes="32x32" href="https://glstatic.net/glossary-page-template-favicons/favicon-32x32.png?v=2">
<link rel="icon" type="image/png" sizes="16x16" href="https://glstatic.net/glossary-page-template-favicons/favicon-16x16.png?v=2">
<link rel="manifest" href="https://glstatic.net/glossary-page-template-favicons/site.webmanifest">
<link rel="mask-icon" href="https://glstatic.net/glossary-page-template-favicons/safari-pinned-tab.svg?v=2" color="#5bbad5">
<link rel="shortcut icon" href="https://glstatic.net/glossary-page-template-favicons/favicon.ico?v=2">
<meta name="msapplication-TileColor" content="#da532c">
<meta name="msapplication-config" content="https://glstatic.net/glossary-page-template-favicons/browserconfig.xml">
<meta name="theme-color" content="#ffffff">
<script type="text/javascript">
// Prevent FOUC
document.documentElement.className = 'invisible';
</script>
<!-- Uncomment the lines below to add support for math typesetting using KaTeX. -->
<!--
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css" integrity="sha384-wcIxkf4k558AjM3Yz3BBFQUbk/zgIYC2R0QpeeYb+TwlBVMrlgLqwRjRtGZiK7ww" crossorigin="anonymous">
<script defer src="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.js" integrity="sha384-hIoBPJpTUs74ddyc4bFZSM1TVlQDA60VBbJS0oA934VSz82sBx1X7kSx2ATBDIyd" crossorigin="anonymous"></script>
-->
<script type="module" src="./glossary.ts"></script>
</head>
<body>
<div id="glossary-page-container" data-enable-help-for-making-changes="true" data-enable-export-menu="true" data-enable-order-items-buttons="true" data-enable-last-updated-dates="true" data-card-width="intermediate">
<header>
<h1 id="glossary-page-title">
Glossary Page Template
</h1>
</header>
<main>
<div id="glossary-page-about">
<p>This is a template for a glossary page.</p>
<ul>
</ul>
</div>
<article id="glossary-page-items">
<dl>
</dl>
</article>
</main>
<footer>
Built using
<a target="_blank" href="https://glossary.page/template">Glossary Page Template</a>
.
</footer>
</div>
</body>
</html>
<!--
#!/usr/bin/env node
/* START OF editor.js
This script starts a simple server listening on localhost.
* GET requests are served by local HTML/JS/CSS files.
* PATCH requests to / expect to receive an HTML fragment string in the body.
This string is used to update the glossary file, replacing
<div id="glossary-page-container"
...
</div>.
This allows the editor to save any updates made in the UI.
*/
const http = require('http');
const fs = require('fs');
const path = require('path');
const HOST = process.env['HOST'] || 'localhost';
const PORT = process.env['PORT'] || 3003;
const FILE = process.env['FILE'] || './glossary.html';
const mimeTypes = {
'.html': 'text/html',
'.js': 'text/javascript',
'.css': 'text/css'
};
const server = http.createServer(async (req, res) => {
if (req.url === '/' && req.method === 'PATCH') {
const buffers = [];
for await (const chunk of req) {
buffers.push(chunk);
}
const body = Buffer.concat(buffers).toString();
replaceGlossaryElementInFile(body);
res.writeHead(204).end();
} else {
serveLocalFile(req, res);
}
});
server.listen(PORT, HOST, () => {
console.log(`Server started at http://${HOST}:${PORT}`);
});
function serveLocalFile(req, res) {
var filePath = '.' + req.url.replace(/\?.*$/g, '');
if (filePath === './') filePath = FILE;
const extname = String(path.extname(filePath)).toLowerCase();
const contentType = mimeTypes[extname] || 'application/octet-stream';
fs.readFile(filePath, 'utf-8', (err, fileContents) => {
if (err) {
serveErrorPage(err, res);
} else {
if (filePath === FILE)
fileContents = fileContents.replace(
/<div id="glossary-page-container"/,
`<div id="glossary-page-container" data-editor-is-running="true"`
);
res.writeHead(200, { 'Content-Type': contentType });
res.end(fileContents, 'utf-8');
}
});
}
function serveErrorPage(err, res) {
if (err.code == 'ENOENT') {
res.writeHead(404, { 'Content-Type': 'text/html' });
res.end('<html><body>Page not found</body></html>');
} else {
res.writeHead(500, { 'Content-Type': 'text/html' });
res.end('<html><body>Internal server error</body></html>');
}
}
function replaceGlossaryElementInFile(newElementString) {
fs.readFile(FILE, 'utf8', (err, fileContents) => {
if (err) return console.log(err);
const regex = /\n[ \t]*<div id="glossary-page-container".*<\/div>\n/s;
if (!fileContents.replace(regex, 'replacing-worked').includes('replacing-worked')) {
return console.log(`Unable to save changes using the regex ${regex}`);
}
const updatedFileContents = fileContents.replace(regex, "\n" + newElementString + "\n");
fs.writeFile(FILE, updatedFileContents, 'utf8', (err) => {
if (err) return console.log(err);
});
});
}
// -->