From 171f81d6051c9c746cd4b53bdf453a65ab72933d Mon Sep 17 00:00:00 2001 From: sailong Date: Tue, 17 Jun 2025 17:51:29 +0800 Subject: [PATCH] feat(UI):File-change supports files such as dockerfile, gitignore and license --- .../apps/web/components/DiffView/FileDiff.tsx | 2 +- .../web/components/DiffView/parsedDiffs.ts | 68 ++++++++++++------- 2 files changed, 44 insertions(+), 26 deletions(-) diff --git a/moon/apps/web/components/DiffView/FileDiff.tsx b/moon/apps/web/components/DiffView/FileDiff.tsx index 257232761..84b46aa6f 100644 --- a/moon/apps/web/components/DiffView/FileDiff.tsx +++ b/moon/apps/web/components/DiffView/FileDiff.tsx @@ -71,7 +71,7 @@ export default function FileDiff({ diffs }: { diffs: string }) { file: { path: string; lang: string; diff: string }; instance: DiffFile; }) => { - if (file.lang === 'plaintext') { + if (file.lang === 'binary') { return
Binary file
} diff --git a/moon/apps/web/components/DiffView/parsedDiffs.ts b/moon/apps/web/components/DiffView/parsedDiffs.ts index 32d48f792..1f35f81cd 100644 --- a/moon/apps/web/components/DiffView/parsedDiffs.ts +++ b/moon/apps/web/components/DiffView/parsedDiffs.ts @@ -1,31 +1,49 @@ const extensionToLangMap: Record = { - ".ts": "typescript", - ".tsx": "typescriptreact", - ".js": "javascript", - ".jsx": "javascriptreact", - ".json": "json", - ".md": "markdown", - ".py": "python", - ".rs": "rust", - ".cpp": "cpp", - ".c": "c", - ".h": "cpp", - ".java": "java", - ".go": "go", - ".sh": "bash", - ".yml": "yaml", - ".yaml": "yaml", - ".css": "css", - ".scss": "scss", - ".html": "html", - ".vue": "vue", - ".toml": "toml", -}; + '.ts': 'typescript', + '.tsx': 'tsx', + '.js': 'javascript', + '.jsx': 'jsx', + '.json': 'json', + '.md': 'markdown', + '.py': 'python', + '.rs': 'rust', + '.cpp': 'cpp', + '.c': 'c', + '.h': 'cpp', + '.java': 'java', + '.go': 'go', + '.sh': 'bash', + '.yml': 'yaml', + '.yaml': 'yaml', + '.css': 'css', + '.scss': 'scss', + '.html': 'html', + '.vue': 'vue', + '.toml': 'toml', + 'dockerfile': 'dockerfile', + '.dockerfile': 'dockerfile', + 'license-mit': 'plaintext', + 'buck': 'plaintext', + '.gitignore': 'plaintext', + '.env': 'plaintext', + 'license-third-party': 'plaintext', + 'license-apache': 'plaintext', +} function getLangFromPath(path: string): string { - const ext = path.match(/\.[^./\\]+$/)?.[0]?.toLowerCase(); + const extMatch = path.match(/\.[^./\\]+$/); - return ext ? extensionToLangMap[ext] ?? "plaintext" : "plaintext"; + if(extMatch) { + return extensionToLangMap[extMatch[0].toLowerCase()] ?? "binary"; + } else { + const lastPart = path.split('/').pop()?.toLowerCase(); + + if(lastPart) { + return extensionToLangMap[lastPart] ?? "binary"; + } + } + + return "binary"; } export function parsedDiffs(diffText: string): { path: string; lang: string; diff: string }[] { @@ -52,7 +70,7 @@ export function parsedDiffs(diffText: string): { path: string; lang: string; dif } } - if (getLangFromPath(path) === "plaintext") { + if (getLangFromPath(path) === "binary") { return { path, lang: getLangFromPath(path),