-
Notifications
You must be signed in to change notification settings - Fork 90
News Site Nuxt - Article Ids #448
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
Changes from all commits
b85ffd7
7255eff
bec5d4e
7a460f8
be0a710
db2e943
252114d
3fb9c89
3a326cd
a198da0
da78dca
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -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"; | ||||||||||||||||
|
@@ -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; | ||||||||||||||||
Comment on lines
+35
to
+37
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wanted to (optionally) suggest this:
Suggested change
but I'm not sure this looks better. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||||||||||||||||
|
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.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.