Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

News Site Nuxt - Article Ids #448

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 },
});

flashdesignory marked this conversation as resolved.
Show resolved Hide resolved
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;
Comment on lines +35 to +37
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to (optionally) suggest this:

Suggested change
const currentItem = { ...item };
currentItem.id = uuidv4();
return currentItem;
return {
...item,
id: uuidv4();
};

but I'm not sure this looks better.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know what you mean. I think I'd rather keep things consistent (visually) and treat currentArticle and currentItem the same way.

});
}
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"
}
}
Loading