Skip to content

Commit 3985c67

Browse files
committed
Implement site
1 parent aff1952 commit 3985c67

File tree

10 files changed

+155
-45
lines changed

10 files changed

+155
-45
lines changed

site/bat-build-watch.bat

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
:: Prevent quit on error
2+
if not defined in_subprocess (cmd /k set in_subprocess=y ^& %0 %*) & exit
3+
:: Clear screen
4+
cls
5+
6+
:: Build (watch mode)
7+
npm run build-watch

site/bat-build.bat

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
:: Prevent quit on error
2+
if not defined in_subprocess (cmd /k set in_subprocess=y ^& %0 %*) & exit
3+
:: Clear screen
4+
cls
5+
6+
:: Build
7+
npm run build

site/bat-localhost.bat

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
:: Prevent quit on error
2+
if not defined in_subprocess (cmd /k set in_subprocess=y ^& %0 %*) & exit
3+
:: Clear screen
4+
cls
5+
6+
:: Test site locally
7+
npx live-server

site/build/main.js

Lines changed: 20 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

site/build/main.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

site/index.html

Lines changed: 69 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,83 @@
55
<title>Custom Language → JSON</title>
66
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
77
<style>
8-
body { padding: 50px; background-color: #f7f9fc; }
9-
textarea { width: 100%; height: 200px; margin-bottom: 20px; font-family: monospace; }
10-
h1 { margin-bottom: 30px; }
8+
body {
9+
padding: 50px;
10+
background-color: #0d1117;
11+
color: #c9d1d9;
12+
font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
13+
}
14+
15+
h1 {
16+
margin-bottom: 30px;
17+
color: #58a6ff;
18+
}
19+
20+
textarea {
21+
width: 100%;
22+
height: 200px;
23+
margin-bottom: 20px;
24+
font-family: monospace;
25+
background-color: #161b22;
26+
color: #c9d1d9;
27+
border: 1px solid #30363d;
28+
border-radius: 8px;
29+
padding: 10px;
30+
resize: vertical;
31+
box-shadow: inset 0 1px 2px rgba(0,0,0,0.5);
32+
}
33+
34+
textarea:focus {
35+
outline: none;
36+
border-color: #58a6ff;
37+
box-shadow: 0 0 0 2px rgba(88,166,255,0.3);
38+
background-color: #0d1117;
39+
}
40+
41+
.container {
42+
max-width: 800px;
43+
}
44+
45+
a.github-link {
46+
display: inline-block;
47+
margin-top: 20px;
48+
color: #58a6ff;
49+
text-decoration: none;
50+
font-weight: 500;
51+
}
52+
53+
a.github-link:hover {
54+
text-decoration: underline;
55+
}
56+
57+
.form-check {
58+
margin-bottom: 20px;
59+
}
60+
61+
label {
62+
margin-left: 5px;
63+
}
1164
</style>
1265
</head>
1366
<body>
1467
<div class="container">
1568
<h1>Custom Language → JSON Converter</h1>
69+
1670
<textarea id="input" placeholder="Write your custom language here..."></textarea>
71+
72+
<!-- Minify checkbox -->
73+
<div class="form-check">
74+
<input class="form-check-input" type="checkbox" value="" id="minify">
75+
<label class="form-check-label" for="minify">Minify JSON output</label>
76+
</div>
77+
1778
<textarea id="output" placeholder="JSON output..." readonly></textarea>
18-
<button class="btn btn-primary" onclick="convert()">Convert</button>
79+
80+
<a href="https://github.com/yourusername/your-repo" target="_blank" class="github-link">
81+
View this project on GitHub
82+
</a>
1983
</div>
2084

21-
<script type="module" src="./dist/main.js"></script>
85+
<script type="module" src="./build/main.js"></script>
2286
</body>
2387
</html>

site/main.ts

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,29 @@
1+
import { JsonhReader } from "jsonh-ts";
2+
13
const input = document.getElementById('input') as HTMLTextAreaElement;
24
const output = document.getElementById('output') as HTMLTextAreaElement;
3-
const button = document.getElementById('convert') as HTMLButtonElement;
5+
const minify = document.getElementById('minify') as HTMLInputElement;
6+
7+
function convert(): void {
8+
let elementResult = JsonhReader.parseElementFromString(input.value);
9+
if (elementResult.isValue) {
10+
let element: unknown = elementResult.value;
11+
12+
if (minify.checked) {
13+
output.value = JSON.stringify(element, null, " ");
14+
}
15+
else {
16+
output.value = JSON.stringify(element);
17+
}
18+
}
19+
else {
20+
let error: Error = elementResult.error;
21+
22+
output.value = `Error: ${error.message}`;
23+
}
24+
}
425

5-
button.addEventListener('click', () => {
6-
try {
7-
const lines = input.value.split('\n');
8-
const json: Record<string, string> = {};
9-
lines.forEach(line => {
10-
if (line.includes('=')) {
11-
const [key, value] = line.split('=').map(s => s.trim());
12-
json[key!] = value!;
13-
}
14-
});
15-
output.value = JSON.stringify(json, null, 2);
16-
} catch (e: any) {
17-
output.value = 'Error: ' + e.message;
18-
}
19-
});
26+
// Run conversion every time user types
27+
input.addEventListener('input', convert);
28+
// Run conversion immediately
29+
convert();

site/package-lock.json

Lines changed: 9 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

site/package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@
22
"name": "site",
33
"version": "1.0.0",
44
"description": "",
5-
"main": "index.js",
5+
"type": "module",
6+
"main": "main.js",
67
"scripts": {
78
"test": "echo \"Error: no test specified\" && exit 1",
89
"build": "tsc",
9-
"watch": "tsc --watch"
10+
"build-watch": "tsc --watch"
1011
},
1112
"keywords": [],
1213
"author": "",
13-
"license": "ISC",
14-
"type": "commonjs",
14+
"license": "MIT",
1515
"devDependencies": {
16+
"jsonh-ts": "^1.1.0",
1617
"typescript": "^5.9.2"
1718
}
1819
}

site/tsconfig.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@
44
"outDir": "./build",
55

66
// Environment Settings
7-
"module": "commonjs",
7+
"module": "node16",
88
"target": "es2022",
99
"lib": ["ES2022", "DOM"],
1010
"types": [],
1111

12+
"moduleResolution": "node16",
13+
"esModuleInterop": true,
14+
1215
// Other Outputs
1316
"sourceMap": true,
1417
"declaration": true,

0 commit comments

Comments
 (0)