spa-ssi 0.0.4 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/serve.js +78 -5
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spa-ssi",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "description": "Single Page App / Server Side Include Simple File Web Server",
5
5
  "keywords": [
6
6
  "single-page-app",
package/serve.js CHANGED
@@ -52,11 +52,17 @@ class SimpleHTTPRequestHandler {
52
52
  stat = await fs.stat(filepath);
53
53
  }
54
54
  } catch {
55
- stat = null;
55
+ const siteMapContent = await this.renderSiteMap();
56
+ // Send response
57
+ res.writeHead(200, { "Content-Type": 'text/html' });
58
+ res.end(siteMapContent);
59
+ return;
56
60
  }
57
61
 
58
62
  // If requested .html doesn't exist → fallback to root index.html (SPA mode)
59
63
  if ((!stat || !stat.isFile()) && pathname.endsWith(".html")) {
64
+
65
+
60
66
  filepath = path.join(this.rootDir, "index.html");
61
67
  }
62
68
 
@@ -162,9 +168,16 @@ class SimpleHTTPRequestHandler {
162
168
  if (typeof value === 'string') {
163
169
  const title = await this.extractTitle(value);
164
170
  const href = path.relative(baseDir, value).replace(/\\/g, '/');
165
- html += `<li><a href="${href}">${title}</a></li>`;
171
+ html += String.raw `<li><a href="${href}">${title}</a></li>`;
166
172
  } else {
167
- html += `<li>${key}${await this.renderTree(value, baseDir)}</li>`;
173
+ html += String.raw`
174
+ <li>
175
+ <details>
176
+ <summary>${key}</summary>
177
+ ${await this.renderTree(value, baseDir)}
178
+ </details>
179
+ </li>
180
+ `;
168
181
  }
169
182
  }
170
183
  html += '</ul>';
@@ -175,8 +188,68 @@ class SimpleHTTPRequestHandler {
175
188
  // Run it
176
189
  const baseDir = process.cwd();
177
190
  const htmlFiles = await this.findHtmlFiles(baseDir);
178
- const htmlOutput = this.buildHtmlList(htmlFiles, baseDir);
179
- return htmlOutput;
191
+ const htmlOutput = await this.buildHtmlList(htmlFiles, baseDir);
192
+ const fullHTMLOutput = String.raw `
193
+ <!DOCTYPE html>
194
+ <html lang="en">
195
+ <head>
196
+ <meta charset="UTF-8">
197
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
198
+ <title>Site Map</title>
199
+ <style>
200
+ @import "https://unpkg.com/open-props";
201
+
202
+ /* optional imports that use the props */
203
+ @import "https://unpkg.com/open-props/normalize.min.css";
204
+ @import "https://unpkg.com/open-props/buttons.min.css";
205
+
206
+ /* just dark or light themes */
207
+ @import "https://unpkg.com/open-props/normalize.dark.min.css";
208
+ @import "https://unpkg.com/open-props/buttons.dark.min.css";
209
+ @import "https://unpkg.com/open-props/normalize.light.min.css";
210
+ @import "https://unpkg.com/open-props/buttons.light.min.css";
211
+ @media (prefers-color-scheme: light) {
212
+ /* Styles for light mode */
213
+ body {
214
+ background: #ffffff;
215
+ color: #000000;
216
+ }
217
+
218
+ }
219
+
220
+ @media (prefers-color-scheme: dark) {
221
+ /* Styles for dark mode */
222
+ body {
223
+ background: #000000;
224
+ color: #ffffff;
225
+ }
226
+
227
+
228
+ }
229
+
230
+ ul{
231
+ list-style-type: none; /* Removes bullets */
232
+ }
233
+
234
+ li {
235
+ max-inline-size: 100%;
236
+ }
237
+
238
+ summary{
239
+ color: black;
240
+ }
241
+
242
+ a {
243
+ color: hotpink;
244
+ }
245
+ </style>
246
+ </head>
247
+ <body>
248
+ ${htmlOutput}
249
+ </body>
250
+ </html>
251
+ `;
252
+ return fullHTMLOutput;
180
253
  }
181
254
 
182
255
  /**