mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-05-15 04:26:37 +00:00
fix: last modified date
This commit is contained in:
parent
01c6252754
commit
ea9ed42547
1 changed files with 10 additions and 9 deletions
|
|
@ -20,7 +20,7 @@ import { NavLink } from '../types';
|
||||||
import { getFileList } from '../utils/getFileList';
|
import { getFileList } from '../utils/getFileList';
|
||||||
|
|
||||||
import { textStyles } from '../theme/foundations';
|
import { textStyles } from '../theme/foundations';
|
||||||
import { getParsedDate } from '../utils';
|
import { getLastModifiedDate, getParsedDate } from '../utils';
|
||||||
|
|
||||||
const MATTER_OPTIONS = {
|
const MATTER_OPTIONS = {
|
||||||
engines: {
|
engines: {
|
||||||
|
|
@ -40,21 +40,22 @@ 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');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get last commit on file date
|
||||||
|
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 +63,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'
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue