Skip to content

Commit

Permalink
Merge pull request #56 from liuqh0609/fix/not-git
Browse files Browse the repository at this point in the history
fix: without initializing the git repository, the program terminates …
  • Loading branch information
sanyuan0704 committed Oct 2, 2022
2 parents 2a0b92e + 96e5b3f commit ac012c7
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/node/plugin-mdx/pluginMdxLastUpdated.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
import { Plugin } from 'vite';
import { simpleGit } from 'simple-git';
import { GitError, simpleGit } from 'simple-git';
import { MD_REGEX } from '../constants';
import { cleanUrl } from '../../shared/utils';
import { now } from 'lodash-es';

export function pluginMdxGit(): Plugin {
const cache = new Map<string, string>();
const git = simpleGit();

// https://github.com/steveukx/git-js#git-log
async function getLastUpdatedTime(path: string) {
const { latest } = await git.log({ file: path });
return !latest ? '' : latest.date;
try {
const { latest } = await git.log({ file: path });
return !latest ? '' : latest.date;
} catch (e) {
console.log((e as GitError)?.message);
return now();
}
}

return <Plugin>{
Expand Down

1 comment on commit ac012c7

@vercel
Copy link

@vercel vercel bot commented on ac012c7 Oct 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.