From e8ddc4c7a482a181ab1438ece5bf911e9d0b47f3 Mon Sep 17 00:00:00 2001 From: DefectingCat Date: Fri, 19 May 2023 15:33:40 +0800 Subject: [PATCH] add single gist slice with 20 lines --- app/gists/gists-code.tsx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/gists/gists-code.tsx b/app/gists/gists-code.tsx index 87f48c0..418a2a0 100644 --- a/app/gists/gists-code.tsx +++ b/app/gists/gists-code.tsx @@ -15,6 +15,9 @@ interface Props { } const GistsCode = ({ file, showFileName = false }: Props) => { + const fileContent = showFileName + ? file.content + : file.content?.split('\n').slice(0, 20).join('\n'); const code = unified() .use(remarkParse) .use(remarkRehype) @@ -24,7 +27,7 @@ const GistsCode = ({ file, showFileName = false }: Props) => { createElement, Fragment, }) - .processSync(`\`\`\`${file.language ?? ''}\n${file.content}`).result; + .processSync(`\`\`\`${file.language ?? ''}\n${fileContent}`).result; return ( <> @@ -76,4 +79,4 @@ const GistsCode = ({ file, showFileName = false }: Props) => { ); }; -export default memo(GistsCode); +export default memo(GistsCode); \ No newline at end of file