Skip to content

Commit 5c871e4

Browse files
committed
[fix] Title & Path of Markdown cards
1 parent 1efe4fc commit 5c871e4

File tree

6 files changed

+22
-15
lines changed

6 files changed

+22
-15
lines changed

components/Home/LatestBlogs.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { FC } from 'react';
22
import { Button, Card, Col, Container, Row } from 'react-bootstrap';
33

4+
import { MD_pattern } from '../../models/configuration';
45
import { ArticleMeta } from '../../pages/api/core';
56
import { SectionTitle } from './SectionTitle';
67

@@ -17,11 +18,11 @@ export const LatestBlogs: FC<LatestBlogsProps> = ({ articles }) => (
1718
{articles.map(({ name, meta, path }) => (
1819
<Col key={name}>
1920
<Card body>
20-
<Card.Title className="text-dark">{name}</Card.Title>
21-
<Card.Text className="text-dark">
22-
发布日期: {meta?.date || '未知日期'}
23-
</Card.Text>
24-
<Button href={path || '#'} variant="secondary">
21+
<Card.Title className="text-dark">
22+
{meta?.title || name.replace(MD_pattern, '')}
23+
</Card.Title>
24+
<Card.Text className="text-dark">发布日期: {meta?.date || '未知日期'}</Card.Text>
25+
<Button href={path?.replace(MD_pattern, '') || '#'} variant="secondary">
2526
阅读文章
2627
</Button>
2728
</Card>

components/Home/Sponsors.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { FC } from 'react';
22
import { Button, Card, Col, Container, Row } from 'react-bootstrap';
33

4+
import { MD_pattern } from '../../models/configuration';
45
import { ArticleMeta } from '../../pages/api/core';
56
import { SectionTitle } from './SectionTitle';
67

@@ -17,10 +18,10 @@ export const Sponsors: FC<SponsorsProps> = ({ sponsors }) => (
1718
{sponsors.map(({ name, meta }) => (
1819
<Col key={name}>
1920
<Card body>
20-
<Card.Title className="text-dark">{name}</Card.Title>
21-
<Card.Text className="text-dark">
22-
{meta?.description || '暂无描述'}
23-
</Card.Text>
21+
<Card.Title className="text-dark">
22+
{meta?.title || name.replace(MD_pattern, '')}
23+
</Card.Title>
24+
<Card.Text className="text-dark">{meta?.description || '暂无描述'}</Card.Text>
2425
</Card>
2526
</Col>
2627
))}

components/Home/UpcomingEvents.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import Link from 'next/link';
33
import { FC, useContext } from 'react';
44
import { Button, Card, Col, Row } from 'react-bootstrap';
55

6+
import { MD_pattern } from '../../models/configuration';
67
import { I18nContext } from '../../models/Translation';
78
import { ArticleMeta } from '../../pages/api/core';
89
import { SectionTitle } from './SectionTitle';
@@ -22,15 +23,17 @@ export const UpcomingEvents: FC<UpcomingEventsProps> = observer(({ events }) =>
2223
{events.map(({ name, meta, path }) => (
2324
<Col key={name}>
2425
<Card body>
25-
<Card.Title className="text-dark">{name}</Card.Title>
26+
<Card.Title className="text-dark">
27+
{meta?.title || name.replace(MD_pattern, '')}
28+
</Card.Title>
2629
<Card.Text className="text-dark">
2730
{t('activity_time')}: {meta?.start || 'N/A'}
2831
</Card.Text>
2932
<Card.Text className="text-dark">
3033
{t('activity_location')}: {meta?.address || 'N/A'}
3134
</Card.Text>
3235

33-
<Link href={path || '#'} className="btn btn-primary">
36+
<Link href={path?.replace(MD_pattern, '') || '#'} className="btn btn-primary">
3437
{t('view_details')}
3538
</Link>
3639
</Card>

models/configuration.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import { parseCookie } from 'web-utility';
22

33
export const isServer = () => typeof window === 'undefined';
44

5+
export const MD_pattern = /\.(md|markdown)$/i,
6+
MDX_pattern = /\.mdx?$/i;
7+
58
export const Name = process.env.NEXT_PUBLIC_SITE_NAME,
69
Summary = process.env.NEXT_PUBLIC_SITE_SUMMARY,
710
DefaultImage = process.env.NEXT_PUBLIC_LOGO!;

pages/api/core.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import { basename } from 'path';
88
import { ProxyAgent, setGlobalDispatcher } from 'undici';
99
import { parse } from 'yaml';
1010

11+
import { MDX_pattern } from '../../models/configuration';
12+
1113
const { HTTP_PROXY } = process.env;
1214

1315
if (HTTP_PROXY) setGlobalDispatcher(new ProxyAgent(HTTP_PROXY));
@@ -53,9 +55,6 @@ export interface ArticleMeta {
5355
subs: ArticleMeta[];
5456
}
5557

56-
export const MD_pattern = /\.(md|markdown)$/i,
57-
MDX_pattern = /\.mdx?$/i;
58-
5958
export function splitFrontMatter(raw: string) {
6059
const [, frontMatter, markdown] =
6160
raw.trim().match(/^---[\r\n]([\s\S]+?[\r\n])---[\r\n]([\s\S]*)/) || [];

0 commit comments

Comments
 (0)