From d07464b8b0bb08cb258b218d6e8951ceea42660e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Quiroz?= Date: Tue, 13 Dec 2022 14:19:33 -0300 Subject: [PATCH 01/12] chore: update constants --- src/constants.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/constants.ts b/src/constants.ts index 58c0354042..bd5c425426 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -171,6 +171,8 @@ export const LATEST_GETH_RELEASE_URL = 'https://api.github.com/repos/ethereum/go-ethereum/releases/latest'; export const ALL_GETH_COMMITS_URL = 'https://api.github.com/repos/ethereum/go-ethereum/commits/'; export const RELEASE_COMMIT_BASE_URL = 'https://github.com/ethereum/go-ethereum/tree/'; +export const LAST_COMMIT_BASE_URL = + 'https://api.github.com/repos/ethereum/geth-website/commits?path='; // Binaries urls export const BINARIES_BASE_URL = 'https://gethstore.blob.core.windows.net/builds/'; From 01c625275409047b969ce02e0014ff8f6d50f6c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Quiroz?= Date: Tue, 13 Dec 2022 14:19:57 -0300 Subject: [PATCH 02/12] feat: add getLastModifiedDate --- src/utils/getLastModifiedDate.ts | 11 +++++++++++ src/utils/index.ts | 1 + 2 files changed, 12 insertions(+) create mode 100644 src/utils/getLastModifiedDate.ts diff --git a/src/utils/getLastModifiedDate.ts b/src/utils/getLastModifiedDate.ts new file mode 100644 index 0000000000..5b63043bc1 --- /dev/null +++ b/src/utils/getLastModifiedDate.ts @@ -0,0 +1,11 @@ +import { LAST_COMMIT_BASE_URL } from '../constants'; + +export const getLastModifiedDate = async (filePath: string) => + fetch(`${LAST_COMMIT_BASE_URL}${filePath}/index.md&page=1&per_page=1`) + .then(res => res.json()) + .then(commits => commits[0].commit.committer.date) + .catch(_ => + fetch(`${LAST_COMMIT_BASE_URL}${filePath}.md&page=1&per_page=1`) + .then(res => res.json()) + .then(commits => commits[0].commit.committer.date) + ); diff --git a/src/utils/index.ts b/src/utils/index.ts index f950ec7d46..1616b13b8d 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -4,6 +4,7 @@ export { fetchLatestReleaseVersionAndName } from './fetchLatestReleaseVersionAnd export { fetchXMLData } from './fetchXMLData'; export { getChecksum } from './getChecksum'; export { getKebabCaseFromName } from './getKebabCaseFromName'; +export { getLastModifiedDate } from './getLastModifiedDate'; export { getLatestBinaryURL } from './getLatestBinaryURL'; export { getOS } from './getOS'; export { getParsedDate } from './getParsedDate'; From ea9ed42547c095d12bc0104f3d3ffad4255b3c72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Quiroz?= Date: Tue, 13 Dec 2022 14:20:16 -0300 Subject: [PATCH 03/12] fix: last modified date --- src/pages/[...slug].tsx | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/pages/[...slug].tsx b/src/pages/[...slug].tsx index a8f00430eb..7165047455 100644 --- a/src/pages/[...slug].tsx +++ b/src/pages/[...slug].tsx @@ -20,7 +20,7 @@ import { NavLink } from '../types'; import { getFileList } from '../utils/getFileList'; import { textStyles } from '../theme/foundations'; -import { getParsedDate } from '../utils'; +import { getLastModifiedDate, getParsedDate } from '../utils'; const MATTER_OPTIONS = { engines: { @@ -40,21 +40,22 @@ export const getStaticPaths: GetStaticPaths = () => { // Reads file data for markdown pages export const getStaticProps: GetStaticProps = async context => { + const navLinks = yaml.load(fs.readFileSync('src/data/documentation-links.yaml', 'utf8')); + const { slug } = context.params as ParsedUrlQuery; const filePath = (slug as string[])!.join('/'); let file; - let lastModified; - - const navLinks = yaml.load(fs.readFileSync('src/data/documentation-links.yaml', 'utf8')); + // read file try { - file = fs.readFileSync(`${filePath}.md`, 'utf-8'); - lastModified = fs.statSync(`${filePath}.md`); - } catch { file = fs.readFileSync(`${filePath}/index.md`, 'utf-8'); - lastModified = fs.statSync(`${filePath}/index.md`); + } catch (error) { + file = fs.readFileSync(`${filePath}.md`, 'utf-8'); } + // get last commit on file date + const lastModified = await getLastModifiedDate(filePath); + const { data: frontmatter, content } = matter(file, MATTER_OPTIONS); return { @@ -62,7 +63,7 @@ export const getStaticProps: GetStaticProps = async context => { frontmatter, content, navLinks, - lastModified: getParsedDate(lastModified.mtime, { + lastModified: getParsedDate(lastModified, { month: 'long', day: 'numeric', year: 'numeric' From a53aa19ccff7e2193d8516e68d27142855cca3ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Quiroz?= Date: Fri, 16 Dec 2022 15:49:21 -0300 Subject: [PATCH 04/12] chore: update .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index c87c9b392c..a21acbe116 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,7 @@ yarn-error.log* .pnpm-debug.log* # local env files +.env .env*.local # vercel From 9748bdfd0c1dc1350c88c02209feaf63b478b75f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Quiroz?= Date: Fri, 16 Dec 2022 16:05:51 -0300 Subject: [PATCH 05/12] chore: add .env.local.example --- .env.local.example | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 .env.local.example diff --git a/.env.local.example b/.env.local.example new file mode 100644 index 0000000000..7e981d8dcb --- /dev/null +++ b/.env.local.example @@ -0,0 +1,9 @@ +# Algolia +NEXT_PUBLIC_ALGOLIA_APP_ID= +NEXT_PUBLIC_ALGOLIA_SEARCH_API_KEY= +NEXT_PUBLIC_ALGOLIA_BASE_SEARCH_INDEX_NAME= + +# GitHub API +# Note: this token expires on Dec 16, 2023 +# check fine-grained tokens https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token#about-personal-access-tokens +GITHUB_TOKEN_READ_ONLY= From ec7773916b113a544452e9354f2eae00b14cf144 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Quiroz?= Date: Fri, 16 Dec 2022 16:06:46 -0300 Subject: [PATCH 06/12] chore: update getLastModifiedDate util --- src/pages/404.tsx | 14 ++++++++++---- src/utils/getLastModifiedDate.ts | 14 +++++++++++--- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/pages/404.tsx b/src/pages/404.tsx index 82f268a70a..8fb61d55d6 100644 --- a/src/pages/404.tsx +++ b/src/pages/404.tsx @@ -5,7 +5,7 @@ import NextLink from 'next/link'; import { GopherHomeFront } from '../components/UI/svgs'; import { PageMetadata } from '../components/UI'; -import { METADATA} from '../constants'; +import { METADATA } from '../constants'; const Page404NotFound: NextPage = ({}) => { return ( @@ -13,10 +13,16 @@ const Page404NotFound: NextPage = ({}) => {
- + { 404 - fetch(`${LAST_COMMIT_BASE_URL}${filePath}/index.md&page=1&per_page=1`) +export const getLastModifiedDate = async (filePath: string) => { + const headers = new Headers({ + // Note: this token expires on Dec 16, 2023 + // check fine-grained tokens https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token#about-personal-access-tokens + Authorization: 'Token ' + process.env.GITHUB_TOKEN_READ_ONLY + }); + + return fetch(`${LAST_COMMIT_BASE_URL}${filePath}/index.md&page=1&per_page=1`, { headers }) .then(res => res.json()) .then(commits => commits[0].commit.committer.date) .catch(_ => - fetch(`${LAST_COMMIT_BASE_URL}${filePath}.md&page=1&per_page=1`) + fetch(`${LAST_COMMIT_BASE_URL}${filePath}.md&page=1&per_page=1`, { headers }) .then(res => res.json()) .then(commits => commits[0].commit.committer.date) + .catch(console.error) ); +}; From 37537d0520226476bcc2c2770cbfcd98298da9b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Quiroz?= Date: Fri, 16 Dec 2022 16:07:30 -0300 Subject: [PATCH 07/12] chore: update lastModified code --- src/components/UI/downloads/DownloadsTable.tsx | 8 ++++++-- src/pages/[...slug].tsx | 11 ++++------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/components/UI/downloads/DownloadsTable.tsx b/src/components/UI/downloads/DownloadsTable.tsx index feb14bc9c4..c21e4865a4 100644 --- a/src/components/UI/downloads/DownloadsTable.tsx +++ b/src/components/UI/downloads/DownloadsTable.tsx @@ -45,7 +45,7 @@ export const DownloadsTable: FC = ({ if (/iPhone/i.test(OS)) return 3; if (/Android/i.test(userAgent)) return 4; return 0; - }, []) + }, []); return ( = ({ : 'none' } > - setTotalReleases(totalReleases[idx])} defaultIndex={getDefaultIndex}> + setTotalReleases(totalReleases[idx])} + defaultIndex={getDefaultIndex} + > {DOWNLOADS_TABLE_TABS.map((tab, idx) => { return ( diff --git a/src/pages/[...slug].tsx b/src/pages/[...slug].tsx index 7165047455..873891067d 100644 --- a/src/pages/[...slug].tsx +++ b/src/pages/[...slug].tsx @@ -11,16 +11,15 @@ import rehypeRaw from 'rehype-raw'; import { ParsedUrlQuery } from 'querystring'; import type { GetStaticPaths, GetStaticProps, NextPage } from 'next'; -import MDComponents from '../components/UI/docs'; -import { Breadcrumbs, DocsNav, DocumentNav } from '../components/UI/docs'; +import MDComponents, { Breadcrumbs, DocsNav, DocumentNav } from '../components/UI/docs'; import { PageMetadata } from '../components/UI'; -import { NavLink } from '../types'; - import { getFileList } from '../utils/getFileList'; +import { getLastModifiedDate, getParsedDate } from '../utils'; + +import { NavLink } from '../types'; import { textStyles } from '../theme/foundations'; -import { getLastModifiedDate, getParsedDate } from '../utils'; const MATTER_OPTIONS = { engines: { @@ -53,9 +52,7 @@ export const getStaticProps: GetStaticProps = async context => { file = fs.readFileSync(`${filePath}.md`, 'utf-8'); } - // get last commit on file date const lastModified = await getLastModifiedDate(filePath); - const { data: frontmatter, content } = matter(file, MATTER_OPTIONS); return { From 681aa89dcdeb45ec2f6705377cf00d35d15d5e6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Quiroz?= Date: Fri, 16 Dec 2022 16:47:01 -0300 Subject: [PATCH 08/12] chore: update gh api fetch --- src/utils/fetchLatestReleaseCommit.ts | 8 +++++++- src/utils/fetchLatestReleaseVersionAndName.ts | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/utils/fetchLatestReleaseCommit.ts b/src/utils/fetchLatestReleaseCommit.ts index 005abcbb33..b0d6612dc9 100644 --- a/src/utils/fetchLatestReleaseCommit.ts +++ b/src/utils/fetchLatestReleaseCommit.ts @@ -1,7 +1,13 @@ import { ALL_GETH_COMMITS_URL } from '../constants'; export const fetchLatestReleaseCommit = (versionNumber: string) => { - return fetch(`${ALL_GETH_COMMITS_URL}/${versionNumber}`) + const headers = new Headers({ + // Note: this token expires on Dec 16, 2023 + // check fine-grained tokens https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token#about-personal-access-tokens + Authorization: 'Token ' + process.env.GITHUB_TOKEN_READ_ONLY + }); + + return fetch(`${ALL_GETH_COMMITS_URL}/${versionNumber}`, { headers }) .then(response => response.json()) .then(commit => commit.sha.slice(0, 8)); }; diff --git a/src/utils/fetchLatestReleaseVersionAndName.ts b/src/utils/fetchLatestReleaseVersionAndName.ts index e022766067..1bc91ec568 100644 --- a/src/utils/fetchLatestReleaseVersionAndName.ts +++ b/src/utils/fetchLatestReleaseVersionAndName.ts @@ -1,7 +1,13 @@ import { LATEST_GETH_RELEASE_URL } from '../constants'; export const fetchLatestReleaseVersionAndName = () => { - return fetch(LATEST_GETH_RELEASE_URL) + const headers = new Headers({ + // Note: this token expires on Dec 16, 2023 + // check fine-grained tokens https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token#about-personal-access-tokens + Authorization: 'Token ' + process.env.GITHUB_TOKEN_READ_ONLY + }); + + return fetch(LATEST_GETH_RELEASE_URL, { headers }) .then(response => response.json()) .then(release => { return { From db1780d4faf186fd1c609612b02ab18a44f4d5d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Quiroz?= Date: Fri, 16 Dec 2022 17:30:46 -0300 Subject: [PATCH 09/12] Update .env.local.example Co-authored-by: Paul Wackerow <54227730+wackerow@users.noreply.github.com> --- .env.local.example | 1 - 1 file changed, 1 deletion(-) diff --git a/.env.local.example b/.env.local.example index 7e981d8dcb..951809844f 100644 --- a/.env.local.example +++ b/.env.local.example @@ -4,6 +4,5 @@ NEXT_PUBLIC_ALGOLIA_SEARCH_API_KEY= NEXT_PUBLIC_ALGOLIA_BASE_SEARCH_INDEX_NAME= # GitHub API -# Note: this token expires on Dec 16, 2023 # check fine-grained tokens https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token#about-personal-access-tokens GITHUB_TOKEN_READ_ONLY= From 55ef81be8d81cee9127f687aff44639848a62124 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Quiroz?= Date: Fri, 16 Dec 2022 17:35:59 -0300 Subject: [PATCH 10/12] Update src/utils/fetchLatestReleaseCommit.ts Co-authored-by: Paul Wackerow <54227730+wackerow@users.noreply.github.com> --- src/utils/fetchLatestReleaseCommit.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/utils/fetchLatestReleaseCommit.ts b/src/utils/fetchLatestReleaseCommit.ts index b0d6612dc9..2f28465a69 100644 --- a/src/utils/fetchLatestReleaseCommit.ts +++ b/src/utils/fetchLatestReleaseCommit.ts @@ -2,8 +2,7 @@ import { ALL_GETH_COMMITS_URL } from '../constants'; export const fetchLatestReleaseCommit = (versionNumber: string) => { const headers = new Headers({ - // Note: this token expires on Dec 16, 2023 - // check fine-grained tokens https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token#about-personal-access-tokens + // About personal access tokens https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token#about-personal-access-tokens Authorization: 'Token ' + process.env.GITHUB_TOKEN_READ_ONLY }); From ae003383289f298d072d30ede9b09760a73eb550 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Quiroz?= Date: Fri, 16 Dec 2022 17:36:16 -0300 Subject: [PATCH 11/12] Update src/utils/fetchLatestReleaseVersionAndName.ts Co-authored-by: Paul Wackerow <54227730+wackerow@users.noreply.github.com> --- src/utils/fetchLatestReleaseVersionAndName.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/utils/fetchLatestReleaseVersionAndName.ts b/src/utils/fetchLatestReleaseVersionAndName.ts index 1bc91ec568..423b89ab62 100644 --- a/src/utils/fetchLatestReleaseVersionAndName.ts +++ b/src/utils/fetchLatestReleaseVersionAndName.ts @@ -2,8 +2,7 @@ import { LATEST_GETH_RELEASE_URL } from '../constants'; export const fetchLatestReleaseVersionAndName = () => { const headers = new Headers({ - // Note: this token expires on Dec 16, 2023 - // check fine-grained tokens https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token#about-personal-access-tokens + // About personal access tokens https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token#about-personal-access-tokens Authorization: 'Token ' + process.env.GITHUB_TOKEN_READ_ONLY }); From 378bd7999755a1bc2ed4fb0551cc49d7cb18e710 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Quiroz?= Date: Fri, 16 Dec 2022 17:36:35 -0300 Subject: [PATCH 12/12] Update src/utils/getLastModifiedDate.ts Co-authored-by: Paul Wackerow <54227730+wackerow@users.noreply.github.com> --- src/utils/getLastModifiedDate.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/utils/getLastModifiedDate.ts b/src/utils/getLastModifiedDate.ts index 773e962cea..af0598d37e 100644 --- a/src/utils/getLastModifiedDate.ts +++ b/src/utils/getLastModifiedDate.ts @@ -2,8 +2,7 @@ import { LAST_COMMIT_BASE_URL } from '../constants'; export const getLastModifiedDate = async (filePath: string) => { const headers = new Headers({ - // Note: this token expires on Dec 16, 2023 - // check fine-grained tokens https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token#about-personal-access-tokens + // About personal access tokens https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token#about-personal-access-tokens Authorization: 'Token ' + process.env.GITHUB_TOKEN_READ_ONLY });