From 07c0add68226355c4d4ca7cf4460491584f8464b Mon Sep 17 00:00:00 2001 From: Robson Oliveira Date: Tue, 5 Dec 2023 23:19:44 -0300 Subject: [PATCH] fix(getdocs): get documents from raw.github --- src/pages/docs/tracks/[slug].tsx | 56 ++++++++++++++-------- src/pages/docs/tutorial/[slug].tsx | 54 +++++++++++++-------- src/pages/updates/announcements/[slug].tsx | 22 ++++++--- 3 files changed, 87 insertions(+), 45 deletions(-) diff --git a/src/pages/docs/tracks/[slug].tsx b/src/pages/docs/tracks/[slug].tsx index e44de06d..84f7e3ea 100644 --- a/src/pages/docs/tracks/[slug].tsx +++ b/src/pages/docs/tracks/[slug].tsx @@ -29,7 +29,7 @@ import Breadcrumb from 'components/breadcrumb' import getHeadings from 'utils/getHeadings' import getNavigation from 'utils/getNavigation' -import getGithubFile from 'utils/getGithubFile' +// import getGithubFile from 'utils/getGithubFile' import { getDocsPaths as getTracksPaths } from 'utils/getDocsPaths' import replaceMagicBlocks from 'utils/replaceMagicBlocks' import escapeCurlyBraces from 'utils/escapeCurlyBraces' @@ -215,19 +215,29 @@ export const getStaticProps: GetStaticProps = async ({ } } - let documentationContent = await getGithubFile( - 'vtexdocs', - 'help-center-content', - branch, - path - ) + // let documentationContent = await getGithubFile( + // 'vtexdocs', + // 'help-center-content', + // branch, + // path + // ) - const contributors = await getFileContributors( - 'vtexdocs', - 'help-center-content', - branch, - path - ) + let documentationContent = + (await fetch( + `https://raw.githubusercontent.com/vtexdocs/help-center-content/${branch}/${path}` + ) + .then((res) => res.text()) + .catch((err) => console.log(err))) || '' + + const contributors = + (await getFileContributors( + 'vtexdocs', + 'help-center-content', + branch, + path + ).catch((err) => { + console.log(err) + })) || [] let format: 'md' | 'mdx' = 'mdx' try { @@ -278,12 +288,20 @@ export const getStaticProps: GetStaticProps = async ({ )?.path if (seeAlsoPath) { try { - const documentationContent = await getGithubFile( - 'vtexdocs', - 'help-center-content', - 'main', - seeAlsoPath - ) + const documentationContent = + (await fetch( + `https://raw.githubusercontent.com/vtexdocs/help-center-content/main/${seeAlsoPath}` + ) + .then((res) => res.text()) + .catch((err) => console.log(err))) || '' + + // const documentationContent = await getGithubFile( + // 'vtexdocs', + // 'help-center-content',W + // 'main', + // seeAlsoPath + // ) + const serialized = await serialize(documentationContent, { parseFrontmatter: true, }) diff --git a/src/pages/docs/tutorial/[slug].tsx b/src/pages/docs/tutorial/[slug].tsx index 73424daf..0619700a 100644 --- a/src/pages/docs/tutorial/[slug].tsx +++ b/src/pages/docs/tutorial/[slug].tsx @@ -29,7 +29,7 @@ import Breadcrumb from 'components/breadcrumb' import getHeadings from 'utils/getHeadings' import getNavigation from 'utils/getNavigation' -import getGithubFile from 'utils/getGithubFile' +// import getGithubFile from 'utils/getGithubFile' import { getDocsPaths as getTutorialsPaths } from 'utils/getDocsPaths' import replaceMagicBlocks from 'utils/replaceMagicBlocks' import escapeCurlyBraces from 'utils/escapeCurlyBraces' @@ -214,19 +214,29 @@ export const getStaticProps: GetStaticProps = async ({ } } - let documentationContent = await getGithubFile( - 'vtexdocs', - 'help-center-content', - branch, - path - ) + // let documentationContent = await getGithubFile( + // 'vtexdocs', + // 'help-center-content', + // branch, + // path + // ) - const contributors = await getFileContributors( - 'vtexdocs', - 'help-center-content', - branch, - path - ) + let documentationContent = + (await fetch( + `https://raw.githubusercontent.com/vtexdocs/help-center-content/${branch}/${path}` + ) + .then((res) => res.text()) + .catch((err) => console.log(err))) || '' + + const contributors = + (await getFileContributors( + 'vtexdocs', + 'help-center-content', + branch, + path + ).catch((err) => { + console.log(err) + })) || [] let format: 'md' | 'mdx' = 'mdx' try { @@ -277,12 +287,18 @@ export const getStaticProps: GetStaticProps = async ({ )?.path if (seeAlsoPath) { try { - const documentationContent = await getGithubFile( - 'vtexdocs', - 'help-center-content', - 'main', - seeAlsoPath - ) + const documentationContent = + (await fetch( + `https://raw.githubusercontent.com/vtexdocs/help-center-content/main/${seeAlsoPath}` + ) + .then((res) => res.text()) + .catch((err) => console.log(err))) || '' + // const documentationContent = await getGithubFile( + // 'vtexdocs', + // 'help-center-content', + // 'main', + // seeAlsoPath + // ) const serialized = await serialize(documentationContent, { parseFrontmatter: true, }) diff --git a/src/pages/updates/announcements/[slug].tsx b/src/pages/updates/announcements/[slug].tsx index f92e78df..6f6dd2fa 100644 --- a/src/pages/updates/announcements/[slug].tsx +++ b/src/pages/updates/announcements/[slug].tsx @@ -31,7 +31,7 @@ import { localeType, } from 'utils/navigation-utils' import getNavigation from 'utils/getNavigation' -import getGithubFile from 'utils/getGithubFile' +// import getGithubFile from 'utils/getGithubFile' import { getDocsPaths as getNewsPaths } from 'utils/getDocsPaths' import replaceMagicBlocks from 'utils/replaceMagicBlocks' import escapeCurlyBraces from 'utils/escapeCurlyBraces' @@ -176,12 +176,20 @@ export const getStaticProps: GetStaticProps = async ({ } } - let documentationContent = await getGithubFile( - 'vtexdocs', - 'help-center-content', - branch, - path - ) + // let documentationContent = await getGithubFile( + // 'vtexdocs', + // 'help-center-content', + // branch, + // path + // ) + + let documentationContent = + (await fetch( + `https://raw.githubusercontent.com/vtexdocs/help-center-content/${branch}/${path}` + ) + .then((res) => res.text()) + .catch((err) => console.log(err))) || '' + const logger = getLogger('News') try {