Skip to content

Commit

Permalink
Merge pull request #1222 from near/toggle_blog_for_testing
Browse files Browse the repository at this point in the history
Support testing blog content by toggling the github branch used for blog content based on the current environment
  • Loading branch information
charleslavon authored Jun 26, 2024
2 parents 9ca8ded + e89d3b8 commit 14803fb
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/pages/blog/[[...pages]].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,19 @@ import { recordHandledError } from '@/utils/analytics';
import type { NextPageWithLayout } from '@/utils/types';

export const getServerSideProps = (async ({ resolvedUrl }) => {
const isProd = ['https://near.org', 'https://dev.near.org'].some((url) => process.env.NEXT_PUBLIC_HOSTNAME === url);
const blog_branch = isProd ? 'main' : 'develop';
const blogParts = resolvedUrl.split('blog/');
let title = 'index.html';
if (blogParts[1] !== title) {
title = `${blogParts[1].substring(0, blogParts[1].indexOf('/'))}/index.html`;
}
const res = await fetch(`https://raw.githubusercontent.com/near/nearorg_marketing/main/public/blog/${title}`).catch(
(e) => {
recordHandledError({ title, message: 'failed to fetch github blog html for requested title' });
throw e;
},
);
const res = await fetch(
`https://raw.githubusercontent.com/near/nearorg_marketing/${blog_branch}/public/blog/${title}`,
).catch((e) => {
recordHandledError({ title, message: 'failed to fetch github blog html for requested title' });
throw e;
});

const __html = await (await res.blob()).text();

Expand Down

0 comments on commit 14803fb

Please sign in to comment.