@webjourney/vite-plugins 1.2.13 → 1.2.14

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/dist/build.js +28 -0
  2. package/package.json +1 -1
package/dist/build.js CHANGED
@@ -184,6 +184,29 @@ async function extractRoutes(projectRoot) {
184
184
  // If no routes found, default to root
185
185
  return routes.length > 0 ? routes : ['/'];
186
186
  }
187
+ function generateSitemap(routes, hostname) {
188
+ const lastmod = new Date().toISOString().split('T')[0];
189
+ const urls = routes
190
+ .filter(route => !route.includes(':')) // Exclude dynamic routes like /posts/:id
191
+ .map(route => {
192
+ const loc = route === '/' ? hostname : `${hostname}${route}`;
193
+ // Only include lastmod on homepage
194
+ if (route === '/') {
195
+ return ` <url>
196
+ <loc>${loc}</loc>
197
+ <lastmod>${lastmod}</lastmod>
198
+ </url>`;
199
+ }
200
+ return ` <url>
201
+ <loc>${loc}</loc>
202
+ </url>`;
203
+ })
204
+ .join('\n');
205
+ return `<?xml version="1.0" encoding="UTF-8"?>
206
+ <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
207
+ ${urls}
208
+ </urlset>`;
209
+ }
187
210
  async function prerender(projectRoot) {
188
211
  const toAbsolute = (p) => path.resolve(projectRoot, p);
189
212
  // Read the built index.html
@@ -202,6 +225,11 @@ async function prerender(projectRoot) {
202
225
  // Extract routes from App.tsx
203
226
  const routes = await extractRoutes(projectRoot);
204
227
  console.log(` Found ${routes.length} route(s): ${routes.join(', ')}`);
228
+ // Generate sitemap
229
+ const hostname = process.env.__VITE_ADDITIONAL_SERVER_ALLOWED_HOSTS || 'http://127.0.0.1';
230
+ const sitemap = generateSitemap(routes, hostname);
231
+ fs.writeFileSync(toAbsolute('dist/sitemap.xml'), sitemap);
232
+ console.log(' Generated: sitemap.xml');
205
233
  for (const route of routes) {
206
234
  // Render the app HTML
207
235
  const appHtml = renderToString(render(route));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webjourney/vite-plugins",
3
- "version": "1.2.13",
3
+ "version": "1.2.14",
4
4
  "description": "Vite plugins for Webjourney WYSIWYG editing",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",