@cocreate/server-side-render 1.12.5 → 1.12.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.
- package/CHANGELOG.md +14 -0
- package/package.json +1 -1
- package/src/index.js +28 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
## [1.12.7](https://github.com/CoCreate-app/CoCreate-server-side-render/compare/v1.12.6...v1.12.7) (2025-10-11)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* add theme injection to HTML rendering for improved client-side styling ([e849c72](https://github.com/CoCreate-app/CoCreate-server-side-render/commit/e849c72cf4112c8e6caa44187bca3fada5ff72cc))
|
|
7
|
+
|
|
8
|
+
## [1.12.6](https://github.com/CoCreate-app/CoCreate-server-side-render/compare/v1.12.5...v1.12.6) (2025-10-11)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* ensure pathname ends with a trailing slash for correct URL construction in HTML rendering ([5122e24](https://github.com/CoCreate-app/CoCreate-server-side-render/commit/5122e2413a986ebe51cb4a48ab92387aad4b5727))
|
|
14
|
+
|
|
1
15
|
## [1.12.5](https://github.com/CoCreate-app/CoCreate-server-side-render/compare/v1.12.4...v1.12.5) (2025-10-08)
|
|
2
16
|
|
|
3
17
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocreate/server-side-render",
|
|
3
|
-
"version": "1.12.
|
|
3
|
+
"version": "1.12.7",
|
|
4
4
|
"description": "A simple server-side-render component in vanilla javascript. Easily configured using HTML5 data-attributes and/or JavaScript API.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"server-side-render",
|
package/src/index.js
CHANGED
|
@@ -7,7 +7,7 @@ class CoCreateServerSideRender {
|
|
|
7
7
|
this.crud = crud;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
async HTML(file, organization, urlObject, langRegion, lang) {
|
|
10
|
+
async HTML(file, organization, urlObject, langRegion, lang, theme) {
|
|
11
11
|
const self = this;
|
|
12
12
|
let ignoreElement = {
|
|
13
13
|
INPUT: true,
|
|
@@ -107,8 +107,12 @@ class CoCreateServerSideRender {
|
|
|
107
107
|
src = src.replaceAll(/\$relativePath\/?/g, path);
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
+
let pathname = file.path
|
|
111
|
+
if (!pathname.endsWith("/")) {
|
|
112
|
+
pathname += "/";
|
|
113
|
+
}
|
|
110
114
|
// Construct actual pathname using src and the original URL
|
|
111
|
-
|
|
115
|
+
pathname = new URL(src, `http://localhost${pathname}`)
|
|
112
116
|
.pathname;
|
|
113
117
|
|
|
114
118
|
if (pathname.endsWith("/")) {
|
|
@@ -172,6 +176,28 @@ class CoCreateServerSideRender {
|
|
|
172
176
|
dom = await this.translate(dom, file, langRegion, lang);
|
|
173
177
|
}
|
|
174
178
|
|
|
179
|
+
// Inject preferred theme into the DOM so client gets server-rendered theme
|
|
180
|
+
if (theme) {
|
|
181
|
+
const htmlEl = dom.querySelector("html");
|
|
182
|
+
try {
|
|
183
|
+
if (htmlEl && htmlEl.setAttribute) htmlEl.setAttribute("data-bs-theme", theme);
|
|
184
|
+
|
|
185
|
+
const head = dom.querySelector("head");
|
|
186
|
+
if (head) {
|
|
187
|
+
// add or update color-scheme meta tag
|
|
188
|
+
let meta = head.querySelector('meta[name="color-scheme"]');
|
|
189
|
+
if (meta && meta.setAttribute) {
|
|
190
|
+
meta.setAttribute("content", theme);
|
|
191
|
+
} else {
|
|
192
|
+
const metaNode = parse(`<meta name="color-scheme" content="${theme}">`);
|
|
193
|
+
head.appendChild(metaNode);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
} catch (e) {
|
|
197
|
+
// fail-safe: don't abort rendering if theme injection fails
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
175
201
|
if (organization.languages && organization.languages.length > 0) {
|
|
176
202
|
let langLinkTags = this.createLanguageLinkTags(
|
|
177
203
|
file,
|