diff --git a/pages/news.tsx b/pages/news.tsx index af5007d1..7289ceae 100644 --- a/pages/news.tsx +++ b/pages/news.tsx @@ -2,11 +2,17 @@ import { GetServerSideProps } from "next"; import { getCOH3SteamNews } from "../src/apis/steam-api"; import SteamNewsPage from "../screens/news"; -export const getServerSideProps: GetServerSideProps = async () => { +export const getServerSideProps: GetServerSideProps = async ({ res }) => { let COH3SteamNews = null; try { COH3SteamNews = await getCOH3SteamNews(); + + // Cache for 30 minutes, stale while revalidate 48 hours + res.setHeader( + "Cache-Control", + "public, max-age=600, s-maxage=1800, stale-while-revalidate=172800", + ); } catch (e) { console.error(`Error getting the steam news`); console.error(e); diff --git a/routes.ts b/routes.ts index 6ba57f3d..bbe1d64b 100644 --- a/routes.ts +++ b/routes.ts @@ -177,13 +177,7 @@ export default new Router() browser: { serviceWorkerSeconds: 60 * 30, }, - edge: { - // Add 60 minutes cache - maxAgeSeconds: 60 * 60, - // Server stale page up to 48 hours - staleWhileRevalidateSeconds: 48 * 60 * 60, - forcePrivateCaching: true, - }, + // The cache is setup in nextjs response }); }) .match("/_next/data/:version/news.json", ({ cache }) => { @@ -191,13 +185,7 @@ export default new Router() browser: { serviceWorkerSeconds: 60 * 30, }, - edge: { - // Add 60 minutes cache - maxAgeSeconds: 60 * 60, - // Server stale page up to 48 hours - staleWhileRevalidateSeconds: 48 * 60 * 60, - forcePrivateCaching: true, - }, + // The cache is setup in nextjs response }); }) // Caching for SSG - explorer diff --git a/screens/news/index.tsx b/screens/news/index.tsx index edd42584..6eb9fb98 100644 --- a/screens/news/index.tsx +++ b/screens/news/index.tsx @@ -50,20 +50,11 @@ const preset = reactPreset.extend((tags: any) => ({ }, }; }, - // br: (node: { content: any }) => { - // return { - // tag: "br", - // // attrs: { - // // pt: "sm", - // // pb: "sm", - // // radius: "md", - // // w: "auto", - // // fit: "contain", - // // src: node.content, - // // loading: "lazy", - // // }, - // }; - // }, + br: () => { + return { + tag: "br", + }; + }, previewyoutube: (node: { attrs: NonNullable }) => { try { const youtubeId = Object.keys(node.attrs)[0]?.split(";")[0] || null; diff --git a/src/apis/steam-api.ts b/src/apis/steam-api.ts index 3783521b..3c9989fa 100644 --- a/src/apis/steam-api.ts +++ b/src/apis/steam-api.ts @@ -45,9 +45,11 @@ const getCOH3SteamNews = async (count = 15): Promise => { delete news.appid; news.contents = news.contents.replaceAll("{STEAM_CLAN_IMAGE}", steamImagesBaseUrl); - // news.contents = news.contents.replace(/(\n\n)|\n/g, (match: any, p1: any) => - // p1 ? "[br]" : "[br]", - // ); + // console.log(JSON.stringify(news.contents)) + // news.contents = news.contents.replaceAll(/\n/g, "[br]"); + + // news.contents = news.contents.replaceAll(/(?:[^\]])\s*(\n{1,3})/g, "[br]"); + // news.contents = news.contents.replaceAll("][br]", ""); // console.log(JSON.stringify(news.contents)) news.image = news.contents.match(/\[img\](.*?)\[\/img\]/)?.[1] ?? null;