From 6766c0dc70e95daa88294ef4468790fd661c5d58 Mon Sep 17 00:00:00 2001 From: Yufan Sheng Date: Mon, 17 Jun 2024 05:42:12 +0800 Subject: [PATCH] feat: cleanup the invalid tags in feed xml. --- src/asserts/scripts/yufan.me.js | 1 - src/components/comment/artalk.ts | 12 ++++---- src/components/image/Image.astro | 4 +-- src/components/image/UnstyledImage.astro | 11 ++++++++ src/components/page/post/PostContent.astro | 4 +-- .../player/UnstyledMusicPlayer.astro | 2 +- src/pages/feed.ts | 28 +++++++++++++++++-- 7 files changed, 47 insertions(+), 15 deletions(-) create mode 100644 src/components/image/UnstyledImage.astro diff --git a/src/asserts/scripts/yufan.me.js b/src/asserts/scripts/yufan.me.js index d4164d2..82be599 100644 --- a/src/asserts/scripts/yufan.me.js +++ b/src/asserts/scripts/yufan.me.js @@ -103,7 +103,6 @@ if (typeof comments !== 'undefined' && comments !== null) { const rid = ridInput.value; ridInput.value = '0'; if (rid !== '0') { - console.log({ rid: rid }); const children = comments.querySelector(`#atk-comment-${rid}`).querySelector('.children'); if (children !== null && children.querySelectorAll('li').length === 0) { children.remove(); diff --git a/src/components/comment/artalk.ts b/src/components/comment/artalk.ts index 0e5e270..dc6b1d4 100644 --- a/src/components/comment/artalk.ts +++ b/src/components/comment/artalk.ts @@ -46,10 +46,7 @@ export const loadComments = async ( if (title !== null) { params = { ...params, title: title }; } - const query = querystring.stringify(params); - - console.log(query); - const data = await fetch(urlJoin(server, `/api/v2/comments?${query}`)) + const data = await fetch(urlJoin(server, `/api/v2/comments?${querystring.stringify(params)}`)) .then((response) => response.json()) .catch((e) => { console.log(e); @@ -158,8 +155,11 @@ const parseContent = async (content: string): Promise => { 'li', ], allowAttributes: { - img: ['src', 'width', 'height'], - a: ['rel', 'target'], + src: ['img'], + width: ['img'], + height: ['img'], + rel: ['a'], + target: ['a'], }, allowComments: false, }), diff --git a/src/components/image/Image.astro b/src/components/image/Image.astro index 2d977a7..8d99168 100644 --- a/src/components/image/Image.astro +++ b/src/components/image/Image.astro @@ -5,7 +5,7 @@ interface Props extends Image { alt: string; } -const { alt, ...meta } = Astro.props; +const { alt, src, width, height } = Astro.props; --- - + diff --git a/src/components/image/UnstyledImage.astro b/src/components/image/UnstyledImage.astro new file mode 100644 index 0000000..4dc52c2 --- /dev/null +++ b/src/components/image/UnstyledImage.astro @@ -0,0 +1,11 @@ +--- +import type { Image } from '@/helpers/images'; + +interface Props extends Image { + alt: string; +} + +const { alt, src } = Astro.props; +--- + + diff --git a/src/components/page/post/PostContent.astro b/src/components/page/post/PostContent.astro index 4a9a524..bd03590 100644 --- a/src/components/page/post/PostContent.astro +++ b/src/components/page/post/PostContent.astro @@ -1,5 +1,5 @@ --- -import Image from '@/components/image/Image.astro'; +import UnstyledImage from '@/components/image/UnstyledImage.astro'; import UnstyledMusicPlayer from '@/components/player/UnstyledMusicPlayer.astro'; import { posts } from '@/helpers/schema'; @@ -16,4 +16,4 @@ if (!post) { const { Content } = await post.render(); --- - + diff --git a/src/components/player/UnstyledMusicPlayer.astro b/src/components/player/UnstyledMusicPlayer.astro index c438d3e..41e3aae 100644 --- a/src/components/player/UnstyledMusicPlayer.astro +++ b/src/components/player/UnstyledMusicPlayer.astro @@ -6,4 +6,4 @@ interface Props extends MusicPlayerProps {} const { url } = await resolveSong(Astro.props); --- -{url !== '' &&