Merge pull request 'Remove APA as cite format' (#4595) from beowulf/remove-apa-cite-format into forgejo
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/4595 Reviewed-by: Gusted <gusted@noreply.codeberg.org>
This commit is contained in:
commit
75af19a497
5 changed files with 8 additions and 65 deletions
23
package-lock.json
generated
23
package-lock.json
generated
|
@ -7,7 +7,6 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@citation-js/core": "0.7.11",
|
"@citation-js/core": "0.7.11",
|
||||||
"@citation-js/plugin-bibtex": "0.7.11",
|
"@citation-js/plugin-bibtex": "0.7.11",
|
||||||
"@citation-js/plugin-csl": "0.7.11",
|
|
||||||
"@citation-js/plugin-software-formats": "0.6.1",
|
"@citation-js/plugin-software-formats": "0.6.1",
|
||||||
"@github/markdown-toolbar-element": "2.2.3",
|
"@github/markdown-toolbar-element": "2.2.3",
|
||||||
"@github/relative-time-element": "4.4.2",
|
"@github/relative-time-element": "4.4.2",
|
||||||
|
@ -375,22 +374,6 @@
|
||||||
"node": ">=14.0.0"
|
"node": ">=14.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@citation-js/plugin-csl": {
|
|
||||||
"version": "0.7.11",
|
|
||||||
"resolved": "https://registry.npmjs.org/@citation-js/plugin-csl/-/plugin-csl-0.7.11.tgz",
|
|
||||||
"integrity": "sha512-4OGZ9wHZDfpgiPU2cOXWGuKt7P+ndGWAeLG95nOG+DXe5U+f9EEZTXfaM4C99x8Ri+g6JklR96A3kuYZxYLllg==",
|
|
||||||
"license": "MIT",
|
|
||||||
"dependencies": {
|
|
||||||
"@citation-js/date": "^0.5.0",
|
|
||||||
"citeproc": "^2.4.6"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">=16.0.0"
|
|
||||||
},
|
|
||||||
"peerDependencies": {
|
|
||||||
"@citation-js/core": "^0.7.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/@citation-js/plugin-github": {
|
"node_modules/@citation-js/plugin-github": {
|
||||||
"version": "0.6.1",
|
"version": "0.6.1",
|
||||||
"resolved": "https://registry.npmjs.org/@citation-js/plugin-github/-/plugin-github-0.6.1.tgz",
|
"resolved": "https://registry.npmjs.org/@citation-js/plugin-github/-/plugin-github-0.6.1.tgz",
|
||||||
|
@ -4150,12 +4133,6 @@
|
||||||
"node": ">=8"
|
"node": ">=8"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/citeproc": {
|
|
||||||
"version": "2.4.63",
|
|
||||||
"resolved": "https://registry.npmjs.org/citeproc/-/citeproc-2.4.63.tgz",
|
|
||||||
"integrity": "sha512-68F95Bp4UbgZU/DBUGQn0qV3HDZLCdI9+Bb2ByrTaNJDL5VEm9LqaiNaxljsvoaExSLEXe1/r6n2Z06SCzW3/Q==",
|
|
||||||
"license": "CPAL-1.0 OR AGPL-1.0"
|
|
||||||
},
|
|
||||||
"node_modules/clean-regexp": {
|
"node_modules/clean-regexp": {
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/clean-regexp/-/clean-regexp-1.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/clean-regexp/-/clean-regexp-1.0.0.tgz",
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@citation-js/core": "0.7.11",
|
"@citation-js/core": "0.7.11",
|
||||||
"@citation-js/plugin-bibtex": "0.7.11",
|
"@citation-js/plugin-bibtex": "0.7.11",
|
||||||
"@citation-js/plugin-csl": "0.7.11",
|
|
||||||
"@citation-js/plugin-software-formats": "0.6.1",
|
"@citation-js/plugin-software-formats": "0.6.1",
|
||||||
"@github/markdown-toolbar-element": "2.2.3",
|
"@github/markdown-toolbar-element": "2.2.3",
|
||||||
"@github/relative-time-element": "4.4.2",
|
"@github/relative-time-element": "4.4.2",
|
||||||
|
|
|
@ -1,9 +1,6 @@
|
||||||
<button class="ui citation button" id="citation-copy-apa" data-text="">
|
<span class="ui citation label primary" id="citation-copy-bibtex" data-text="">
|
||||||
APA
|
|
||||||
</button>
|
|
||||||
<button class="ui citation button" id="citation-copy-bibtex" data-text="">
|
|
||||||
BibTeX
|
BibTeX
|
||||||
</button>
|
</span>
|
||||||
<!-- the value will be updated by initCitationFileCopyContent, the code below is used to avoid UI flicking -->
|
<!-- the value will be updated by initCitationFileCopyContent, the code below is used to avoid UI flicking -->
|
||||||
<input id="citation-copy-content" value="" size="1" readonly>
|
<input id="citation-copy-content" value="" size="1" readonly>
|
||||||
<button class="ui icon button" id="citation-clipboard-btn" data-tooltip-content="{{ctx.Locale.Tr "copy"}}" data-clipboard-target="#citation-copy-content">
|
<button class="ui icon button" id="citation-clipboard-btn" data-tooltip-content="{{ctx.Locale.Tr "copy"}}" data-clipboard-target="#citation-copy-content">
|
||||||
|
|
|
@ -2068,11 +2068,6 @@ td .commit-summary {
|
||||||
line-height: 1.4;
|
line-height: 1.4;
|
||||||
}
|
}
|
||||||
|
|
||||||
#cite-repo-modal #citation-panel .citation.button {
|
|
||||||
font-size: 13px;
|
|
||||||
padding: 7.5px 5px;
|
|
||||||
}
|
|
||||||
|
|
||||||
#cite-repo-modal #citation-panel #citation-copy-content {
|
#cite-repo-modal #citation-panel #citation-copy-content {
|
||||||
border-radius: 0;
|
border-radius: 0;
|
||||||
padding: 5px 10px;
|
padding: 5px 10px;
|
||||||
|
@ -2081,8 +2076,9 @@ td .commit-summary {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#cite-repo-modal #citation-panel #citation-copy-apa,
|
|
||||||
#cite-repo-modal #citation-panel #citation-copy-bibtex {
|
#cite-repo-modal #citation-panel #citation-copy-bibtex {
|
||||||
|
font-size: 13px;
|
||||||
|
padding: 7.5px 5px;
|
||||||
border-right: none;
|
border-right: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,12 +3,11 @@ import {getCurrentLocale} from '../utils.js';
|
||||||
|
|
||||||
const {pageData} = window.config;
|
const {pageData} = window.config;
|
||||||
|
|
||||||
async function initInputCitationValue(citationCopyApa, citationCopyBibtex) {
|
async function initInputCitationValue(inputContent) {
|
||||||
const [{Cite, plugins}] = await Promise.all([
|
const [{Cite, plugins}] = await Promise.all([
|
||||||
import(/* webpackChunkName: "citation-js-core" */'@citation-js/core'),
|
import(/* webpackChunkName: "citation-js-core" */'@citation-js/core'),
|
||||||
import(/* webpackChunkName: "citation-js-formats" */'@citation-js/plugin-software-formats'),
|
import(/* webpackChunkName: "citation-js-formats" */'@citation-js/plugin-software-formats'),
|
||||||
import(/* webpackChunkName: "citation-js-bibtex" */'@citation-js/plugin-bibtex'),
|
import(/* webpackChunkName: "citation-js-bibtex" */'@citation-js/plugin-bibtex'),
|
||||||
import(/* webpackChunkName: "citation-js-csl" */'@citation-js/plugin-csl'),
|
|
||||||
]);
|
]);
|
||||||
const {citationFileContent} = pageData;
|
const {citationFileContent} = pageData;
|
||||||
const config = plugins.config.get('@bibtex');
|
const config = plugins.config.get('@bibtex');
|
||||||
|
@ -16,30 +15,16 @@ async function initInputCitationValue(citationCopyApa, citationCopyBibtex) {
|
||||||
config.constants.fieldTypes.version = ['field', 'literal'];
|
config.constants.fieldTypes.version = ['field', 'literal'];
|
||||||
const citationFormatter = new Cite(citationFileContent);
|
const citationFormatter = new Cite(citationFileContent);
|
||||||
const lang = getCurrentLocale() || 'en-US';
|
const lang = getCurrentLocale() || 'en-US';
|
||||||
const apaOutput = citationFormatter.format('bibliography', {template: 'apa', lang});
|
|
||||||
const bibtexOutput = citationFormatter.format('bibtex', {lang});
|
const bibtexOutput = citationFormatter.format('bibtex', {lang});
|
||||||
citationCopyBibtex.setAttribute('data-text', bibtexOutput);
|
inputContent.value = bibtexOutput;
|
||||||
citationCopyApa.setAttribute('data-text', apaOutput);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function initCitationFileCopyContent() {
|
export async function initCitationFileCopyContent() {
|
||||||
const defaultCitationFormat = 'apa'; // apa or bibtex
|
|
||||||
|
|
||||||
if (!pageData.citationFileContent) return;
|
if (!pageData.citationFileContent) return;
|
||||||
|
|
||||||
const citationCopyApa = document.getElementById('citation-copy-apa');
|
|
||||||
const citationCopyBibtex = document.getElementById('citation-copy-bibtex');
|
|
||||||
const inputContent = document.getElementById('citation-copy-content');
|
const inputContent = document.getElementById('citation-copy-content');
|
||||||
|
|
||||||
if ((!citationCopyApa && !citationCopyBibtex) || !inputContent) return;
|
if (!inputContent) return;
|
||||||
|
|
||||||
const updateUi = () => {
|
|
||||||
const isBibtex = (localStorage.getItem('citation-copy-format') || defaultCitationFormat) === 'bibtex';
|
|
||||||
const copyContent = (isBibtex ? citationCopyBibtex : citationCopyApa).getAttribute('data-text');
|
|
||||||
inputContent.value = copyContent;
|
|
||||||
citationCopyBibtex.classList.toggle('primary', isBibtex);
|
|
||||||
citationCopyApa.classList.toggle('primary', !isBibtex);
|
|
||||||
};
|
|
||||||
|
|
||||||
document.getElementById('cite-repo-button')?.addEventListener('click', async (e) => {
|
document.getElementById('cite-repo-button')?.addEventListener('click', async (e) => {
|
||||||
const dropdownBtn = e.target.closest('.ui.dropdown.button');
|
const dropdownBtn = e.target.closest('.ui.dropdown.button');
|
||||||
|
@ -47,22 +32,11 @@ export async function initCitationFileCopyContent() {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
try {
|
try {
|
||||||
await initInputCitationValue(citationCopyApa, citationCopyBibtex);
|
await initInputCitationValue(inputContent);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(`initCitationFileCopyContent error: ${e}`, e);
|
console.error(`initCitationFileCopyContent error: ${e}`, e);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
updateUi();
|
|
||||||
|
|
||||||
citationCopyApa.addEventListener('click', () => {
|
|
||||||
localStorage.setItem('citation-copy-format', 'apa');
|
|
||||||
updateUi();
|
|
||||||
});
|
|
||||||
|
|
||||||
citationCopyBibtex.addEventListener('click', () => {
|
|
||||||
localStorage.setItem('citation-copy-format', 'bibtex');
|
|
||||||
updateUi();
|
|
||||||
});
|
|
||||||
|
|
||||||
inputContent.addEventListener('click', () => {
|
inputContent.addEventListener('click', () => {
|
||||||
inputContent.select();
|
inputContent.select();
|
||||||
|
|
Loading…
Reference in a new issue