-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcv.html
More file actions
64 lines (58 loc) · 2.19 KB
/
Copy pathcv.html
File metadata and controls
64 lines (58 loc) · 2.19 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>JSON and Mustache Template Processor</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mustache.js/4.1.0/mustache.min.js"></script>
</head>
<body>
<input type="file" id="jsonInput" accept=".json">
<input type="file" id="templateInput" accept=".html,.htm">
<button onclick="processTemplate()" disabled id="ptbutton">Process Template</button>
<button onclick="downloadResult()" disabled id="dlbutton">Download Result</button>
<script>
let jsonData, templateContent, processedResult;
document.getElementById('jsonInput').addEventListener('change', function(event) {
const file = event.target.files[0];
const reader = new FileReader();
reader.onload = function(e) {
jsonData = JSON.parse(e.target.result);
checkFilesUploaded();
console.log("json input uploaded");
};
reader.readAsText(file);
});
document.getElementById('templateInput').addEventListener('change', function(event) {
const file = event.target.files[0];
const reader = new FileReader();
reader.onload = function(e) {
templateContent = e.target.result;
checkFilesUploaded();
console.log("template input uploaded");
};
reader.readAsText(file);
});
function checkFilesUploaded() {
if (jsonData && templateContent) {
document.getElementById("ptbutton").disabled = false;
document.getElementById("dlbutton").disabled = false;
}
}
function processTemplate() {
processedResult = Mustache.render(templateContent, jsonData);
}
function downloadResult() {
const blob = new Blob([processedResult], {type: 'text/html'});
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'processed_template.html';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
}
</script>
</body>
</html>