summaryrefslogtreecommitdiffstats
path: root/web_src
diff options
context:
space:
mode:
authorGiteabot <teabot@gitea.io>2023-12-12 21:14:04 +0800
committerGitHub <noreply@github.com>2023-12-12 21:14:04 +0800
commit5e2bae7716bf1991ff5ac95788cf3acb2ae59f71 (patch)
tree808891ddda4f96f0e22e7789633395502d9bd791 /web_src
parent96d3fcf179d4eea98f62d380e04f246ff65694d7 (diff)
downloadgitea-5e2bae7716bf1991ff5ac95788cf3acb2ae59f71.tar.gz
gitea-5e2bae7716bf1991ff5ac95788cf3acb2ae59f71.zip
Don't show unnecessary citation JS error on UI (#28433) (#28437)
Backport #28433 by wxiaoguang Fix #28226 Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Diffstat (limited to 'web_src')
-rw-r--r--web_src/js/features/citation.js15
1 files changed, 11 insertions, 4 deletions
diff --git a/web_src/js/features/citation.js b/web_src/js/features/citation.js
index 65666864f6..61f378f0f2 100644
--- a/web_src/js/features/citation.js
+++ b/web_src/js/features/citation.js
@@ -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');