mirror of
https://git.aramjonghu.dev/AramJonghu/aramjonghu-site.git
synced 2026-09-11 17:13:29 +02:00
audit fix + beter markdown rendering, more robust with image support
This commit is contained in:
@@ -16,6 +16,7 @@
|
|||||||
"react-markdown": "^10.1.0",
|
"react-markdown": "^10.1.0",
|
||||||
"rehype-raw": "^7.0.0",
|
"rehype-raw": "^7.0.0",
|
||||||
"rehype-sanitize": "^6.0.0",
|
"rehype-sanitize": "^6.0.0",
|
||||||
|
"remark-gfm": "^4.0.1",
|
||||||
"tailwindcss": "^4.2.2"
|
"tailwindcss": "^4.2.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
@@ -36,5 +37,8 @@
|
|||||||
"typescript-language-server": "^5.3.0",
|
"typescript-language-server": "^5.3.0",
|
||||||
"vite": "^8.0.4",
|
"vite": "^8.0.4",
|
||||||
"vscode-langservers-extracted": "^4.10.0"
|
"vscode-langservers-extracted": "^4.10.0"
|
||||||
|
},
|
||||||
|
"allowScripts": {
|
||||||
|
"core-js@3.49.0": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import { useEffect, useState, useMemo } from "react";
|
import { useEffect, useState, useMemo } from "react";
|
||||||
import ReactMarkdown from "react-markdown";
|
import ReactMarkdown from "react-markdown";
|
||||||
|
import remarkGfm from "remark-gfm";
|
||||||
import rehypeRaw from "rehype-raw";
|
import rehypeRaw from "rehype-raw";
|
||||||
|
import rehypeSanitize from "rehype-sanitize";
|
||||||
|
|
||||||
const toRawUrl = (repoUrl) => {
|
const toRawUrl = (repoUrl) => {
|
||||||
if (!repoUrl) return repoUrl;
|
if (!repoUrl) return repoUrl;
|
||||||
@@ -35,7 +37,7 @@ const getRepoRawBase = (repoUrl) => {
|
|||||||
|
|
||||||
const rawIndex = parts.indexOf("raw");
|
const rawIndex = parts.indexOf("raw");
|
||||||
if (rawIndex !== -1) {
|
if (rawIndex !== -1) {
|
||||||
return `${url.origin}/${parts.slice(0, rawIndex + 2).join("/")}`;
|
return `${url.origin}/${parts.slice(0, rawIndex + 3).join("/")}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@@ -46,23 +48,11 @@ const getRepoRawBase = (repoUrl) => {
|
|||||||
|
|
||||||
const resolveImageSrc = (src, base) => {
|
const resolveImageSrc = (src, base) => {
|
||||||
if (!src) return src;
|
if (!src) return src;
|
||||||
|
|
||||||
if (src.startsWith("http")) return src;
|
if (src.startsWith("http")) return src;
|
||||||
|
|
||||||
if (src.includes("/blob/")) {
|
|
||||||
return src
|
|
||||||
.replace("github.com", "raw.githubusercontent.com")
|
|
||||||
.replace("/blob/", "/");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!base) return src;
|
if (!base) return src;
|
||||||
|
|
||||||
const clean = src.replace(/^.\//, "");
|
const clean = src.replace(/^.\//, "");
|
||||||
|
if (src.startsWith("/")) return base + src;
|
||||||
if (src.startsWith("/")) {
|
|
||||||
return base + src;
|
|
||||||
}
|
|
||||||
|
|
||||||
return `${base}/${clean}`;
|
return `${base}/${clean}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -106,7 +96,8 @@ export default function ProjectsReadme({ repoUrl }) {
|
|||||||
) : (
|
) : (
|
||||||
<div className="text-ctp-text leading-relaxed prose prose-base md:prose-lg dark:prose-invert max-w-none">
|
<div className="text-ctp-text leading-relaxed prose prose-base md:prose-lg dark:prose-invert max-w-none">
|
||||||
<ReactMarkdown
|
<ReactMarkdown
|
||||||
rehypePlugins={[rehypeRaw]}
|
remarkPlugins={[remarkGfm]}
|
||||||
|
rehypePlugins={[rehypeRaw, rehypeSanitize]}
|
||||||
components={{
|
components={{
|
||||||
code({ className, children, ...props }) {
|
code({ className, children, ...props }) {
|
||||||
const isBlock =
|
const isBlock =
|
||||||
@@ -208,7 +199,7 @@ export default function ProjectsReadme({ repoUrl }) {
|
|||||||
<img
|
<img
|
||||||
src={resolved}
|
src={resolved}
|
||||||
alt={alt}
|
alt={alt}
|
||||||
className="max-w-full h-auto rounded-lg my-4 shadow-sm"
|
className="max-w-full h-auto rounded-md my-4 shadow-sm border-2 border-ctp-text"
|
||||||
loading="lazy"
|
loading="lazy"
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user