Skip to content

Commit 78d40ac

Browse files
committed
Updated webpack config to use locale title and description
1 parent 66f935b commit 78d40ac

File tree

2 files changed

+113
-104
lines changed

2 files changed

+113
-104
lines changed

packages/ui/src/translation-factory/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ export const translationFunctionFactory =
2525
dictionary: T,
2626
getLanguageCode: () => keyof T[keyof T],
2727
fallbackText?: string,
28-
): ((k: keyof T, r?: Record<string, string>) => string) =>
29-
(k, r = {}) => {
30-
const languageCode = getLanguageCode();
28+
): ((k: keyof T, r?: Record<string, string>, overrideLanguage?: keyof T[keyof T]) => string) =>
29+
(k, r = {}, overrideLanguage) => {
30+
const languageCode = overrideLanguage || getLanguageCode();
3131
return replace(dictionary, languageCode, fallbackText, k, r);
3232
};
3333

web/src/apps/main/entry/webpack.plugins.ts

Lines changed: 110 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import { getCollection } from "@dzcode.io/data/dist/get/collection";
2+
import { allLanguages } from "@dzcode.io/models/dist/language";
3+
import { translationFunctionFactory } from "@dzcode.io/ui/dist/translation-factory";
24
import HtmlWebpackPlugin from "html-webpack-plugin";
35
import { join } from "path";
46

7+
import { dictionary } from "../components/t/dictionary";
58
import config from "./app-config";
69

710
const app = { ...config, name: "main" };
@@ -11,112 +14,118 @@ const gaCode = app.vars.analytics.google;
1114
const fbAppCode = app.vars.plugins.fbAppCode;
1215
const plugins: HtmlWebpackPlugin[] = [];
1316

17+
const t = translationFunctionFactory(dictionary, () => "en");
18+
1419
// SSR --------------------------------|
15-
// Root URL ----
16-
const pages = [
17-
{
18-
uri: "/",
19-
title: "DZ Open-Source | DzCode i/o",
20-
description: "Algerian Open-Source Community",
21-
ogImage:
22-
"https://images.unsplash.com/photo-1527285341945-715b98b98ea2?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1200&h=627&q=80",
23-
themeColor: "#000",
24-
keywords: "",
25-
},
26-
];
27-
// Other URLs
28-
if (process.env.NODE_ENV !== "development") {
29-
// Static URLs ----
30-
pages.push(
31-
...[
32-
{
33-
uri: "/Contribute",
34-
title: "Contribute to algerian open-source projects | DzCode i/o",
35-
description: "Contribute to algerian open-source projects",
36-
ogImage:
37-
"https://images.unsplash.com/photo-1532618500676-2e0cbf7ba8b8?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1200&h=627&q=80",
38-
themeColor: "#000",
39-
keywords: "contribute, open-source, algeria, dzcode",
40-
},
41-
{
42-
uri: "/Learn",
43-
title: "Learn about software development through open-source | DzCode i/o",
44-
description: "Learn, edit and share the knowledge between all Algerian developers!",
45-
ogImage:
46-
"https://images.unsplash.com/photo-1519670107408-15dc1b3ecb1c?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1200&h=627&q=80",
47-
themeColor: "#000",
48-
keywords: "learn, open-source, algeria, dzcode",
49-
},
50-
{
51-
uri: "/Projects",
52-
title: "Browse a growing list of algerian open-source projects | DzCode i/o",
53-
description:
54-
"Browse a growing list of algerian open-source projects and be up-to-date with the state of dz open-source, or Add your own project to the list!",
55-
ogImage:
56-
"https://images.unsplash.com/photo-1531403009284-440f080d1e12?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1200&h=627&q=80",
57-
themeColor: "#000",
58-
keywords: "projects, open-source, algeria, dzcode",
59-
},
60-
{
61-
uri: "/Articles",
62-
title: "Read and discuss articles written by algerian developers | DzCode i/o",
63-
description:
64-
"Browse, read, modify a growing list of articles written by algerian developers, or Add your own article to the list!",
65-
ogImage:
66-
"https://images.unsplash.com/photo-1585241936939-be4099591252?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1200&h=627&q=80",
67-
themeColor: "#000",
68-
keywords: "articles, open-source, algeria, dzcode",
69-
},
70-
{
71-
uri: "/FAQ",
72-
title:
73-
"Understand what exactly is DzCode i/o, get answers to the frequently asked questions | DzCode i/o",
74-
description: "Frequently asked questions about DzCode i/o",
75-
ogImage:
76-
"https://images.unsplash.com/photo-1516246843873-9d12356b6fab?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8https://images.unsplash.com/photo-1516246843873-9d12356b6fab?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=750&q=80&auto=format&fit=crop&w=1200&h=627&q=80",
77-
themeColor: "#000",
78-
keywords: "faq, open-source, algeria, dzcode",
79-
},
80-
{
81-
uri: "/Team",
82-
title: "Meet the team! | DzCode i/o",
83-
description:
84-
"Meet and connect with all the open-source contributors of all the listed projects in dzcode.io website",
85-
ogImage:
86-
"https://images.unsplash.com/photo-1526663089957-f2aa2776f572?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=750&q=80&auto=format&fit=crop&w=1200&h=627&q=80",
87-
themeColor: "#000",
88-
keywords: "faq, open-source, algeria, dzcode",
89-
},
90-
],
91-
);
92-
// Dynamic URLs ----
20+
// Static URLs ----
21+
const pages = (
9322
[
94-
{ file: "articles", slug: "Articles" },
95-
{ file: "documentation", slug: "Learn" },
96-
{ file: "projects", slug: "Projects" },
97-
].forEach((collectionInfo) => {
98-
const collection = getCollection<Record<string, string>>(
99-
join(__dirname, "../../../../../data"),
100-
collectionInfo.file,
101-
"ssr.json",
102-
);
103-
if (!Array.isArray(collection)) {
104-
throw new Error(`Collection is not an array: ${collection}`);
105-
}
106-
collection.forEach((entry) => {
107-
pages.push({
108-
uri: `/${collectionInfo.slug}/${entry.slug}`,
109-
title: `${entry.title} | DzCode i/o`,
110-
description: entry.description,
111-
ogImage: entry.image,
112-
themeColor: "#000",
113-
keywords: entry.keywords,
114-
});
23+
{
24+
uri: "/",
25+
title: "landing-title",
26+
description: "landing-description",
27+
ogImage:
28+
"https://images.unsplash.com/photo-1527285341945-715b98b98ea2?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1200&h=627&q=80",
29+
themeColor: "#000",
30+
keywords: "",
31+
},
32+
{
33+
uri: "/Contribute",
34+
title: "contribute-title",
35+
description: "contribute-description",
36+
ogImage:
37+
"https://images.unsplash.com/photo-1532618500676-2e0cbf7ba8b8?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1200&h=627&q=80",
38+
themeColor: "#000",
39+
keywords: "contribute, open-source, algeria, dzcode",
40+
},
41+
{
42+
uri: "/Learn",
43+
title: "learn-title",
44+
description: "learn-description",
45+
ogImage:
46+
"https://images.unsplash.com/photo-1519670107408-15dc1b3ecb1c?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1200&h=627&q=80",
47+
themeColor: "#000",
48+
keywords: "learn, open-source, algeria, dzcode",
49+
},
50+
{
51+
uri: "/Projects",
52+
title: "projects-title",
53+
description: "projects-description",
54+
ogImage:
55+
"https://images.unsplash.com/photo-1531403009284-440f080d1e12?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1200&h=627&q=80",
56+
themeColor: "#000",
57+
keywords: "projects, open-source, algeria, dzcode",
58+
},
59+
{
60+
uri: "/Articles",
61+
title: "articles-title",
62+
description: "articles-description",
63+
ogImage:
64+
"https://images.unsplash.com/photo-1585241936939-be4099591252?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1200&h=627&q=80",
65+
themeColor: "#000",
66+
keywords: "articles, open-source, algeria, dzcode",
67+
},
68+
{
69+
uri: "/FAQ",
70+
title: "faq-title",
71+
description: "faq-description",
72+
ogImage:
73+
"https://images.unsplash.com/photo-1516246843873-9d12356b6fab?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8https://images.unsplash.com/photo-1516246843873-9d12356b6fab?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=750&q=80&auto=format&fit=crop&w=1200&h=627&q=80",
74+
themeColor: "#000",
75+
keywords: "faq, open-source, algeria, dzcode",
76+
},
77+
{
78+
uri: "/Team",
79+
title: "team-title",
80+
description: "team-description",
81+
ogImage:
82+
"https://images.unsplash.com/photo-1526663089957-f2aa2776f572?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=750&q=80&auto=format&fit=crop&w=1200&h=627&q=80",
83+
themeColor: "#000",
84+
keywords: "faq, open-source, algeria, dzcode",
85+
},
86+
] as const
87+
).reduce(
88+
(pV, { title, description, uri, ...page }) => [
89+
...pV,
90+
...allLanguages.map(({ code }) => ({
91+
...page,
92+
title: t(title, undefined, code),
93+
description: t(description, undefined, code),
94+
uri: code === "en" ? uri : `/${code}${uri}`,
95+
})),
96+
],
97+
[] as any[],
98+
);
99+
100+
// Dynamic URLs ----
101+
// @TODO-ZM: to localize this
102+
[
103+
{ file: "articles", slug: "Articles" },
104+
{ file: "documentation", slug: "Learn" },
105+
{ file: "projects", slug: "Projects" },
106+
].forEach((collectionInfo) => {
107+
const collection = getCollection<Record<string, string>>(
108+
join(__dirname, "../../../../../data"),
109+
collectionInfo.file,
110+
"ssr.json",
111+
);
112+
if (!Array.isArray(collection)) {
113+
throw new Error(`Collection is not an array: ${collection}`);
114+
}
115+
collection.forEach((entry) => {
116+
pages.push({
117+
uri: `/${collectionInfo.slug}/${entry.slug}`,
118+
title: `${entry.title} | DzCode i/o`,
119+
description: entry.description,
120+
ogImage: entry.image,
121+
themeColor: "#000",
122+
keywords: entry.keywords,
115123
});
116124
});
117-
}
125+
});
126+
118127
// Convert pages into html webpack plugins
119-
pages.forEach((page) => {
128+
(process.env.NODE_ENV === "development" ? [pages[0]] : pages).forEach((page) => {
120129
plugins.push(
121130
new HtmlWebpackPlugin({
122131
filename: (page.uri !== "/" ? `${page.uri}/index.html` : "/index.html").substring(1),

0 commit comments

Comments
 (0)