Merge pull request #157 from ethereum/fix-last-edit-timestamp
fix: docs last edit timestamp
This commit is contained in:
commit
57b5b1de8d
|
@ -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=
|
|
@ -26,6 +26,7 @@ yarn-error.log*
|
||||||
.pnpm-debug.log*
|
.pnpm-debug.log*
|
||||||
|
|
||||||
# local env files
|
# local env files
|
||||||
|
.env
|
||||||
.env*.local
|
.env*.local
|
||||||
|
|
||||||
# vercel
|
# vercel
|
||||||
|
|
|
@ -45,7 +45,7 @@ export const DownloadsTable: FC<Props> = ({
|
||||||
if (/iPhone/i.test(OS)) return 3;
|
if (/iPhone/i.test(OS)) return 3;
|
||||||
if (/Android/i.test(userAgent)) return 4;
|
if (/Android/i.test(userAgent)) return 4;
|
||||||
return 0;
|
return 0;
|
||||||
}, [])
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack
|
<Stack
|
||||||
|
@ -56,7 +56,11 @@ export const DownloadsTable: FC<Props> = ({
|
||||||
: 'none'
|
: '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'>
|
<TabList color='primary' bg='button-bg'>
|
||||||
{DOWNLOADS_TABLE_TABS.map((tab, idx) => {
|
{DOWNLOADS_TABLE_TABS.map((tab, idx) => {
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -173,6 +173,8 @@ export const LATEST_GETH_RELEASE_URL =
|
||||||
'https://api.github.com/repos/ethereum/go-ethereum/releases/latest';
|
'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 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 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
|
// Binaries urls
|
||||||
export const BINARIES_BASE_URL = 'https://gethstore.blob.core.windows.net/builds/';
|
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 { GopherHomeFront } from '../components/UI/svgs';
|
||||||
import { PageMetadata } from '../components/UI';
|
import { PageMetadata } from '../components/UI';
|
||||||
|
|
||||||
import { METADATA} from '../constants';
|
import { METADATA } from '../constants';
|
||||||
|
|
||||||
const Page404NotFound: NextPage = ({}) => {
|
const Page404NotFound: NextPage = ({}) => {
|
||||||
return (
|
return (
|
||||||
|
@ -13,10 +13,16 @@ const Page404NotFound: NextPage = ({}) => {
|
||||||
<PageMetadata title={METADATA.PAGE_404_TITLE} description={METADATA.PAGE_404_DESCRIPTION} />
|
<PageMetadata title={METADATA.PAGE_404_TITLE} description={METADATA.PAGE_404_DESCRIPTION} />
|
||||||
|
|
||||||
<main id='main-content'>
|
<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 />
|
<GopherHomeFront />
|
||||||
<Text
|
<Text
|
||||||
fontSize={{ base: "8xl", md: "9xl" }}
|
fontSize={{ base: '8xl', md: '9xl' }}
|
||||||
lineHeight='120%'
|
lineHeight='120%'
|
||||||
fontFamily='heading'
|
fontFamily='heading'
|
||||||
textAlign='center'
|
textAlign='center'
|
||||||
|
@ -26,7 +32,7 @@ const Page404NotFound: NextPage = ({}) => {
|
||||||
404
|
404
|
||||||
</Text>
|
</Text>
|
||||||
<Text
|
<Text
|
||||||
fontSize={{ base: 'xl', md: '2xl'}}
|
fontSize={{ base: 'xl', md: '2xl' }}
|
||||||
fontFamily='heading'
|
fontFamily='heading'
|
||||||
fontWeight='700'
|
fontWeight='700'
|
||||||
textAlign='center'
|
textAlign='center'
|
||||||
|
|
|
@ -11,16 +11,15 @@ import rehypeRaw from 'rehype-raw';
|
||||||
import { ParsedUrlQuery } from 'querystring';
|
import { ParsedUrlQuery } from 'querystring';
|
||||||
import type { GetStaticPaths, GetStaticProps, NextPage } from 'next';
|
import type { GetStaticPaths, GetStaticProps, NextPage } from 'next';
|
||||||
|
|
||||||
import MDComponents from '../components/UI/docs';
|
import MDComponents, { Breadcrumbs, DocsNav, DocumentNav } from '../components/UI/docs';
|
||||||
import { Breadcrumbs, DocsNav, DocumentNav } from '../components/UI/docs';
|
|
||||||
import { PageMetadata } from '../components/UI';
|
import { PageMetadata } from '../components/UI';
|
||||||
|
|
||||||
|
import { getFileList } from '../utils/getFileList';
|
||||||
|
import { getLastModifiedDate, getParsedDate } from '../utils';
|
||||||
|
|
||||||
import { NavLink } from '../types';
|
import { NavLink } from '../types';
|
||||||
|
|
||||||
import { getFileList } from '../utils/getFileList';
|
|
||||||
|
|
||||||
import { textStyles } from '../theme/foundations';
|
import { textStyles } from '../theme/foundations';
|
||||||
import { getParsedDate } from '../utils';
|
|
||||||
|
|
||||||
const MATTER_OPTIONS = {
|
const MATTER_OPTIONS = {
|
||||||
engines: {
|
engines: {
|
||||||
|
@ -40,21 +39,20 @@ export const getStaticPaths: GetStaticPaths = () => {
|
||||||
|
|
||||||
// Reads file data for markdown pages
|
// Reads file data for markdown pages
|
||||||
export const getStaticProps: GetStaticProps = async context => {
|
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 { slug } = context.params as ParsedUrlQuery;
|
||||||
const filePath = (slug as string[])!.join('/');
|
const filePath = (slug as string[])!.join('/');
|
||||||
let file;
|
let file;
|
||||||
let lastModified;
|
|
||||||
|
|
||||||
const navLinks = yaml.load(fs.readFileSync('src/data/documentation-links.yaml', 'utf8'));
|
|
||||||
|
|
||||||
|
// read file
|
||||||
try {
|
try {
|
||||||
file = fs.readFileSync(`${filePath}.md`, 'utf-8');
|
|
||||||
lastModified = fs.statSync(`${filePath}.md`);
|
|
||||||
} catch {
|
|
||||||
file = fs.readFileSync(`${filePath}/index.md`, 'utf-8');
|
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);
|
const { data: frontmatter, content } = matter(file, MATTER_OPTIONS);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -62,7 +60,7 @@ export const getStaticProps: GetStaticProps = async context => {
|
||||||
frontmatter,
|
frontmatter,
|
||||||
content,
|
content,
|
||||||
navLinks,
|
navLinks,
|
||||||
lastModified: getParsedDate(lastModified.mtime, {
|
lastModified: getParsedDate(lastModified, {
|
||||||
month: 'long',
|
month: 'long',
|
||||||
day: 'numeric',
|
day: 'numeric',
|
||||||
year: 'numeric'
|
year: 'numeric'
|
||||||
|
|
|
@ -1,7 +1,12 @@
|
||||||
import { ALL_GETH_COMMITS_URL } from '../constants';
|
import { ALL_GETH_COMMITS_URL } from '../constants';
|
||||||
|
|
||||||
export const fetchLatestReleaseCommit = (versionNumber: string) => {
|
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(response => response.json())
|
||||||
.then(commit => commit.sha.slice(0, 8));
|
.then(commit => commit.sha.slice(0, 8));
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,7 +1,12 @@
|
||||||
import { LATEST_GETH_RELEASE_URL } from '../constants';
|
import { LATEST_GETH_RELEASE_URL } from '../constants';
|
||||||
|
|
||||||
export const fetchLatestReleaseVersionAndName = () => {
|
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(response => response.json())
|
||||||
.then(release => {
|
.then(release => {
|
||||||
return {
|
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 { fetchXMLData } from './fetchXMLData';
|
||||||
export { getChecksum } from './getChecksum';
|
export { getChecksum } from './getChecksum';
|
||||||
export { getKebabCaseFromName } from './getKebabCaseFromName';
|
export { getKebabCaseFromName } from './getKebabCaseFromName';
|
||||||
|
export { getLastModifiedDate } from './getLastModifiedDate';
|
||||||
export { getLatestBinaryURL } from './getLatestBinaryURL';
|
export { getLatestBinaryURL } from './getLatestBinaryURL';
|
||||||
export { getOS } from './getOS';
|
export { getOS } from './getOS';
|
||||||
export { getParsedDate } from './getParsedDate';
|
export { getParsedDate } from './getParsedDate';
|
||||||
|
|
Loading…
Reference in New Issue