mnfst 0.5.34 → 0.5.36
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.
- package/dist/manifest.localization.js +24 -0
- package/package.json +10 -7
|
@@ -89,6 +89,20 @@ function initializeLocalizationPlugin() {
|
|
|
89
89
|
return rtlLanguages.has(lang);
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
+
function isPrerenderedStaticBuild() {
|
|
93
|
+
return document.head?.querySelector('meta[name="manifest:prerendered"][content="1"]') !== null;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function buildLocaleNavigationUrl(newLang, availableLocales) {
|
|
97
|
+
const currentUrl = new URL(window.location.href);
|
|
98
|
+
const pathParts = currentUrl.pathname.split('/').filter(Boolean);
|
|
99
|
+
const hasLanguageInUrl = pathParts[0] && availableLocales.includes(pathParts[0]);
|
|
100
|
+
if (hasLanguageInUrl) pathParts[0] = newLang;
|
|
101
|
+
else pathParts.unshift(newLang);
|
|
102
|
+
currentUrl.pathname = '/' + pathParts.join('/');
|
|
103
|
+
return currentUrl.toString();
|
|
104
|
+
}
|
|
105
|
+
|
|
92
106
|
// Input validation for language codes
|
|
93
107
|
function isValidLanguageCode(lang) {
|
|
94
108
|
if (typeof lang !== 'string' || lang.length === 0) return false;
|
|
@@ -313,6 +327,16 @@ function initializeLocalizationPlugin() {
|
|
|
313
327
|
|
|
314
328
|
|
|
315
329
|
try {
|
|
330
|
+
// In prerendered static output, locale switching must navigate to a locale URL.
|
|
331
|
+
// Mutating Alpine store alone won't re-render baked static content.
|
|
332
|
+
if (isPrerenderedStaticBuild()) {
|
|
333
|
+
const targetUrl = buildLocaleNavigationUrl(newLang, store.available || []);
|
|
334
|
+
if (targetUrl !== window.location.href) {
|
|
335
|
+
window.location.assign(targetUrl);
|
|
336
|
+
}
|
|
337
|
+
return true;
|
|
338
|
+
}
|
|
339
|
+
|
|
316
340
|
// Update store
|
|
317
341
|
store.current = newLang;
|
|
318
342
|
store.direction = isRTL(newLang) ? 'rtl' : 'ltr';
|
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mnfst",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.36",
|
|
4
4
|
"private": false,
|
|
5
5
|
"workspaces": [
|
|
6
|
-
"templates/starter"
|
|
6
|
+
"templates/starter",
|
|
7
|
+
"packages/render"
|
|
7
8
|
],
|
|
8
9
|
"main": "dist/manifest.js",
|
|
9
10
|
"style": "dist/manifest.css",
|
|
@@ -13,16 +14,18 @@
|
|
|
13
14
|
"LICENSE"
|
|
14
15
|
],
|
|
15
16
|
"scripts": {
|
|
16
|
-
"clean": "rimraf src/scripts/manifest.js src/styles/manifest.css src/styles/manifest.min.css src/styles/manifest.code.min.css dist",
|
|
17
|
+
"clean": "rimraf src/scripts/manifest.js src/scripts/manifest.render.mjs src/styles/manifest.css src/styles/manifest.min.css src/styles/manifest.code.min.css dist",
|
|
17
18
|
"build": "cd src && node scripts/build.mjs",
|
|
18
19
|
"build:docs": "echo 'Docs is a static website - no build needed'",
|
|
19
20
|
"start:src": "cd src && browser-sync start --config bs-config.js",
|
|
20
21
|
"start:docs": "cd docs && browser-sync start --config bs-config.js",
|
|
21
22
|
"start:starter": "cd templates/starter && browser-sync start --config bs-config.js --port 3001",
|
|
22
|
-
"prerender": "node src/
|
|
23
|
-
"prerender:docs": "node src/
|
|
24
|
-
"prerender:starter": "node src/
|
|
23
|
+
"prerender": "node src/scripts/manifest.render.mjs --root src",
|
|
24
|
+
"prerender:docs": "node src/scripts/manifest.render.mjs --root docs",
|
|
25
|
+
"prerender:starter": "node src/scripts/manifest.render.mjs --root templates/starter",
|
|
26
|
+
"render": "node src/scripts/manifest.render.mjs --root src",
|
|
25
27
|
"publish:starter": "cd packages/create-starter && npm publish --auth-type=web",
|
|
28
|
+
"publish:render": "cd packages/render && npm publish --auth-type=web",
|
|
26
29
|
"prepublishOnly": "npm run build",
|
|
27
30
|
"test": "echo 'No tests configured'",
|
|
28
31
|
"lint": "echo 'No linting configured'"
|
|
@@ -59,4 +62,4 @@
|
|
|
59
62
|
"bugs": {
|
|
60
63
|
"url": "https://github.com/andrewmatlock/manifest/issues"
|
|
61
64
|
}
|
|
62
|
-
}
|
|
65
|
+
}
|