spa-ssi 0.0.5 → 0.0.7

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 +82 -10
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spa-ssi",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
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
@@ -48,15 +48,20 @@ class SimpleHTTPRequestHandler {
48
48
  try {
49
49
  stat = await fs.stat(filepath);
50
50
  if (stat.isDirectory()) {
51
+ throw 'DoIndex';
52
+
53
+ }
54
+ } catch(e) {
55
+ try{
51
56
  filepath = path.join(this.rootDir, '/index.html'); //path.join(filepath, "index.html");
52
57
  stat = await fs.stat(filepath);
58
+ }catch(e2){
59
+ const siteMapContent = await this.renderSiteMap();
60
+ // Send response
61
+ res.writeHead(200, { "Content-Type": 'text/html' });
62
+ res.end(siteMapContent);
63
+ return;
53
64
  }
54
- } catch {
55
- const siteMapContent = await this.renderSiteMap();
56
- // Send response
57
- res.writeHead(200, { "Content-Type": 'text/html' });
58
- res.end(siteMapContent);
59
- return;
60
65
  }
61
66
 
62
67
  // If requested .html doesn't exist → fallback to root index.html (SPA mode)
@@ -168,9 +173,16 @@ class SimpleHTTPRequestHandler {
168
173
  if (typeof value === 'string') {
169
174
  const title = await this.extractTitle(value);
170
175
  const href = path.relative(baseDir, value).replace(/\\/g, '/');
171
- html += `<li><a href="${href}">${title}</a></li>`;
176
+ html += String.raw `<li><a href="${href}">${title}</a></li>`;
172
177
  } else {
173
- html += `<li>${key}${await this.renderTree(value, baseDir)}</li>`;
178
+ html += String.raw`
179
+ <li>
180
+ <details>
181
+ <summary>${key}</summary>
182
+ ${await this.renderTree(value, baseDir)}
183
+ </details>
184
+ </li>
185
+ `;
174
186
  }
175
187
  }
176
188
  html += '</ul>';
@@ -181,8 +193,68 @@ class SimpleHTTPRequestHandler {
181
193
  // Run it
182
194
  const baseDir = process.cwd();
183
195
  const htmlFiles = await this.findHtmlFiles(baseDir);
184
- const htmlOutput = this.buildHtmlList(htmlFiles, baseDir);
185
- return htmlOutput;
196
+ const htmlOutput = await this.buildHtmlList(htmlFiles, baseDir);
197
+ const fullHTMLOutput = String.raw `
198
+ <!DOCTYPE html>
199
+ <html lang="en">
200
+ <head>
201
+ <meta charset="UTF-8">
202
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
203
+ <title>Site Map</title>
204
+ <style>
205
+ @import "https://unpkg.com/open-props";
206
+
207
+ /* optional imports that use the props */
208
+ @import "https://unpkg.com/open-props/normalize.min.css";
209
+ @import "https://unpkg.com/open-props/buttons.min.css";
210
+
211
+ /* just dark or light themes */
212
+ @import "https://unpkg.com/open-props/normalize.dark.min.css";
213
+ @import "https://unpkg.com/open-props/buttons.dark.min.css";
214
+ @import "https://unpkg.com/open-props/normalize.light.min.css";
215
+ @import "https://unpkg.com/open-props/buttons.light.min.css";
216
+ @media (prefers-color-scheme: light) {
217
+ /* Styles for light mode */
218
+ body {
219
+ background: #ffffff;
220
+ color: #000000;
221
+ }
222
+
223
+ }
224
+
225
+ @media (prefers-color-scheme: dark) {
226
+ /* Styles for dark mode */
227
+ body {
228
+ background: #000000;
229
+ color: #ffffff;
230
+ }
231
+
232
+
233
+ }
234
+
235
+ ul{
236
+ list-style-type: none; /* Removes bullets */
237
+ }
238
+
239
+ li {
240
+ max-inline-size: 100%;
241
+ }
242
+
243
+ summary{
244
+ color: black;
245
+ }
246
+
247
+ a {
248
+ color: hotpink;
249
+ }
250
+ </style>
251
+ </head>
252
+ <body>
253
+ ${htmlOutput}
254
+ </body>
255
+ </html>
256
+ `;
257
+ return fullHTMLOutput;
186
258
  }
187
259
 
188
260
  /**