Skip to content

Commit

Permalink
News Site Next - Article Ids (#447)
Browse files Browse the repository at this point in the history
  • Loading branch information
flashdesignory authored Jan 21, 2025
1 parent d979723 commit 2ff56c9
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 9 deletions.
2 changes: 1 addition & 1 deletion resources/newssite/news-next/dist/404.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!DOCTYPE html><html lang="en"><head><meta charSet="utf-8"/><meta name="viewport" content="width=device-width"/><meta name="next-head-count" content="2"/><link rel="preload" href="./_next/static/css/a0dca1379a01e5cf.css" as="style"/><link rel="stylesheet" href="./_next/static/css/a0dca1379a01e5cf.css" data-n-g=""/><noscript data-n-css=""></noscript><script defer="" nomodule="" src="./_next/static/chunks/polyfills-c67a75d1b6f99dc8.js"></script><script src="./_next/static/chunks/webpack-e50e9853db18b759.js" defer=""></script><script src="./_next/static/chunks/framework-2c79e2a64abdb08b.js" defer=""></script><script src="./_next/static/chunks/main-2ba37e62325cc71b.js" defer=""></script><script src="./_next/static/chunks/pages/_app-77983e68be50f72a.js" defer=""></script><script src="./_next/static/chunks/pages/_error-54de1933a164a1ff.js" defer=""></script><script src="./_next/static/dKI4-ZnFPRMFEw-AlcuLr/_buildManifest.js" defer=""></script><script src="./_next/static/dKI4-ZnFPRMFEw-AlcuLr/_ssgManifest.js" defer=""></script></head><body><div id="__next"></div><div id="settings-container"></div><div id="notifications-container"></div><script id="__NEXT_DATA__" type="application/json">{"props":{"pageProps":{"statusCode":404}},"page":"/_error","query":{},"buildId":"dKI4-ZnFPRMFEw-AlcuLr","assetPrefix":".","nextExport":true,"isFallback":false,"gip":true,"scriptLoader":[]}</script></body></html>
<!DOCTYPE html><html lang="en"><head><meta charSet="utf-8"/><meta name="viewport" content="width=device-width"/><meta name="next-head-count" content="2"/><link rel="preload" href="./_next/static/css/a0dca1379a01e5cf.css" as="style"/><link rel="stylesheet" href="./_next/static/css/a0dca1379a01e5cf.css" data-n-g=""/><noscript data-n-css=""></noscript><script defer="" nomodule="" src="./_next/static/chunks/polyfills-c67a75d1b6f99dc8.js"></script><script src="./_next/static/chunks/webpack-e50e9853db18b759.js" defer=""></script><script src="./_next/static/chunks/framework-2c79e2a64abdb08b.js" defer=""></script><script src="./_next/static/chunks/main-2ba37e62325cc71b.js" defer=""></script><script src="./_next/static/chunks/pages/_app-77983e68be50f72a.js" defer=""></script><script src="./_next/static/chunks/pages/_error-54de1933a164a1ff.js" defer=""></script><script src="./_next/static/IbZpY6lpxNCTHGQFLD2XQ/_buildManifest.js" defer=""></script><script src="./_next/static/IbZpY6lpxNCTHGQFLD2XQ/_ssgManifest.js" defer=""></script></head><body><div id="__next"></div><div id="settings-container"></div><div id="notifications-container"></div><script id="__NEXT_DATA__" type="application/json">{"props":{"pageProps":{"statusCode":404}},"page":"/_error","query":{},"buildId":"IbZpY6lpxNCTHGQFLD2XQ","assetPrefix":".","nextExport":true,"isFallback":false,"gip":true,"scriptLoader":[]}</script></body></html>

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

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
self.__SSG_MANIFEST=new Set,self.__SSG_MANIFEST_CB&&self.__SSG_MANIFEST_CB();

Large diffs are not rendered by default.

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

2 changes: 1 addition & 1 deletion resources/newssite/news-next/dist/index.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!DOCTYPE html><html lang="en"><head><meta charSet="utf-8"/><meta name="viewport" content="width=device-width"/><meta name="next-head-count" content="2"/><link rel="preload" href="./_next/static/css/a0dca1379a01e5cf.css" as="style"/><link rel="stylesheet" href="./_next/static/css/a0dca1379a01e5cf.css" data-n-g=""/><link rel="preload" href="./_next/static/css/2cf5163b53bb0adb.css" as="style"/><link rel="stylesheet" href="./_next/static/css/2cf5163b53bb0adb.css" data-n-p=""/><noscript data-n-css=""></noscript><script defer="" nomodule="" src="./_next/static/chunks/polyfills-c67a75d1b6f99dc8.js"></script><script src="./_next/static/chunks/webpack-e50e9853db18b759.js" defer=""></script><script src="./_next/static/chunks/framework-2c79e2a64abdb08b.js" defer=""></script><script src="./_next/static/chunks/main-2ba37e62325cc71b.js" defer=""></script><script src="./_next/static/chunks/pages/_app-77983e68be50f72a.js" defer=""></script><script src="./_next/static/chunks/743-fd706aeabb7828e3.js" defer=""></script><script src="./_next/static/chunks/pages/index-5268ea812327eb5e.js" defer=""></script><script src="./_next/static/dKI4-ZnFPRMFEw-AlcuLr/_buildManifest.js" defer=""></script><script src="./_next/static/dKI4-ZnFPRMFEw-AlcuLr/_ssgManifest.js" defer=""></script></head><body><div id="__next"></div><div id="settings-container"></div><div id="notifications-container"></div><script id="__NEXT_DATA__" type="application/json">{"props":{"pageProps":{}},"page":"/","query":{},"buildId":"dKI4-ZnFPRMFEw-AlcuLr","assetPrefix":".","nextExport":true,"autoExport":true,"isFallback":false,"scriptLoader":[]}</script></body></html>
<!DOCTYPE html><html lang="en"><head><meta charSet="utf-8"/><meta name="viewport" content="width=device-width"/><meta name="next-head-count" content="2"/><link rel="preload" href="./_next/static/css/a0dca1379a01e5cf.css" as="style"/><link rel="stylesheet" href="./_next/static/css/a0dca1379a01e5cf.css" data-n-g=""/><link rel="preload" href="./_next/static/css/2cf5163b53bb0adb.css" as="style"/><link rel="stylesheet" href="./_next/static/css/2cf5163b53bb0adb.css" data-n-p=""/><noscript data-n-css=""></noscript><script defer="" nomodule="" src="./_next/static/chunks/polyfills-c67a75d1b6f99dc8.js"></script><script src="./_next/static/chunks/webpack-e50e9853db18b759.js" defer=""></script><script src="./_next/static/chunks/framework-2c79e2a64abdb08b.js" defer=""></script><script src="./_next/static/chunks/main-2ba37e62325cc71b.js" defer=""></script><script src="./_next/static/chunks/pages/_app-77983e68be50f72a.js" defer=""></script><script src="./_next/static/chunks/743-fd706aeabb7828e3.js" defer=""></script><script src="./_next/static/chunks/pages/index-aded717294ad42d4.js" defer=""></script><script src="./_next/static/IbZpY6lpxNCTHGQFLD2XQ/_buildManifest.js" defer=""></script><script src="./_next/static/IbZpY6lpxNCTHGQFLD2XQ/_ssgManifest.js" defer=""></script></head><body><div id="__next"></div><div id="settings-container"></div><div id="notifications-container"></div><script id="__NEXT_DATA__" type="application/json">{"props":{"pageProps":{}},"page":"/","query":{},"buildId":"IbZpY6lpxNCTHGQFLD2XQ","assetPrefix":".","nextExport":true,"autoExport":true,"isFallback":false,"scriptLoader":[]}</script></body></html>
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { v4 as uuidv4 } from "uuid";
import classNames from "classnames";

import ArticleImage from "./article-image";
Expand All @@ -21,7 +20,7 @@ export default function ArticleContent({ type, content, display }) {
<div className={styles["article-content"]}>
<ul className={classNames(styles["article-list"], styles.vertical, { [styles[display]]: display })}>
{content.map((item) =>
<li key={uuidv4()} className={styles["article-list-item"]}>
<li key={item.id} className={styles["article-list-item"]}>
{item.url && !item.title
? <a href={item.url}>
<ArticleText text={item.content} />
Expand All @@ -40,7 +39,7 @@ export default function ArticleContent({ type, content, display }) {
<div className={styles["article-list-content"]}>
<ul className={classNames(styles["article-list"], styles.vertical)}>
{content.map((item) =>
<li key={uuidv4()} className={styles["article-list-item"]}>
<li key={item.id} className={styles["article-list-item"]}>
<ArticleText textClass={classNames(styles["article-title"], "truncate-multiline", "truncate-multiline-3")} text={item.title} type="h3" />
{item.url && !item.title
? <a href={item.url}>
Expand All @@ -59,7 +58,7 @@ export default function ArticleContent({ type, content, display }) {
return (
<ul className={classNames(styles["article-list"], styles.horizontal)}>
{content.map((item) =>
<li key={uuidv4()} className={styles["article-list-item"]}>
<li key={item.id} className={styles["article-list-item"]}>
<ArticleImage imageClass={styles["article-hero"]} image={item.image} />
<div className={styles["article-content"]}>
<ArticleText textClass="truncate-multiline truncate-multiline-3" text={item.text} type="div" />
Expand All @@ -74,7 +73,7 @@ export default function ArticleContent({ type, content, display }) {
return (
<div className={classNames(layoutStyles["grid-container"], { [layoutStyles[display]]: display })}>
{content.map((item) =>
<div key={uuidv4()} className={layoutStyles["grid-item"]}>
<div key={item.id} className={layoutStyles["grid-item"]}>
<ArticleImage imageClass={styles["article-image-container"]} image={item.image} meta={item.meta} />

{item.url
Expand All @@ -93,7 +92,7 @@ export default function ArticleContent({ type, content, display }) {
return (
<ul className={classNames(styles["article-list"], styles.vertical)}>
{content.map((item) =>
<li key={uuidv4()} className={styles["article-list-item"]}>
<li key={item.id} className={styles["article-list-item"]}>
<ArticleImage imageClass={styles["article-image-container"]} image={item.image} />
<ArticleText textClass={classNames(styles["article-title"], "truncate-multiline", "truncate-multiline-3")} text={item.title} type="h3" />
</li>
Expand Down
33 changes: 33 additions & 0 deletions resources/newssite/news-next/src/context/data-context.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { createContext, useContext } from "react";
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 const DataContextProvider = ({ children }) => {
document.documentElement.setAttribute("dir", dir);
document.documentElement.setAttribute("lang", 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,
};

return <DataContext.Provider value={value}>{children}</DataContext.Provider>;
Expand Down

0 comments on commit 2ff56c9

Please sign in to comment.