fix: feed field
This commit is contained in:
parent
308562dc7a
commit
fb23caebfc
8 changed files with 77 additions and 22 deletions
|
@ -1,6 +1,7 @@
|
|||
import rss from "@astrojs/rss";
|
||||
import { fetchGlobals } from "@utils/data/globals.js";
|
||||
import { fetchActivity } from "@utils/data/activity.js";
|
||||
import { sanitizeContent, md } from "@utils/helpers/general.js";
|
||||
|
||||
export const prerender = true;
|
||||
|
||||
|
@ -17,7 +18,7 @@ export async function GET() {
|
|||
title: item.feed.title,
|
||||
pubDate: item.feed.date,
|
||||
link: item.feed.url,
|
||||
description: item.feed.description,
|
||||
content: sanitizeContent(md(item.feed.description)),
|
||||
})),
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import rss from "@astrojs/rss";
|
||||
import { fetchGlobals } from "@utils/data/globals.js";
|
||||
import { fetchBooks } from "@utils/data/books.js";
|
||||
import { escapeHtml, md } from "@utils/helpers/general.js";
|
||||
import { sanitizeContent, md } from "@utils/helpers/general.js";
|
||||
|
||||
export const prerender = true;
|
||||
|
||||
|
@ -18,7 +18,7 @@ export async function GET() {
|
|||
title: book.feed.title,
|
||||
pubDate: book.feed.date,
|
||||
link: book.feed.url,
|
||||
description: escapeHtml(md(book.feed.description)),
|
||||
content: sanitizeContent(md(book.feed.description)),
|
||||
})),
|
||||
});
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ export async function GET() {
|
|||
title: link.feed.title,
|
||||
pubDate: link.feed.date,
|
||||
link: link.feed.url,
|
||||
description: link.feed.description,
|
||||
content: link.feed.description,
|
||||
})),
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import rss from "@astrojs/rss";
|
||||
import { fetchGlobals } from "@utils/data/globals.js";
|
||||
import { fetchMovies } from "@utils/data/movies.js";
|
||||
import { escapeHtml, md } from "@utils/helpers/general.js";
|
||||
import { sanitizeContent, md } from "@utils/helpers/general.js";
|
||||
|
||||
export const prerender = true;
|
||||
|
||||
|
@ -18,7 +18,7 @@ export async function GET() {
|
|||
title: movie.feed.title,
|
||||
pubDate: movie.feed.date,
|
||||
link: movie.feed.url,
|
||||
description: escapeHtml(md(movie.feed.description)),
|
||||
content: sanitizeContent(md(movie.feed.description)),
|
||||
})),
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import rss from "@astrojs/rss";
|
||||
import { fetchGlobals } from "@utils/data/globals.js";
|
||||
import { fetchAllPosts } from "@utils/data/posts.js";
|
||||
import { escapeHtml, md } from "@utils/helpers/general.js";
|
||||
import { htmlToText, sanitizeContent, md } from "@utils/helpers/general.js";
|
||||
|
||||
export const prerender = true;
|
||||
|
||||
|
@ -18,7 +18,8 @@ export async function GET() {
|
|||
title: post.feed.title,
|
||||
pubDate: post.feed.date,
|
||||
link: post.feed.url,
|
||||
description: escapeHtml(md(post.feed.description)),
|
||||
description: htmlToText(md(post.feed.description)),
|
||||
content: sanitizeContent(md(post.feed.content)),
|
||||
})),
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import { convert } from "html-to-text";
|
||||
import { format } from "date-fns-tz";
|
||||
import sanitizeHtml from "sanitize-html";
|
||||
import markdownIt from "markdown-it";
|
||||
import markdownItAnchor from "markdown-it-anchor";
|
||||
import markdownItFootnote from "markdown-it-footnote";
|
||||
|
@ -60,19 +61,29 @@ export const htmlToText = (html) =>
|
|||
],
|
||||
});
|
||||
|
||||
export const escapeHtml = (input) =>
|
||||
typeof input === "string"
|
||||
? input.replace(/[&<>"']/g, (char) => {
|
||||
const map = {
|
||||
"&": "&",
|
||||
"<": "<",
|
||||
">": ">",
|
||||
'"': """,
|
||||
"'": "'",
|
||||
};
|
||||
return map[char];
|
||||
})
|
||||
: "";
|
||||
export const sanitizeContent = (html) =>
|
||||
sanitizeHtml(html, {
|
||||
allowedTags: [
|
||||
"p",
|
||||
"ul",
|
||||
"ol",
|
||||
"li",
|
||||
"strong",
|
||||
"em",
|
||||
"a",
|
||||
"img",
|
||||
"blockquote",
|
||||
"pre",
|
||||
"code",
|
||||
"h1",
|
||||
"h2",
|
||||
"h3",
|
||||
],
|
||||
allowedAttributes: {
|
||||
a: ["href"],
|
||||
img: ["src", "alt"],
|
||||
},
|
||||
});
|
||||
|
||||
// markdown
|
||||
const markdown = markdownIt({
|
||||
|
|
Reference in a new issue