Skip to content

Commit

Permalink
fix: 论文引用格式
Browse files Browse the repository at this point in the history
  • Loading branch information
14790897 committed Feb 13, 2024
1 parent c1f201b commit b603365
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 15 deletions.
1 change: 0 additions & 1 deletion components/GetPubMed .tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ async function getPubMedPaperDetails(idList: IDList) {
}

let journalTitle = articleDetails.Journal.Title; // 提取出版者信息(杂志标题)
journalTitle += "[J]";
journalTitle += `, ${publishedDate}`;
if (articleDetails.Journal.JournalIssue.Volume) {
journalTitle += `, ${articleDetails.Journal.JournalIssue.Volume}`;
Expand Down
3 changes: 2 additions & 1 deletion components/QuillEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ const QEditor = ({ lng }) => {
year: entry.year,
author: entry.authors?.slice(0, 3).join(", "),
venue: entry.venue,
journalReference: formatJournalReference(entry),
journal: formatJournalReference(entry),
}));
dataString = rawData
.map((entry) => {
Expand Down Expand Up @@ -357,6 +357,7 @@ const QEditor = ({ lng }) => {
upsreamUrl,
systemPrompt
);
setUserInput("");
// 重新获取更新后的内容并更新 Redux store
const updatedContent = quill.root.innerHTML;
dispatch(setEditorContent(updatedContent));
Expand Down
30 changes: 18 additions & 12 deletions components/ReferenceList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,27 @@ function ReferenceList({ editor, lng }: ReferenceListProps) {
}
}, [references]);

function formatReference(reference) {
function formatReference(reference: Reference) {
if (reference.journal) {
return `${reference.journal}. `;
return `[J]. ${reference.journal}. `;
} else if (reference.journalReference) {
return `${reference.journalReference}`;
return `[J]. ${reference.journalReference}`;
} else {
return `${reference.venue}, ${reference.year}.`;
}
}

function getFullReference(reference: Reference) {
let fullReference = `${reference.author}. ${reference.title}`;
fullReference += formatReference(reference);
return fullReference;
}
function getAllFullReferences(references: Reference[]) {
return references
.map((reference, index) => {
return `[${index + 1}] ${getFullReference(reference)}`;
})
.join("\n");
}
return (
<div className=" mx-auto p-4">
{/* 引用列表显示区域 */}
Expand All @@ -116,8 +127,7 @@ function ReferenceList({ editor, lng }: ReferenceListProps) {
<li key={index} className="mb-3 p-2 border-b">
{/* 显示序号 */}
<span className="font-bold mr-2">[{index + 1}].</span>
{reference.author}. {reference.title}.{" "}
<span>{formatReference(reference)}</span>
{getFullReference(reference)}
{reference.url && (
<a
href={reference.url}
Expand All @@ -144,9 +154,7 @@ function ReferenceList({ editor, lng }: ReferenceListProps) {
</button>
<button
className="bg-gray-500 hover:bg-gray-700 text-white font-bold py-1 px-2 ml-2 rounded"
onClick={() =>
copyToClipboard(formatReferenceForCopy(reference))
}
onClick={() => copyToClipboard(getFullReference(reference))}
>
{t("复制")}
</button>
Expand Down Expand Up @@ -231,9 +239,7 @@ function ReferenceList({ editor, lng }: ReferenceListProps) {
<button
className="bg-gray-300 hover:bg-gray-400 text-black font-bold py-2 px-4 rounded "
type="button"
onClick={() =>
copyToClipboard(formatAllReferencesForCopy(references))
}
onClick={() => copyToClipboard(getAllFullReferences(references))}
>
{t("复制所有引用")}
</button>
Expand Down
1 change: 1 addition & 0 deletions utils/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export type Reference = {
url: string;
venue?: string;
journal?: JournalInfo;
journalReference?: string;
};

export interface IndexProps {
Expand Down
2 changes: 1 addition & 1 deletion utils/others/quillutils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ export function formatJournalReference(entry: any) {
}

// 基础引用格式:期刊名称和出版年份
let reference = `${entry.journal.name}[J], ${entry.year}`;
let reference = `${entry.journal.name}, ${entry.year}`;

// 如果有卷号,添加卷号信息
if (entry.journal.volume) {
Expand Down

0 comments on commit b603365

Please sign in to comment.