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] 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) ); +};