Skip to content

Commit ea99bcc

Browse files
authored
Merge pull request #7 from cocdeshijie/dev
Link Card Component, and small fixes
2 parents 86d78d3 + e90a85c commit ea99bcc

File tree

11 files changed

+229
-6
lines changed

11 files changed

+229
-6
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { NextResponse } from "next/server"
2+
3+
export async function GET(request: Request) {
4+
const { searchParams } = new URL(request.url)
5+
const url = decodeURIComponent(searchParams.get('url') || '')
6+
7+
const ogs = require('open-graph-scraper');
8+
const options = { url: url };
9+
const data = await ogs(options);
10+
let { error, result } = data;
11+
if (error) {
12+
result = {
13+
"ogTitle": "Error",
14+
"ogDescription": "Error retrieving metadata.",
15+
}
16+
}
17+
return NextResponse.json(result)
18+
}

app/globals.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
--scrollbar-bg: theme('colors.slate.800');
1313
}
1414

15+
code {
16+
word-break: break-all;
17+
}
18+
1519
::-webkit-scrollbar {
1620
width: 6px;
1721
height: 6px;

components/background-image/APIBackgroundImage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import Image from "next/image";
33
const backgroundImageSetting = require("@/config").blogConfig.background_image.settings
44

55
export default function APIBackgroundImage() {
6+
const image = backgroundImageSetting.url ?? "/api/image-api";
67

7-
const image = backgroundImageSetting.image ?? "/api/image-api";
88
return (
99
<>
1010
<Image

components/mdx/MDXComponents.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,17 @@ function a({ href, children }: React.HTMLProps<HTMLAnchorElement>) {
1818
);
1919
}
2020

21+
function ul({ children, className }: React.HTMLProps<HTMLUListElement>) {
22+
let style = {};
23+
24+
if (className && className.includes('contains-task-list')) {
25+
style = { listStyleType: 'none' };
26+
}
27+
28+
return <ul style={style}>{children}</ul>;
29+
}
30+
2131
export const MDXComponents = {
22-
a
32+
a,
33+
ul
2334
}

components/mdx/MDXStyles.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ export default function MDXStyles({ children }: MDXStylesProps) {
1919
"dark:prose-blockquote:text-primary_color",
2020
"prose-hr:border-slate-700 dark:prose-hr:border-slate-300",
2121
"prose-th:border-secondary_color/75 dark:prose-th:border-secondary_color-dark/75 prose-th:border-b-2 prose-th:font-bold",
22-
"prose-td:border-secondary_color/50 dark:prose-td:border-secondary_color-dark/50 prose-td:border-b"
22+
"prose-td:border-secondary_color/50 dark:prose-td:border-secondary_color-dark/50 prose-td:border-b",
23+
"prose-img:mx-auto"
2324
)}
2425
>
2526
{children}

config/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,12 @@ export const blogConfig: BlogConfig = {
4040
title: "Content Components",
4141
child: [
4242
{
43-
title: "My Anime List Component",
44-
href: "/my-anime-list"
43+
title: "My Anime List Components",
44+
href: "/anime-list"
45+
},
46+
{
47+
title: "Link Card Components",
48+
href: "/link-card"
4549
}
4650
]
4751
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
"use client";
2+
3+
import { cn } from "@/lib/utils";
4+
import useSWR from "swr";
5+
import {useState} from "react";
6+
7+
type LinkCardProps = {
8+
link: string;
9+
}
10+
11+
const fetcher = (url: string) => fetch(url).then(r => r.json())
12+
13+
export default function LinkCard({ link }: LinkCardProps) {
14+
const [hover, setHover] = useState(false);
15+
const { data, error, isLoading } = useSWR(
16+
"/api/content-components/link-card/link-card?url=" + encodeURIComponent(link),
17+
fetcher)
18+
19+
if (isLoading) return (
20+
<div className={"animate-pulse"}>
21+
<div className={cn(
22+
"flex p-2 mx-auto rounded-xl not-prose",
23+
"md:w-7/12 h-full",
24+
"backdrop-blur-2xl overflow-hidden bg-slate-50/50 dark:bg-gray-800/70"
25+
)}>
26+
<div className={"h-32 w-32 flex items-center"}>
27+
<div className={"rounded-xl h-full w-full bg-slate-300 dark:bg-slate-500"}></div>
28+
</div>
29+
<div className={"h-32 pl-4 flex-1 flex flex-col space-y-2"}>
30+
<div className={"flex flex-col space-y-1"}>
31+
<div className={"h-4 bg-slate-400 dark:bg-slate-500 rounded"}></div>
32+
<div className={"h-4 bg-slate-400 dark:bg-slate-500 rounded"}></div>
33+
</div>
34+
<div className={"flex flex-col space-y-1"}>
35+
<div className={"h-3 bg-slate-400 dark:bg-slate-500 rounded"}></div>
36+
<div className={"h-3 bg-slate-400 dark:bg-slate-500 rounded"}></div>
37+
<div className={"h-3 bg-slate-400 dark:bg-slate-500 rounded"}></div>
38+
</div>
39+
</div>
40+
</div>
41+
</div>
42+
)
43+
44+
if (error || data.error) return <p>Error: {error}</p>
45+
46+
if (data) return (
47+
<div onMouseEnter={() => setHover(true)}
48+
onMouseLeave={() => setHover(false)}
49+
onClick={() => window.location.href = link}
50+
style={hover ? {cursor: 'pointer'} : {}}
51+
className={cn(
52+
"flex p-2 mx-auto rounded-xl not-prose",
53+
"md:w-7/12 h-full duration-500",
54+
"backdrop-blur-2xl overflow-hidden bg-slate-50/50 dark:bg-gray-800/70",
55+
{"shadow-lg shadow-primary_color/50 dark:shadow-primary_color-dark/30": hover}
56+
)}>
57+
<div className={"h-32 w-32 flex items-center"}>
58+
{data.ogImage && data.ogImage[0]?.url ? (
59+
<img className={"h-max w-max mx-auto rounded-lg"}
60+
alt={data.ogTitle}
61+
src={data.ogImage[0].url}/>
62+
) : (
63+
<img className={"h-max w-max mx-auto rounded-lg"}
64+
alt={data.ogTitle}
65+
src={"image-not-found.png"}/>
66+
)}
67+
</div>
68+
<div className={"h-32 pl-4 flex-1 flex flex-col space-y-2"}>
69+
<div className={"line-clamp-2 font-bold text-base"}>
70+
{data.ogTitle}
71+
</div>
72+
<p className={"line-clamp-3 font-light text-sm"}>
73+
{data.ogDescription}
74+
</p>
75+
</div>
76+
</div>
77+
)
78+
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
---
2+
title: Markdown Preview
3+
date: 2000-01-01
4+
excerpt: Markdown Preview
5+
image: https://img.qwq.xyz/2023/c12bb8eabe700.png
6+
---
7+
8+
# Heading 1
9+
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
10+
11+
## Heading 2
12+
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
13+
14+
### Heading 3
15+
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
16+
17+
#### Heading 4
18+
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
19+
20+
##### Heading 5
21+
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
22+
23+
###### Heading 6
24+
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
25+
26+
## Bold
27+
**Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.**
28+
29+
## Italic
30+
*Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.*
31+
32+
## Blockquote
33+
> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
34+
35+
## Ordered List
36+
1. First item
37+
2. Second item
38+
3. Third item
39+
40+
## Unordered List
41+
- First item
42+
- Second item
43+
- Third item
44+
45+
## Horizontal Rule
46+
---
47+
48+
## Link
49+
(not link) [link](https://www.example.com) (not link)
50+
51+
## Image
52+
![alt text](/_next/image?url=%2Fimg.png&w=256&q=75)
53+
54+
## Table
55+
| Syntax | Description |
56+
| ----------- | ----------- |
57+
| Header | Title |
58+
| Paragraph | Text |
59+
60+
## Code
61+
Random Python code: _`list(map(lambda x: x**2, filter(lambda x: x % 2 == 0, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10])))`_
62+
63+
Not code: _`6BEF9A1D57F36C055D7799F810E9A2BB432E8F59C05B33B19C9A0784C76DDBE79838AB2621E49E06D74D5FADB41C4395`_
64+
65+
## Fenced Code Block
66+
```json example.json
67+
{
68+
"firstName": "John",
69+
"lastName": "Smith",
70+
"age": 25
71+
}
72+
```
73+
74+
## Footnotes
75+
Here's a sentence with a footnote. [^1]
76+
77+
## Strikethrough
78+
~~The world is flat.~~
79+
80+
## Task List
81+
82+
- [x] Write the press release
83+
- [ ] Update the website
84+
- [ ] Contact the media
85+
86+
87+
88+
89+
[^1]: This is the footnote.
90+
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: My Anime List Component
2+
title: Anime List Components
33
---
44

55
```mdx /content/pages/my-anime-list.mdx

content/pages/link-card.mdx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
title: Link Card Components
3+
---
4+
5+
```mdx /content/pages/link-card.mdx
6+
import LinkCard from "../../content-components/link-card/LinkCard";
7+
8+
<LinkCard link={"https://github.com"}/>
9+
```
10+
11+
import LinkCard from "../../content-components/link-card/LinkCard";
12+
13+
<LinkCard link={"https://github.com"}/>
14+
15+
16+

0 commit comments

Comments
 (0)