Skip to content

Commit 467d6fb

Browse files
committed
fix: 修复修改文章时间问题,尝试修改link水和问题
1 parent 658ccb1 commit 467d6fb

File tree

5 files changed

+33
-34
lines changed

5 files changed

+33
-34
lines changed

src/app/(app)/notes/[nid]/page.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ export type PageInnerProps = { postData: PostItemType };
2121
export default async function Page({ params }: { params: Record<string, any> }) {
2222
const { nid } = params;
2323
const postData = postDataMap[nid];
24-
console.log(postData);
2524

2625
return (
2726
<PageTransition>

src/app/(app)/notes/[nid]/pageExtra.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,9 @@ export const NoteDateMeta = ({
3434
return (
3535
<span className="inline-flex items-center space-x-1">
3636
<MdiClockOutline />
37-
<time className=" font-semibold text-base font-mono">
38-
{createdAt && !modified
39-
? dayjs(createdAt).format('YYYY 年 M 月 D 日')
40-
: '1999 年 9 月 9 日'}
41-
{modified && <>编辑于&nbsp;&nbsp; {dayjs(updatedAt).format('YYYY 年 M 月 D 日')}</>}
37+
<time className=" font-semibold text-sm font-mono">
38+
{createdAt && dayjs(createdAt).format('YYYY 年 M 月 D 日')}
39+
{modified && <>&nbsp;&nbsp;编辑于 {dayjs(updatedAt).format('YYYY 年 M 月 D 日')}</>}
4240
</time>
4341
</span>
4442
);

src/components/ui/markdown/Markdown.tsx

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22

33
import { clsx } from 'clsx';
44
import type { MarkdownToJSX } from 'markdown-to-jsx';
5-
import {
6-
compiler,
7-
// sanitizeUrl
8-
} from 'markdown-to-jsx';
5+
import { compiler, sanitizeUrl } from 'markdown-to-jsx';
96
import Script from 'next/script';
107
import type React from 'react';
118
import type { FC, PropsWithChildren } from 'react';
@@ -14,7 +11,7 @@ import { memo, Suspense, useMemo, useRef } from 'react';
1411
import { MParagraph } from './renderbers/paragraph';
1512
import { MHeader } from './renderbers/heading';
1613
import { MarkdownImage } from './renderbers/images';
17-
// import { MLink } from './renderbers/Mlink';
14+
import { MLink } from './renderbers/Mlink';
1815
import { CodeBlockRender } from './renderbers/CodeBlock';
1916

2017
export interface MdProps {
@@ -74,25 +71,25 @@ export const Markdown: FC<MdProps & MarkdownToJSX.Options & PropsWithChildren &
7471
);
7572
},
7673
},
77-
// link: {
78-
// react(node, output, state) {
79-
// const { target, title } = node;
80-
81-
// let realText = '';
82-
83-
// for (const child of node.content) {
84-
// if (child.type === 'text') {
85-
// realText += child.content;
86-
// }
87-
// }
88-
89-
// return (
90-
// <MLink href={sanitizeUrl(target)!} title={title} key={state?.key} text={realText}>
91-
// {output(node.content, state!)}
92-
// </MLink>
93-
// );
94-
// },
95-
// },
74+
link: {
75+
react(node, output, state) {
76+
const { target, title } = node;
77+
78+
let realText = '';
79+
80+
for (const child of node.content) {
81+
if (child.type === 'text') {
82+
realText += child.content;
83+
}
84+
}
85+
86+
return (
87+
<MLink href={sanitizeUrl(target)!} title={title} key={state?.key} text={realText}>
88+
{output(node.content, state!)}
89+
</MLink>
90+
);
91+
},
92+
},
9693
codeFenced: {
9794
parse(capture) {
9895
return {

src/components/ui/markdown/renderbers/CodeBlock.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,11 @@ export const CodeBlockRender = (props: {
88
content: string;
99
attrs?: string;
1010
}) => {
11-
// 使用 useMemo 缓存生成的内容
1211
const Content = useMemo(() => {
1312
const { lang } = props;
1413
const nextProps = { ...props };
1514
nextProps.content = formatCode(props.content);
1615

17-
// 动态加载 shiki 高亮
1816
if (lang) {
1917
const ShikiHighLighter: any = lazy(() =>
2018
import('./ShikiHighlighter').then((mod) => ({

src/lib/git.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ export function getLastGitUpdateTime(filePath: string): Date | null {
2020
export function getFirstGitCommitTime(filePath: string): Date | null {
2121
try {
2222
const command = `git log --reverse --format="%ai" -- "${filePath}"`;
23-
const stdout = execSync(command).toString().trim();
24-
console.log(stdout);
23+
const stdout = getFirstLine(execSync(command).toString().trim());
2524

2625
if (!stdout) {
2726
return null;
@@ -34,3 +33,11 @@ export function getFirstGitCommitTime(filePath: string): Date | null {
3433
return null;
3534
}
3635
}
36+
37+
function getFirstLine(str: string) {
38+
if (!str) return '';
39+
40+
const lines = str.split('\n');
41+
42+
return lines[0];
43+
}

0 commit comments

Comments
 (0)