@seip/blue-bird 0.3.7 → 0.3.9
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/backend/routes/frontend.js +3 -20
- package/core/router.js +92 -0
- package/core/template.js +4 -0
- package/frontend.js +59 -0
- package/package.json +1 -1
|
@@ -3,37 +3,20 @@ import Template from "@seip/blue-bird/core/template.js"
|
|
|
3
3
|
|
|
4
4
|
const routerFrontendExample = new Router();
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
routerFrontendExample.seo([
|
|
7
7
|
{
|
|
8
8
|
path: "/",
|
|
9
9
|
component: "Home",
|
|
10
10
|
meta: { titleMeta: "Home - Blue Bird", descriptionMeta: "Welcome to Blue Bird" },
|
|
11
11
|
props: { id: 1, name: "Name" }
|
|
12
|
-
|
|
13
12
|
},
|
|
14
13
|
{
|
|
15
14
|
path: "/about",
|
|
16
15
|
component: "About",
|
|
17
|
-
meta: { titleMeta: "
|
|
16
|
+
meta: { titleMeta: "Aboutt - Blue Bird", descriptionMeta: "About blue bird", keywordsMeta: "Blue Bird, About Blue Bird" },
|
|
18
17
|
props: { id: 2, name: "Name 2" }
|
|
19
18
|
},
|
|
20
|
-
|
|
21
|
-
];
|
|
22
|
-
routesFrontend.forEach(route_ => {
|
|
23
|
-
routerFrontendExample.get(route_.path, (req, res) => {
|
|
24
|
-
const dynamicProps = {
|
|
25
|
-
props: {
|
|
26
|
-
params: req.params,
|
|
27
|
-
query: req.query,
|
|
28
|
-
...route_.props ?? {}
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
return Template.renderReact(res, route_.component, dynamicProps, {
|
|
33
|
-
metaTags: route_.meta,
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
});
|
|
19
|
+
])
|
|
37
20
|
|
|
38
21
|
|
|
39
22
|
routerFrontendExample.get("*", (req, res) => {
|
package/core/router.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import express from "express";
|
|
2
2
|
import Config from "./config.js";
|
|
3
|
+
import Template from "./template.js";
|
|
3
4
|
|
|
4
5
|
const __dirname = Config.dirname()
|
|
5
6
|
const props = Config.props()
|
|
@@ -131,5 +132,96 @@ class Router {
|
|
|
131
132
|
getPath() {
|
|
132
133
|
return this.path
|
|
133
134
|
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Registers multiple routes based on an SEO configuration array.
|
|
138
|
+
* Supports both multi-language (e.g., en, es keys) and single-language (meta key) formats.
|
|
139
|
+
*
|
|
140
|
+
* @param {Array<Object>} routesConfig - Array of route objects.
|
|
141
|
+
* @param {Object} [options={}] - Configuration options.
|
|
142
|
+
* @param {Array<string>} [options.languages] - List of languages to register (e.g., ["en", "es"]).
|
|
143
|
+
* @param {string} [options.defaultLanguage="en"] - The default language for the base path.
|
|
144
|
+
* @param {Function} [options.templateRenderer] - Optional custom template renderer (defaults to Template.renderReact).
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* router.seo([
|
|
148
|
+
* {
|
|
149
|
+
* path: "/",
|
|
150
|
+
* component: "Home",
|
|
151
|
+
* meta: { titleMeta: "Home - Blue Bird", descriptionMeta: "Welcome to Blue Bird" },
|
|
152
|
+
* props: { id: 1, name: "Name 1" }
|
|
153
|
+
* },
|
|
154
|
+
* {
|
|
155
|
+
* path: "/about",
|
|
156
|
+
* component: "About",
|
|
157
|
+
* meta: { titleMeta: "About - Blue Bird", descriptionMeta: "About blue bird" },
|
|
158
|
+
* props: { id: 2, name: "Name 2" }
|
|
159
|
+
* }
|
|
160
|
+
* ], { languages: ["en", "es"], defaultLanguage: "en" });
|
|
161
|
+
*/
|
|
162
|
+
seo(routesConfig, options = {}) {
|
|
163
|
+
const {
|
|
164
|
+
languages = [],
|
|
165
|
+
defaultLanguage = "en",
|
|
166
|
+
templateRenderer
|
|
167
|
+
} = options;
|
|
168
|
+
|
|
169
|
+
const render = templateRenderer || ((res, component, props, renderOptions) => {
|
|
170
|
+
return Template.renderReact(res, component, props, renderOptions);
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
routesConfig.forEach(route => {
|
|
174
|
+
const { path, component, props = {}, meta = {} } = route;
|
|
175
|
+
|
|
176
|
+
if (Object.keys(meta).length > 0 || route.titleMeta) {
|
|
177
|
+
this.get(path, (req, res) => {
|
|
178
|
+
const dynamicProps = {
|
|
179
|
+
props: {
|
|
180
|
+
...props,
|
|
181
|
+
params: req.params,
|
|
182
|
+
query: req.query
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
return render(res, component, dynamicProps, {
|
|
186
|
+
metaTags: meta.titleMeta ? meta : {
|
|
187
|
+
titleMeta: route.titleMeta || meta.title,
|
|
188
|
+
descriptionMeta: route.descriptionMeta || meta.description || meta.desc,
|
|
189
|
+
keywordsMeta: route.keywordsMeta || meta.keywords,
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
const detectedLanguages = languages.length > 0
|
|
196
|
+
? languages
|
|
197
|
+
: Object.keys(route).filter(key => key.length === 2);
|
|
198
|
+
|
|
199
|
+
detectedLanguages.forEach(lang => {
|
|
200
|
+
if (typeof route[lang] === "object") {
|
|
201
|
+
const langData = route[lang];
|
|
202
|
+
const isDefault = lang === defaultLanguage;
|
|
203
|
+
const langPath = isDefault ? path : `/${lang}${path === "/" ? "" : path}`;
|
|
204
|
+
|
|
205
|
+
this.get(langPath, (req, res) => {
|
|
206
|
+
const dynamicProps = {
|
|
207
|
+
props: {
|
|
208
|
+
...props,
|
|
209
|
+
params: req.params,
|
|
210
|
+
query: req.query
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
return render(res, component, dynamicProps, {
|
|
214
|
+
metaTags: {
|
|
215
|
+
titleMeta: langData.title || langData.titleMeta,
|
|
216
|
+
descriptionMeta: langData.desc || langData.description || langData.descriptionMeta,
|
|
217
|
+
keywordsMeta: langData.keywords || langData.keywordsMeta,
|
|
218
|
+
langMeta: lang
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
});
|
|
225
|
+
}
|
|
134
226
|
}
|
|
135
227
|
export default Router;
|
package/core/template.js
CHANGED
package/frontend.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import Router from "@seip/blue-bird/core/router.js"
|
|
2
|
+
import Template from "@seip/blue-bird/core/template.js"
|
|
3
|
+
|
|
4
|
+
const routerFrontendExample = new Router();
|
|
5
|
+
|
|
6
|
+
// const routesFrontend = [
|
|
7
|
+
// {
|
|
8
|
+
// path: "/",
|
|
9
|
+
// component: "Home",
|
|
10
|
+
// meta: { titleMeta: "Home - Blue Bird", descriptionMeta: "Welcome to Blue Bird" },
|
|
11
|
+
// props: { id: 1, name: "Name" }
|
|
12
|
+
|
|
13
|
+
// },
|
|
14
|
+
// {
|
|
15
|
+
// path: "/about",
|
|
16
|
+
// component: "About",
|
|
17
|
+
// meta: { titleMeta: "About - Blue Bird", descriptionMeta: "About blue bird" },
|
|
18
|
+
// props: { id: 2, name: "Name 2" }
|
|
19
|
+
// },
|
|
20
|
+
|
|
21
|
+
// ];
|
|
22
|
+
// routesFrontend.forEach(route_ => {
|
|
23
|
+
// routerFrontendExample.get(route_.path, (req, res) => {
|
|
24
|
+
// const dynamicProps = {
|
|
25
|
+
// props: {
|
|
26
|
+
// params: req.params,
|
|
27
|
+
// query: req.query,
|
|
28
|
+
// ...route_.props ?? {}
|
|
29
|
+
// }
|
|
30
|
+
// };
|
|
31
|
+
|
|
32
|
+
// return Template.renderReact(res, route_.component, dynamicProps, {
|
|
33
|
+
// metaTags: route_.meta,
|
|
34
|
+
// });
|
|
35
|
+
// });
|
|
36
|
+
// });
|
|
37
|
+
|
|
38
|
+
routerFrontendExample.seo([
|
|
39
|
+
{
|
|
40
|
+
path: "/",
|
|
41
|
+
component: "Home",
|
|
42
|
+
meta: { titleMeta: "Home - Blue Bird", descriptionMeta: "Welcome to Blue Bird" },
|
|
43
|
+
props: { id: 1, name: "Name" }
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
path: "/about",
|
|
47
|
+
component: "About",
|
|
48
|
+
meta: { titleMeta: "About - Blue Bird", descriptionMeta: "About blue bird" },
|
|
49
|
+
props: { id: 2, name: "Name 2" }
|
|
50
|
+
},
|
|
51
|
+
])
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
routerFrontendExample.get("*", (req, res) => {
|
|
55
|
+
const response = Template.renderReact(res, "App");
|
|
56
|
+
return response;
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
export default routerFrontendExample;
|