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

fix: docs last edit timestamp
pull/26460/head^2
Nicolás Quiroz 2 years ago committed by GitHub
commit 57b5b1de8d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      .env.local.example
  2. 1
      .gitignore
  3. 8
      src/components/UI/downloads/DownloadsTable.tsx
  4. 2
      src/constants.ts
  5. 14
      src/pages/404.tsx
  6. 24
      src/pages/[...slug].tsx
  7. 7
      src/utils/fetchLatestReleaseCommit.ts
  8. 7
      src/utils/fetchLatestReleaseVersionAndName.ts
  9. 18
      src/utils/getLastModifiedDate.ts
  10. 1
      src/utils/index.ts

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

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

@ -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 (

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

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

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

@ -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));
};

@ -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 {

@ -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)
);
};

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

Loading…
Cancel
Save