fix: last modified date

This commit is contained in:
Nicolás Quiroz 2022-12-13 14:20:16 -03:00
parent 01c6252754
commit ea9ed42547
1 changed files with 10 additions and 9 deletions

View File

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