Skip to content

Commit 4735788

Browse files
create article ids in locale
1 parent 054f8d9 commit 4735788

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

resources/newssite/news-nuxt/composables/provide-locale.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { provide } from "vue";
22
import { useHead } from "#imports";
33
import { dataSource } from "../data";
44

5+
import { v4 as uuidv4 } from "uuid";
6+
57
const RTL_LOCALES = ["ar", "he", "fa", "ps", "ur"];
68
const DEFAULT_LANG = "en";
79
const DEFAULT_DIR = "ltr";
@@ -16,10 +18,41 @@ export function provideLocale() {
1618
htmlAttrs: { dir, lang },
1719
});
1820

21+
const { content } = dataSource[lang];
22+
23+
// Generate unique IDs for all articles, and their content items where appropriate.
24+
const contentWithIds = Object.create(null);
25+
Object.keys(content).forEach((key) => {
26+
const { sections } = content[key];
27+
28+
const currentSections = sections.map((section) => {
29+
const currentSection = { ...section };
30+
currentSection.articles = section.articles.map((article) => {
31+
const currentArticle = { ...article };
32+
currentArticle.id = uuidv4();
33+
if (Array.isArray(article.content)) {
34+
currentArticle.content = article.content.map((item) => {
35+
const currentItem = { ...item };
36+
currentItem.id = uuidv4();
37+
return currentItem;
38+
});
39+
}
40+
return currentArticle;
41+
});
42+
return currentSection;
43+
});
44+
45+
contentWithIds[key] = {
46+
...content[key],
47+
sections: currentSections,
48+
};
49+
});
50+
1951
const value = {
2052
lang,
2153
dir,
2254
...dataSource[lang],
55+
content: contentWithIds,
2356
};
2457

2558
provide("data", value);

0 commit comments

Comments
 (0)