Template
1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo synced 2024-11-25 11:16:11 +01:00

Don't show unnecessary citation JS error on UI (#28433) (#28437)

Backport #28433 by wxiaoguang

Fix #28226

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
(cherry picked from commit 5e2bae7716)
This commit is contained in:
Giteabot 2023-12-12 21:14:04 +08:00 committed by Earl Warren
parent 6b48228500
commit bd264e6aed
No known key found for this signature in database
GPG key ID: 0579CB2928A78A00

View file

@ -2,7 +2,7 @@ import $ from 'jquery';
const {pageData} = window.config;
const initInputCitationValue = async ($citationCopyApa, $citationCopyBibtex) => {
async function initInputCitationValue($citationCopyApa, $citationCopyBibtex) {
const [{Cite, plugins}] = await Promise.all([
import(/* webpackChunkName: "citation-js-core" */'@citation-js/core'),
import(/* webpackChunkName: "citation-js-formats" */'@citation-js/plugin-software-formats'),
@ -19,9 +19,9 @@ const initInputCitationValue = async ($citationCopyApa, $citationCopyBibtex) =>
const bibtexOutput = citationFormatter.format('bibtex', {lang});
$citationCopyBibtex.attr('data-text', bibtexOutput);
$citationCopyApa.attr('data-text', apaOutput);
};
}
export function initCitationFileCopyContent() {
export async function initCitationFileCopyContent() {
const defaultCitationFormat = 'apa'; // apa or bibtex
if (!pageData.citationFileContent) return;
@ -39,7 +39,14 @@ export function initCitationFileCopyContent() {
$citationCopyBibtex.toggleClass('primary', isBibtex);
$citationCopyApa.toggleClass('primary', !isBibtex);
};
initInputCitationValue($citationCopyApa, $citationCopyBibtex).then(updateUi);
try {
await initInputCitationValue($citationCopyApa, $citationCopyBibtex);
} catch (e) {
console.error(`initCitationFileCopyContent error: ${e}`, e);
return;
}
updateUi();
$citationCopyApa.on('click', () => {
localStorage.setItem('citation-copy-format', 'apa');