vite-plugin-html-elements 0.1.3 β†’ 0.1.4

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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAyC,MAAM,MAAM,CAAC;AAI1E,MAAM,WAAW,WAAW;IAC1B;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,mBAAmB;IAClC;;;OAGG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;IAEhB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;;OAGG;IACH,MAAM,CAAC,EAAE,WAAW,EAAE,CAAC;IAEvB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,wBAAgB,YAAY,CAAC,OAAO,GAAE,mBAAwB,GAAG,MAAM,CAiEtE;AAyHD,wBAAgB,cAAc,CAC5B,MAAM,EAAE,MAAM,EACd,KAAK,GAAE,OAAe,GACrB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CA4BxB"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAyC,MAAM,MAAM,CAAC;AAI1E,MAAM,WAAW,WAAW;IAC1B;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,mBAAmB;IAClC;;;OAGG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;IAEhB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;;OAGG;IACH,MAAM,CAAC,EAAE,WAAW,EAAE,CAAC;IAEvB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,wBAAgB,YAAY,CAAC,OAAO,GAAE,mBAAwB,GAAG,MAAM,CAiEtE;AAyHD,wBAAgB,cAAc,CAC5B,MAAM,EAAE,MAAM,EACd,KAAK,GAAE,OAAe,GACrB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CA2DxB"}
package/dist/index.js CHANGED
@@ -62,20 +62,22 @@ function getRoutesEntries(routes, srcDir, debug) {
62
62
  console.error(`❌ Route source not found: ${route.source} for path ${route.path}`);
63
63
  return;
64
64
  }
65
- // Normalize path: remove trailing slash (except for root)
66
- const normalizedPath = route.path === '/' ? '/' : route.path.replace(/\/$/, '');
67
65
  // Convert route path to entry name
66
+ // '/' -> 'index'
67
+ // '/blog' -> 'blog/index'
68
+ // '/blog/today-is-nice' -> 'blog/today-is-nice/index'
68
69
  let entryName;
69
- if (normalizedPath === '/') {
70
+ if (route.path === '/') {
70
71
  entryName = 'index';
71
72
  }
72
73
  else {
73
- const cleanPath = normalizedPath.replace(/^\//, '');
74
+ // Remove leading slash and add /index for directory structure
75
+ const cleanPath = route.path.replace(/^\//, '');
74
76
  entryName = `${cleanPath}/index`;
75
77
  }
76
78
  entries[entryName] = sourcePath;
77
79
  if (debug) {
78
- console.log(`πŸ—ΊοΈ Route: ${normalizedPath} -> ${route.source} (output: ${entryName}.html)`);
80
+ console.log(`πŸ—ΊοΈ Route: ${route.path} -> ${route.source} (output: ${entryName}.html)`);
79
81
  }
80
82
  });
81
83
  return entries;
@@ -134,24 +136,56 @@ function parseAttributes(attrString) {
134
136
  return attrs;
135
137
  }
136
138
  export function getHtmlEntries(srcDir, debug = false) {
137
- try {
138
- const htmlFiles = readdirSync(srcDir).filter((file) => file.endsWith('.html'));
139
- const entries = {};
140
- htmlFiles.forEach((file) => {
141
- const name = file.replace('.html', '');
142
- entries[name] = resolve(srcDir, file);
143
- });
144
- if (debug) {
145
- console.log(`πŸ“„ Auto-discovered HTML files: ${Object.keys(entries).join(', ')}`);
139
+ const entries = {};
140
+ function scanDirectory(dir, basePath = '') {
141
+ try {
142
+ const items = readdirSync(dir, { withFileTypes: true });
143
+ for (const item of items) {
144
+ const fullPath = resolve(dir, item.name);
145
+ const relativePath = basePath ? `${basePath}/${item.name}` : item.name;
146
+ if (item.isDirectory()) {
147
+ // Skip elements directory
148
+ if (item.name === 'elements') {
149
+ continue;
150
+ }
151
+ // Recursively scan subdirectories
152
+ scanDirectory(fullPath, relativePath);
153
+ }
154
+ else if (item.isFile() && item.name.endsWith('.html')) {
155
+ // Generate entry name from file path
156
+ let entryName;
157
+ if (item.name === 'index.html') {
158
+ // index.html in root -> 'index'
159
+ // index.html in blog/ -> 'blog/index'
160
+ entryName = basePath ? `${basePath}/index` : 'index';
161
+ }
162
+ else {
163
+ // about.html -> 'about/index'
164
+ // blog/post.html -> 'blog/post/index'
165
+ const nameWithoutExt = item.name.replace('.html', '');
166
+ entryName = basePath
167
+ ? `${basePath}/${nameWithoutExt}/index`
168
+ : `${nameWithoutExt}/index`;
169
+ }
170
+ entries[entryName] = fullPath;
171
+ }
172
+ }
146
173
  }
147
- return entries;
148
- }
149
- catch (error) {
150
- const errorMessage = error instanceof Error ? error.message : 'Unknown error';
151
- console.warn(`⚠️ Could not read directory: ${srcDir}`);
152
- if (debug) {
153
- console.error(` ${errorMessage}`);
174
+ catch (error) {
175
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error';
176
+ console.warn(`⚠️ Could not read directory: ${dir}`);
177
+ if (debug) {
178
+ console.error(` ${errorMessage}`);
179
+ }
154
180
  }
155
- return {};
156
181
  }
182
+ scanDirectory(srcDir);
183
+ if (debug) {
184
+ console.log(`πŸ“„ Auto-discovered routes:`);
185
+ Object.keys(entries).forEach((key) => {
186
+ const url = key === 'index' ? '/' : `/${key.replace('/index', '')}`;
187
+ console.log(` ${url} -> ${entries[key].replace(srcDir + '/', '')}`);
188
+ });
189
+ }
190
+ return entries;
157
191
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-html-elements",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "Modular HTML without the JavaScript",
5
5
  "author": "Vincent Medina",
6
6
  "license": "MIT",