Merge pull request #157 from ethereum/fix-last-edit-timestamp

fix: docs last edit timestamp
This commit is contained in:
Nicolás Quiroz 2022-12-16 18:08:31 -03:00 committed by GitHub
commit 57b5b1de8d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 69 additions and 21 deletions

8
.env.local.example Normal file
View File

@ -0,0 +1,8 @@
# Algolia
NEXT_PUBLIC_ALGOLIA_APP_ID=
NEXT_PUBLIC_ALGOLIA_SEARCH_API_KEY=
NEXT_PUBLIC_ALGOLIA_BASE_SEARCH_INDEX_NAME=
# GitHub API
# 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=

1
.gitignore vendored
View File

@ -26,6 +26,7 @@ yarn-error.log*
.pnpm-debug.log*
# local env files
.env
.env*.local
# vercel

View File

@ -45,7 +45,7 @@ export const DownloadsTable: FC<Props> = ({
if (/iPhone/i.test(OS)) return 3;
if (/Android/i.test(userAgent)) return 4;
return 0;
}, [])
}, []);
return (
<Stack
@ -56,7 +56,11 @@ export const DownloadsTable: FC<Props> = ({
: 'none'
}
>
<Tabs variant='unstyled' onChange={idx => setTotalReleases(totalReleases[idx])} defaultIndex={getDefaultIndex}>
<Tabs
variant='unstyled'
onChange={idx => setTotalReleases(totalReleases[idx])}
defaultIndex={getDefaultIndex}
>
<TabList color='primary' bg='button-bg'>
{DOWNLOADS_TABLE_TABS.map((tab, idx) => {
return (

View File

@ -173,6 +173,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/';

View File

@ -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 = ({}) => {
<PageMetadata title={METADATA.PAGE_404_TITLE} description={METADATA.PAGE_404_DESCRIPTION} />
<main id='main-content'>
<Flex direction='column' alignItems='center' py={{ base: 16, md: 24 }} border="2px" borderColor="primary">
<Flex
direction='column'
alignItems='center'
py={{ base: 16, md: 24 }}
border='2px'
borderColor='primary'
>
<GopherHomeFront />
<Text
fontSize={{ base: "8xl", md: "9xl" }}
fontSize={{ base: '8xl', md: '9xl' }}
lineHeight='120%'
fontFamily='heading'
textAlign='center'
@ -26,7 +32,7 @@ const Page404NotFound: NextPage = ({}) => {
404
</Text>
<Text
fontSize={{ base: 'xl', md: '2xl'}}
fontSize={{ base: 'xl', md: '2xl' }}
fontFamily='heading'
fontWeight='700'
textAlign='center'

View File

@ -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 { getFileList } from '../utils/getFileList';
import { getLastModifiedDate, getParsedDate } from '../utils';
import { NavLink } from '../types';
import { getFileList } from '../utils/getFileList';
import { textStyles } from '../theme/foundations';
import { getParsedDate } from '../utils';
const MATTER_OPTIONS = {
engines: {
@ -40,21 +39,20 @@ 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');
}
const lastModified = await getLastModifiedDate(filePath);
const { data: frontmatter, content } = matter(file, MATTER_OPTIONS);
return {
@ -62,7 +60,7 @@ export const getStaticProps: GetStaticProps = async context => {
frontmatter,
content,
navLinks,
lastModified: getParsedDate(lastModified.mtime, {
lastModified: getParsedDate(lastModified, {
month: 'long',
day: 'numeric',
year: 'numeric'

View File

@ -1,7 +1,12 @@
import { ALL_GETH_COMMITS_URL } from '../constants';
export const fetchLatestReleaseCommit = (versionNumber: string) => {
return fetch(`${ALL_GETH_COMMITS_URL}/${versionNumber}`)
const headers = new Headers({
// 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
});
return fetch(`${ALL_GETH_COMMITS_URL}/${versionNumber}`, { headers })
.then(response => response.json())
.then(commit => commit.sha.slice(0, 8));
};

View File

@ -1,7 +1,12 @@
import { LATEST_GETH_RELEASE_URL } from '../constants';
export const fetchLatestReleaseVersionAndName = () => {
return fetch(LATEST_GETH_RELEASE_URL)
const headers = new Headers({
// 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
});
return fetch(LATEST_GETH_RELEASE_URL, { headers })
.then(response => response.json())
.then(release => {
return {

View File

@ -0,0 +1,18 @@
import { LAST_COMMIT_BASE_URL } from '../constants';
export const getLastModifiedDate = async (filePath: string) => {
const headers = new Headers({
// 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
});
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`, { headers })
.then(res => res.json())
.then(commits => commits[0].commit.committer.date)
.catch(console.error)
);
};

View File

@ -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';