@@ -2,6 +2,8 @@ import { provide } from "vue";
22import { useHead } from "#imports" ;
33import { dataSource } from "../data" ;
44
5+ import { v4 as uuidv4 } from "uuid" ;
6+
57const RTL_LOCALES = [ "ar" , "he" , "fa" , "ps" , "ur" ] ;
68const DEFAULT_LANG = "en" ;
79const 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