mnfst-render 0.2.0 → 0.2.2

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.
@@ -1229,6 +1229,12 @@ async function runPrerender(config) {
1229
1229
  const fileSegments = is404 ? [] : pathToFileSegments(pathSeg ? `/${pathSeg}` : '/');
1230
1230
  const outDir = is404 ? config.output : join(config.output, ...fileSegments);
1231
1231
  const outFile = is404 ? join(config.output, '404.html') : join(outDir, 'index.html');
1232
+ const currentLocale =
1233
+ pathSeg && locales.length > 0
1234
+ ? locales.includes(pathSeg.split('/')[0])
1235
+ ? pathSeg.split('/')[0]
1236
+ : defaultLocale || 'en'
1237
+ : defaultLocale || 'en';
1232
1238
 
1233
1239
  const page = await browser.newPage();
1234
1240
  try {
@@ -1289,9 +1295,30 @@ async function runPrerender(config) {
1289
1295
 
1290
1296
  // Ensure $route-dependent expressions are recalculated after locale/data stores settle.
1291
1297
  // This helps localized dynamic pages (e.g. /ko/articles/slug) compute prev/next links correctly.
1292
- await page.evaluate(() => {
1298
+ await page.evaluate(({ allLocales, currentLocale }) => {
1293
1299
  try {
1294
- const to = window.ManifestRoutingNavigation?.getCurrentRoute?.() ?? window.location.pathname;
1300
+ const localeList = Array.isArray(allLocales) ? allLocales : [];
1301
+ const store = (typeof Alpine !== 'undefined' && Alpine.store) ? Alpine.store('locale') : null;
1302
+ if (store) {
1303
+ if (!Array.isArray(store.available) || store.available.length === 0) {
1304
+ store.available = localeList.slice();
1305
+ } else {
1306
+ const merged = Array.from(new Set([...store.available, ...localeList]));
1307
+ store.available = merged;
1308
+ }
1309
+ if (currentLocale && typeof currentLocale === 'string') {
1310
+ store.current = currentLocale;
1311
+ }
1312
+ }
1313
+
1314
+ const rawRoute = window.ManifestRoutingNavigation?.getCurrentRoute?.() ?? window.location.pathname;
1315
+ const clean = String(rawRoute || '/').replace(/^\/+|\/+$/g, '');
1316
+ const parts = clean ? clean.split('/') : [];
1317
+ const logical = parts.length > 0 && localeList.includes(parts[0])
1318
+ ? '/' + parts.slice(1).join('/')
1319
+ : (clean ? '/' + clean : '/');
1320
+ const to = logical === '//' ? '/' : logical;
1321
+
1295
1322
  window.dispatchEvent(new CustomEvent('manifest:route-change', {
1296
1323
  detail: {
1297
1324
  from: to,
@@ -1303,7 +1330,8 @@ async function runPrerender(config) {
1303
1330
  } catch {
1304
1331
  // no-op
1305
1332
  }
1306
- }).catch(() => { });
1333
+ }, { allLocales: locales, currentLocale }).catch(() => { });
1334
+ await page.waitForTimeout(60).catch(() => { });
1307
1335
 
1308
1336
  // Optional extra delay so in-page async (e.g. fetch() in x-init for client logos) can complete before snapshot.
1309
1337
  if (config.waitAfterIdle > 0) {
@@ -1456,12 +1484,6 @@ async function runPrerender(config) {
1456
1484
  }
1457
1485
  html = stripDuplicatedLoopDirectives(html);
1458
1486
  html = stripPrerenderedXDataDirectives(html);
1459
- const currentLocale =
1460
- pathSeg && locales.length > 0
1461
- ? locales.includes(pathSeg.split('/')[0])
1462
- ? pathSeg.split('/')[0]
1463
- : defaultLocale || 'en'
1464
- : defaultLocale || 'en';
1465
1487
  const content = loadContentForPrerender(manifest, config.root, currentLocale);
1466
1488
  const xData = { manifest, content };
1467
1489
  html = resolveHeadXBindings(html, xData);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mnfst-render",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "Render Manifest sites to static HTML for SEO",
5
5
  "type": "module",
6
6
  "bin": {