feat: cleanup the invalid tags in feed xml.
This commit is contained in:
parent
66f7e0fb21
commit
289c033736
@ -103,7 +103,6 @@ if (typeof comments !== 'undefined' && comments !== null) {
|
|||||||
const rid = ridInput.value;
|
const rid = ridInput.value;
|
||||||
ridInput.value = '0';
|
ridInput.value = '0';
|
||||||
if (rid !== '0') {
|
if (rid !== '0') {
|
||||||
console.log({ rid: rid });
|
|
||||||
const children = comments.querySelector(`#atk-comment-${rid}`).querySelector('.children');
|
const children = comments.querySelector(`#atk-comment-${rid}`).querySelector('.children');
|
||||||
if (children !== null && children.querySelectorAll('li').length === 0) {
|
if (children !== null && children.querySelectorAll('li').length === 0) {
|
||||||
children.remove();
|
children.remove();
|
||||||
|
@ -46,10 +46,7 @@ export const loadComments = async (
|
|||||||
if (title !== null) {
|
if (title !== null) {
|
||||||
params = { ...params, title: title };
|
params = { ...params, title: title };
|
||||||
}
|
}
|
||||||
const query = querystring.stringify(params);
|
const data = await fetch(urlJoin(server, `/api/v2/comments?${querystring.stringify(params)}`))
|
||||||
|
|
||||||
console.log(query);
|
|
||||||
const data = await fetch(urlJoin(server, `/api/v2/comments?${query}`))
|
|
||||||
.then((response) => response.json())
|
.then((response) => response.json())
|
||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
console.log(e);
|
console.log(e);
|
||||||
@ -158,8 +155,11 @@ const parseContent = async (content: string): Promise<string> => {
|
|||||||
'li',
|
'li',
|
||||||
],
|
],
|
||||||
allowAttributes: {
|
allowAttributes: {
|
||||||
img: ['src', 'width', 'height'],
|
src: ['img'],
|
||||||
a: ['rel', 'target'],
|
width: ['img'],
|
||||||
|
height: ['img'],
|
||||||
|
rel: ['a'],
|
||||||
|
target: ['a'],
|
||||||
},
|
},
|
||||||
allowComments: false,
|
allowComments: false,
|
||||||
}),
|
}),
|
||||||
|
@ -5,7 +5,7 @@ interface Props extends Image {
|
|||||||
alt: string;
|
alt: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const { alt, ...meta } = Astro.props;
|
const { alt, src, width, height } = Astro.props;
|
||||||
---
|
---
|
||||||
|
|
||||||
<img src={meta.src} {alt} loading="lazy" width={meta.width} height={meta.height} style={blurStyle(meta)} />
|
<img {src} {alt} loading="lazy" {width} {height} style={blurStyle(Astro.props)} />
|
||||||
|
11
src/components/image/UnstyledImage.astro
Normal file
11
src/components/image/UnstyledImage.astro
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
---
|
||||||
|
import type { Image } from '@/helpers/images';
|
||||||
|
|
||||||
|
interface Props extends Image {
|
||||||
|
alt: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const { alt, src } = Astro.props;
|
||||||
|
---
|
||||||
|
|
||||||
|
<img {src} {alt} />
|
@ -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 UnstyledMusicPlayer from '@/components/player/UnstyledMusicPlayer.astro';
|
||||||
import { posts } from '@/helpers/schema';
|
import { posts } from '@/helpers/schema';
|
||||||
|
|
||||||
@ -16,4 +16,4 @@ if (!post) {
|
|||||||
const { Content } = await post.render();
|
const { Content } = await post.render();
|
||||||
---
|
---
|
||||||
|
|
||||||
<Content components={{ MusicPlayer: UnstyledMusicPlayer, Image: Image }} />
|
<Content components={{ MusicPlayer: UnstyledMusicPlayer, Image: UnstyledImage }} />
|
||||||
|
@ -6,4 +6,4 @@ interface Props extends MusicPlayerProps {}
|
|||||||
const { url } = await resolveSong(Astro.props);
|
const { url } = await resolveSong(Astro.props);
|
||||||
---
|
---
|
||||||
|
|
||||||
{url !== '' && <audio controls src={url} />}
|
{url !== '' && <audio src={url} />}
|
||||||
|
@ -14,12 +14,29 @@ const cleanupContent = async (html: string) => {
|
|||||||
// Make sure images are absolute, some readers are not smart enough to figure it out
|
// Make sure images are absolute, some readers are not smart enough to figure it out
|
||||||
if (node.name === 'img' && node.attributes.src?.startsWith('/')) {
|
if (node.name === 'img' && node.attributes.src?.startsWith('/')) {
|
||||||
node.attributes.src = urlJoin(import.meta.env.SITE, node.attributes.src);
|
node.attributes.src = urlJoin(import.meta.env.SITE, node.attributes.src);
|
||||||
|
const { src, alt } = node.attributes;
|
||||||
|
node.attributes = { src, alt };
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure links are absolute, some readers are not smart enough to figure it out
|
// Make sure links are absolute, some readers are not smart enough to figure it out
|
||||||
if (node.name === 'a' && node.attributes.href?.startsWith('/')) {
|
if (node.name === 'a') {
|
||||||
|
if (node.attributes.href?.startsWith('/')) {
|
||||||
node.attributes.href = urlJoin(import.meta.env.SITE, node.attributes.href);
|
node.attributes.href = urlJoin(import.meta.env.SITE, node.attributes.href);
|
||||||
}
|
}
|
||||||
|
const { href, title } = node.attributes;
|
||||||
|
const attributes: Record<string, string> = { href };
|
||||||
|
if (typeof title !== 'undefined') {
|
||||||
|
attributes.title = title;
|
||||||
|
}
|
||||||
|
node.attributes = attributes;
|
||||||
|
|
||||||
|
// Remove inner links.
|
||||||
|
if (href.startsWith('#')) {
|
||||||
|
const code = node as unknown as TextNode;
|
||||||
|
code.type = TEXT_NODE;
|
||||||
|
code.value = '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Remove favicon images, some readers don't know they should be inline and it ends up being a broken image
|
// Remove favicon images, some readers don't know they should be inline and it ends up being a broken image
|
||||||
if ('data-favicon' in node.attributes || 'data-favicon-span' in node.attributes) {
|
if ('data-favicon' in node.attributes || 'data-favicon-span' in node.attributes) {
|
||||||
@ -47,7 +64,12 @@ const cleanupContent = async (html: string) => {
|
|||||||
'data-astro-source-file': ['*'],
|
'data-astro-source-file': ['*'],
|
||||||
'data-favicon': ['*'],
|
'data-favicon': ['*'],
|
||||||
'data-image-component': ['img'],
|
'data-image-component': ['img'],
|
||||||
|
style: ['*'],
|
||||||
|
'data-language': ['*'],
|
||||||
|
'data-footnotes': ['*'],
|
||||||
},
|
},
|
||||||
|
allowCustomElements: false,
|
||||||
|
allowComments: false,
|
||||||
}),
|
}),
|
||||||
]);
|
]);
|
||||||
};
|
};
|
||||||
@ -87,7 +109,7 @@ export const GET = async () => {
|
|||||||
title: post.title,
|
title: post.title,
|
||||||
pubDate: post.date,
|
pubDate: post.date,
|
||||||
description: post.summary,
|
description: post.summary,
|
||||||
author: options.author.name,
|
author: `${options.author.email} (${options.author.name})`,
|
||||||
content: contents.get(post.slug) ?? post.summary,
|
content: contents.get(post.slug) ?? post.summary,
|
||||||
categories: [post.category, ...post.tags],
|
categories: [post.category, ...post.tags],
|
||||||
})),
|
})),
|
||||||
|
Loading…
Reference in New Issue
Block a user