Skip to content

Commit 50a652f

Browse files
committed
Update components
1 parent 0469756 commit 50a652f

File tree

2 files changed

+30
-12
lines changed

2 files changed

+30
-12
lines changed

components/ExternLink.tsx

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import React, { useEffect, useState } from 'react';
2-
import {IconChevronRight, Icon as TablerIcon} from '@tabler/icons-react'
3-
import { channel } from 'diagnostics_channel';
2+
import { IconChevronRight, Icon as TablerIcon } from '@tabler/icons-react';
43

54
interface ExternLinkProps {
65
href: string;
@@ -14,7 +13,6 @@ interface LinkMetaData {
1413
icon: string;
1514
}
1615

17-
1816
const fetchMetaData = async (url: string): Promise<LinkMetaData> => {
1917
try {
2018
const response = await fetch(url);
@@ -26,14 +24,14 @@ const fetchMetaData = async (url: string): Promise<LinkMetaData> => {
2624
const doc = parser.parseFromString(text, 'text/html');
2725

2826
const title = doc.querySelector('meta[property="og:title"]')?.getAttribute('content') ||
29-
doc.querySelector('title')?.textContent ||
30-
'No title';
27+
doc.querySelector('title')?.textContent ||
28+
'No title';
3129
const description = doc.querySelector('meta[property="og:description"]')?.getAttribute('content') ||
32-
doc.querySelector('meta[name="description"]')?.getAttribute('content') ||
33-
'No description';
30+
doc.querySelector('meta[name="description"]')?.getAttribute('content') ||
31+
'No description';
3432
const icon = doc.querySelector('link[rel="icon"]')?.getAttribute('href') ||
35-
doc.querySelector('link[rel="shortcut icon"]')?.getAttribute('href') ||
36-
'https://example.com/default-icon.png';
33+
doc.querySelector('link[rel="shortcut icon"]')?.getAttribute('href') ||
34+
'https://example.com/default-icon.png';
3735

3836
return { title, description, icon: new URL(icon, url).href };
3937
} catch (error) {
@@ -45,7 +43,7 @@ const fetchMetaData = async (url: string): Promise<LinkMetaData> => {
4543
};
4644
}
4745
};
48-
46+
4947
const ExternLink: React.FC<ExternLinkProps> = ({ href, icon, manualTitle }) => {
5048
const [metaData, setMetaData] = useState<LinkMetaData | null>(null);
5149
const [loading, setLoading] = useState(true);
@@ -70,10 +68,18 @@ const ExternLink: React.FC<ExternLinkProps> = ({ href, icon, manualTitle }) => {
7068
return <div>Loading...</div>; // Display a loading state while fetching metadata
7169
}
7270

71+
// Funktion zur Kürzung der Beschreibung
72+
const truncateDescription = (description: string, maxLength: number) => {
73+
if (description.length <= maxLength) {
74+
return description;
75+
}
76+
return description.substring(0, maxLength) + '...'; // Kürzen und '...' hinzufügen
77+
};
78+
7379
return (
7480
<a
7581
href={href}
76-
className="w-full border border-gray-200 shadow-sm hover:shadow-md dark:border-neutral-700 dark:hover:border-neutral-600 transition-all duration-200 dark:bg-neutral-900 bg-white rounded-lg overflow-hidden flex flex-col justify-start relative"
82+
className="w-full my-5 border border-gray-200 shadow-sm hover:shadow-md dark:border-neutral-700 dark:hover:border-neutral-600 transition-all duration-200 dark:bg-neutral-900 bg-white rounded-lg overflow-hidden flex flex-col justify-start relative"
7783
target="_blank"
7884
rel="noopener noreferrer"
7985
>
@@ -98,7 +104,7 @@ const ExternLink: React.FC<ExternLinkProps> = ({ href, icon, manualTitle }) => {
98104
{metaData?.title}
99105
</span>
100106
<span className="text-sm text-gray-500 dark:text-gray-300">
101-
{metaData?.description}
107+
{metaData?.description && truncateDescription(metaData.description, 100)} {/* Hier wird die Beschreibung gekürzt */}
102108
</span>
103109
</div>
104110
{/* Arrow Icon */}

components/YouTube.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export default function YouTube ({ id } : { id : string }){
2+
return (
3+
<div className="my-8">
4+
<iframe
5+
className="aspect-video w-full"
6+
src={"https://www.youtube.com/embed/" + id}
7+
title="YouTube Video Player"
8+
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
9+
></iframe>
10+
</div>
11+
);
12+
};

0 commit comments

Comments
 (0)