Skip to content

Commit 9f85f8e

Browse files
News Site Nuxt - Article Ids (#448)
1 parent 2ff56c9 commit 9f85f8e

File tree

9 files changed

+67
-15
lines changed

9 files changed

+67
-15
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);

resources/newssite/news-nuxt/dist/404.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
<head><meta charset="utf-8">
44
<title>The Daily Broadcast</title>
55
<meta name="viewport" content="width=device-width, initial-scale=1">
6-
<meta name="description" content="A news site developed with Nuxt."><link rel="modulepreload" as="script" crossorigin href="./_nuxt/entry.ab49470b.js"><link rel="preload" as="style" href="./_nuxt/entry.4163a698.css"><link rel="prefetch" as="script" crossorigin href="./_nuxt/error-component.98713fee.js"><link rel="stylesheet" href="./_nuxt/entry.4163a698.css"></head>
7-
<body ><div id="__nuxt"></div><script type="application/json" id="__NUXT_DATA__" data-ssr="false">[{"_errors":1,"serverRendered":2,"data":3,"state":4},{},false,{},{}]</script><script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"./",buildAssetsDir:"/_nuxt/",cdnURL:"./"}}</script><script type="module" src="./_nuxt/entry.ab49470b.js" crossorigin></script></body>
6+
<meta name="description" content="A news site developed with Nuxt."><link rel="modulepreload" as="script" crossorigin href="./_nuxt/entry.61b8a168.js"><link rel="preload" as="style" href="./_nuxt/entry.4163a698.css"><link rel="prefetch" as="script" crossorigin href="./_nuxt/error-component.2cb571d2.js"><link rel="stylesheet" href="./_nuxt/entry.4163a698.css"></head>
7+
<body ><div id="__nuxt"></div><script type="application/json" id="__NUXT_DATA__" data-ssr="false">[{"_errors":1,"serverRendered":2,"data":3,"state":4},{},false,{},{}]</script><script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"./",buildAssetsDir:"/_nuxt/",cdnURL:"./"}}</script><script type="module" src="./_nuxt/entry.61b8a168.js" crossorigin></script></body>
88
</html>

resources/newssite/news-nuxt/dist/_nuxt/entry.ab49470b.js renamed to resources/newssite/news-nuxt/dist/_nuxt/entry.61b8a168.js

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

resources/newssite/news-nuxt/dist/_nuxt/error-404.cfea4b42.js renamed to resources/newssite/news-nuxt/dist/_nuxt/error-404.2a577bdf.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

resources/newssite/news-nuxt/dist/_nuxt/error-500.24e732f2.js renamed to resources/newssite/news-nuxt/dist/_nuxt/error-500.c1eac2b8.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

resources/newssite/news-nuxt/dist/_nuxt/error-component.98713fee.js renamed to resources/newssite/news-nuxt/dist/_nuxt/error-component.2cb571d2.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

resources/newssite/news-nuxt/dist/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
<head><meta charset="utf-8">
44
<title>The Daily Broadcast</title>
55
<meta name="viewport" content="width=device-width, initial-scale=1">
6-
<meta name="description" content="A news site developed with Nuxt."><link rel="modulepreload" as="script" crossorigin href="./_nuxt/entry.ab49470b.js"><link rel="preload" as="style" href="./_nuxt/entry.4163a698.css"><link rel="prefetch" as="script" crossorigin href="./_nuxt/error-component.98713fee.js"><link rel="stylesheet" href="./_nuxt/entry.4163a698.css"></head>
7-
<body ><div id="__nuxt"></div><script type="application/json" id="__NUXT_DATA__" data-ssr="false">[{"_errors":1,"serverRendered":2,"data":3,"state":4},{},false,{},{}]</script><script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"./",buildAssetsDir:"/_nuxt/",cdnURL:"./"}}</script><script type="module" src="./_nuxt/entry.ab49470b.js" crossorigin></script></body>
6+
<meta name="description" content="A news site developed with Nuxt."><link rel="modulepreload" as="script" crossorigin href="./_nuxt/entry.61b8a168.js"><link rel="preload" as="style" href="./_nuxt/entry.4163a698.css"><link rel="prefetch" as="script" crossorigin href="./_nuxt/error-component.2cb571d2.js"><link rel="stylesheet" href="./_nuxt/entry.4163a698.css"></head>
7+
<body ><div id="__nuxt"></div><script type="application/json" id="__NUXT_DATA__" data-ssr="false">[{"_errors":1,"serverRendered":2,"data":3,"state":4},{},false,{},{}]</script><script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"./",buildAssetsDir:"/_nuxt/",cdnURL:"./"}}</script><script type="module" src="./_nuxt/entry.61b8a168.js" crossorigin></script></body>
88
</html>

resources/newssite/news-nuxt/package-lock.json

Lines changed: 19 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

resources/newssite/news-nuxt/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
},
2222
"dependencies": {
2323
"http-server": "^14.1.1",
24-
"news-site-css": "file:../news-site-css"
24+
"news-site-css": "file:../news-site-css",
25+
"uuid": "^9.0.0"
2526
}
2627
}

0 commit comments

Comments
 (0)