Skip to content

Commit

Permalink
Simple small changes (#421)
Browse files Browse the repository at this point in the history
* Changes news cache

* Updates
  • Loading branch information
petrvecera authored Apr 11, 2024
1 parent 3557c0c commit 8d8826c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 32 deletions.
8 changes: 7 additions & 1 deletion pages/news.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@ import { GetServerSideProps } from "next";
import { getCOH3SteamNews } from "../src/apis/steam-api";
import SteamNewsPage from "../screens/news";

export const getServerSideProps: GetServerSideProps<any> = async () => {
export const getServerSideProps: GetServerSideProps<any> = 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);
Expand Down
16 changes: 2 additions & 14 deletions routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,27 +177,15 @@ 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 }) => {
cache({
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
Expand Down
19 changes: 5 additions & 14 deletions screens/news/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<unknown> }) => {
try {
const youtubeId = Object.keys(node.attrs)[0]?.split(";")[0] || null;
Expand Down
8 changes: 5 additions & 3 deletions src/apis/steam-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ const getCOH3SteamNews = async (count = 15): Promise<COH3SteamNewsType> => {
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;

Expand Down

0 comments on commit 8d8826c

Please sign in to comment.