Skip to content

Commit

Permalink
News Site Nuxt - Article Ids (#448)
Browse files Browse the repository at this point in the history
  • Loading branch information
flashdesignory authored Jan 21, 2025
1 parent 2ff56c9 commit 9f85f8e
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 15 deletions.
33 changes: 33 additions & 0 deletions resources/newssite/news-nuxt/composables/provide-locale.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { provide } from "vue";
import { useHead } from "#imports";
import { dataSource } from "../data";

import { v4 as uuidv4 } from "uuid";

const RTL_LOCALES = ["ar", "he", "fa", "ps", "ur"];
const DEFAULT_LANG = "en";
const DEFAULT_DIR = "ltr";
Expand All @@ -16,10 +18,41 @@ export function provideLocale() {
htmlAttrs: { dir, lang },
});

const { content } = dataSource[lang];

// Generate unique IDs for all articles, and their content items where appropriate.
const contentWithIds = Object.create(null);
Object.keys(content).forEach((key) => {
const { sections } = content[key];

const currentSections = sections.map((section) => {
const currentSection = { ...section };
currentSection.articles = section.articles.map((article) => {
const currentArticle = { ...article };
currentArticle.id = uuidv4();
if (Array.isArray(article.content)) {
currentArticle.content = article.content.map((item) => {
const currentItem = { ...item };
currentItem.id = uuidv4();
return currentItem;
});
}
return currentArticle;
});
return currentSection;
});

contentWithIds[key] = {
...content[key],
sections: currentSections,
};
});

const value = {
lang,
dir,
...dataSource[lang],
content: contentWithIds,
};

provide("data", value);
Expand Down
4 changes: 2 additions & 2 deletions resources/newssite/news-nuxt/dist/404.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
<head><meta charset="utf-8">
<title>The Daily Broadcast</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<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>
<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>
<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>
<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>
</html>

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions resources/newssite/news-nuxt/dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
<head><meta charset="utf-8">
<title>The Daily Broadcast</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<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>
<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>
<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>
<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>
</html>
20 changes: 19 additions & 1 deletion resources/newssite/news-nuxt/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion resources/newssite/news-nuxt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
},
"dependencies": {
"http-server": "^14.1.1",
"news-site-css": "file:../news-site-css"
"news-site-css": "file:../news-site-css",
"uuid": "^9.0.0"
}
}

0 comments on commit 9f85f8e

Please sign in to comment.