add sub git and git-tools
This commit is contained in:
41
lib/getPosts.tsx
Normal file
41
lib/getPosts.tsx
Normal file
@@ -0,0 +1,41 @@
|
||||
import { exec } from 'child_process';
|
||||
|
||||
export type Post = {
|
||||
title: string;
|
||||
message?: string;
|
||||
author: {
|
||||
email: string;
|
||||
name: string;
|
||||
};
|
||||
time: number;
|
||||
};
|
||||
|
||||
const posts: Post[] = [
|
||||
{
|
||||
author: 'kjuulh',
|
||||
post: 'some post\n',
|
||||
},
|
||||
{
|
||||
author: 'kjuulh',
|
||||
post: `some other post with
|
||||
some more text`,
|
||||
},
|
||||
];
|
||||
|
||||
export const getPosts = async (): Promise<Post[]> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
exec(`git-log --path ${process.env.POSTS_DIR}`, (error, stdout, stderr) => {
|
||||
if (error) {
|
||||
console.warn(error);
|
||||
reject('could not load posts stderr: ' + stderr + 'stdout: ' + stdout);
|
||||
return;
|
||||
}
|
||||
|
||||
const posts: Post[] = JSON.parse(stdout);
|
||||
|
||||
resolve(posts);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
export const revalidate = 5;
|
Reference in New Issue
Block a user