From 1929ed84e3dd718cef3495f102e8cedb36a04f3c Mon Sep 17 00:00:00 2001 From: Chihuah <61900379+Chihuah@users.noreply.github.com> Date: Fri, 20 Jun 2025 11:30:10 +0800 Subject: [PATCH] feat: add publications download --- src/pages/Publications.tsx | 39 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/src/pages/Publications.tsx b/src/pages/Publications.tsx index d938d06..3b5d3d6 100644 --- a/src/pages/Publications.tsx +++ b/src/pages/Publications.tsx @@ -1,5 +1,5 @@ import React, { useState } from 'react' -import { ExternalLink, Search, Filter, Calendar, BookOpen, Award } from 'lucide-react' +import { ExternalLink, Search, Filter, Calendar, BookOpen, Award, Download } from 'lucide-react' import { Button } from '@/components/ui/button' import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card' import { Badge } from '@/components/ui/badge' @@ -414,6 +414,37 @@ const Publications: React.FC = () => { conference: publications.filter(p => p.type === 'Conference').length } + const formatPublication = (pub: Publication, index: number) => { + const authors = pub.authors.length > 1 + ? `${pub.authors.slice(0, -1).join(', ')} & ${pub.authors[pub.authors.length - 1]}` + : pub.authors[0] + + const volPages = pub.volume + ? pub.pages + ? `${pub.volume}:${pub.pages}` + : pub.volume + : pub.pages || '' + + const typePart = `(${pub.type}${pub.ranking ? ', ' + pub.ranking : ''})` + const doiPart = pub.doi ? ` https://doi.org/${pub.doi}` : '' + const journalPart = `${pub.journal}${volPages ? `, ${volPages}` : ''}` + + return `${index + 1}. ${authors}, "${pub.title}", ${pub.year}, ${journalPart}, ${typePart}${doiPart}` + } + + const downloadPublications = () => { + const lines = filteredPublications.map((pub, idx) => formatPublication(pub, idx)) + const blob = new Blob([lines.join('\n')], { type: 'text/plain' }) + const url = URL.createObjectURL(blob) + const link = document.createElement('a') + link.href = url + link.download = 'publications.txt' + document.body.appendChild(link) + link.click() + document.body.removeChild(link) + URL.revokeObjectURL(url) + } + const getTypeColor = (type: string) => { switch (type) { case 'SCI': return 'bg-slate-100 text-blue-800' @@ -479,7 +510,11 @@ const Publications: React.FC = () => { {/* Search and Filter */}