Merge pull request #742 from ajnart/fix/rss-crash

🚑 Fix RSS widget crash
This commit is contained in:
Thomas Camlong
2023-03-21 11:28:40 +08:00
committed by GitHub
2 changed files with 19 additions and 10 deletions

View File

@@ -53,6 +53,7 @@ export const Get = async (request: NextApiRequest, response: NextApiResponse) =>
title: item.title ? decode(item.title) : undefined,
content: decode(item.content),
enclosure: createEnclosure(item),
link: createLink(item),
}))
.sort((a: { pubDate: number }, b: { pubDate: number }) => {
if (!a.pubDate || !b.pubDate) {
@@ -70,6 +71,14 @@ export const Get = async (request: NextApiRequest, response: NextApiResponse) =>
});
};
const createLink = (item: any) => {
if (item.link) {
return item.link;
}
return item.guid;
};
const createEnclosure = (item: any) => {
if (item.enclosure) {
return item.enclosure;

View File

@@ -16,7 +16,6 @@ import {
Title,
UnstyledButton,
} from '@mantine/core';
import { useElementSize } from '@mantine/hooks';
import {
IconBulldozer,
IconCalendarTime,
@@ -65,7 +64,6 @@ function RssTile({ widget }: RssTileProps) {
);
const { classes } = useStyles();
const [loadingOverlayVisible, setLoadingOverlayVisible] = useState(false);
const { ref, height } = useElementSize();
if (!data || isLoading) {
return (
@@ -88,7 +86,7 @@ function RssTile({ widget }: RssTileProps) {
}
return (
<Stack ref={ref} h="100%">
<Stack h="100%">
<LoadingOverlay visible={loadingOverlayVisible} />
<Flex gap="md">
{data.feed.image ? (
@@ -121,7 +119,7 @@ function RssTile({ widget }: RssTileProps) {
<Card
key={index}
withBorder
component={Link}
component={Link ?? 'div'}
href={item.link}
radius="md"
target="_blank"
@@ -183,12 +181,14 @@ function RssTile({ widget }: RssTileProps) {
{data.feed.pubDate}
</Text>
</Group>
{data.feed.lastBuildDate && (
<Group>
<IconBulldozer size={14} />
<Text color="dimmed" size="sm">
{data.feed.lastBuildDate}
</Text>
</Group>
)}
{data.feed.feedUrl && (
<Group spacing="sm">
<IconSpeakerphone size={14} />