-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Copy citation file content, in APA and BibTex format, on repo home pa…
…ge (#19999) Add feature to easily copy CITATION.cff content in APA and BibTex format.
- Loading branch information
Showing
10 changed files
with
474 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<button class="ui basic citation button" id="citation-copy-apa" data-text=""> | ||
APA | ||
</button> | ||
<button class="ui basic citation button" id="citation-copy-bibtex" data-text=""> | ||
BibTeX | ||
</button> | ||
<!-- 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> | ||
<button class="ui basic icon button tooltip" id="citation-clipboard-btn" data-content="{{.locale.Tr "copy"}}" data-clipboard-text="" data-clipboard-target="#citation-copy-content"> | ||
{{svg "octicon-copy"}} | ||
</button> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<div class="ui tiny modal" id="cite-repo-modal"> | ||
<div class="header"> | ||
{{.locale.Tr "repo.cite_this_repo"}} | ||
</div> | ||
<div class="content"> | ||
<div class="ui stackable secondary menu mobile--margin-between-items mobile--no-negative-margins no-vertical-tabs"> | ||
<div class="fitted item"> | ||
<div class="ui action input" id="citation-panel"> | ||
{{template "repo/cite/cite_buttons" .}} | ||
<a id="goto-citation-btn" class="ui basic jump icon button tooltip" href="{{$.RepoLink}}/src/{{$.BranchName}}/CITATION.cff" data-position="top right" data-content="{{.locale.Tr "repo.find_file.go_to_file"}}"> | ||
{{svg "octicon-file-moved"}} | ||
</a> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
<div class="actions"> | ||
<div class="ui black deny button"> | ||
{{.locale.Tr "cancel"}} | ||
</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import $ from 'jquery'; | ||
|
||
const {pageData} = window.config; | ||
|
||
const initInputCitationValue = async ($citationCopyBibtex, $citationCopyApa) => { | ||
const [{Cite, plugins}] = await Promise.all([ | ||
import(/* webpackChunkName: "citation-js-core" */'@citation-js/core'), | ||
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-csl'), | ||
]); | ||
const {citationFileContent} = pageData; | ||
const config = plugins.config.get('@bibtex'); | ||
config.constants.fieldTypes.doi = ['field', 'literal']; | ||
config.constants.fieldTypes.version = ['field', 'literal']; | ||
const citationFormatter = new Cite(citationFileContent); | ||
const lang = document.documentElement.lang || 'en-US'; | ||
const apaOutput = citationFormatter.format('bibliography', {template: 'apa', lang}); | ||
const bibtexOutput = citationFormatter.format('bibtex', {lang}); | ||
$citationCopyBibtex.attr('data-text', bibtexOutput); | ||
$citationCopyApa.attr('data-text', apaOutput); | ||
}; | ||
|
||
export function initCitationFileCopyContent() { | ||
const defaultCitationFormat = 'apa'; // apa or bibtex | ||
|
||
if (!pageData.citationFileContent) return; | ||
|
||
const $citationCopyApa = $('#citation-copy-apa'); | ||
const $citationCopyBibtex = $('#citation-copy-bibtex'); | ||
const $inputContent = $('#citation-copy-content'); | ||
|
||
if ((!$citationCopyApa.length && !$citationCopyBibtex.length) || !$inputContent.length) return; | ||
const updateUi = () => { | ||
const isBibtex = (localStorage.getItem('citation-copy-format') || defaultCitationFormat) === 'bibtex'; | ||
const copyContent = (isBibtex ? $citationCopyBibtex : $citationCopyApa).attr('data-text'); | ||
|
||
$inputContent.val(copyContent); | ||
$citationCopyBibtex.toggleClass('primary', isBibtex); | ||
$citationCopyApa.toggleClass('primary', !isBibtex); | ||
}; | ||
initInputCitationValue($citationCopyApa, $citationCopyBibtex).then(updateUi); | ||
|
||
$citationCopyApa.on('click', () => { | ||
localStorage.setItem('citation-copy-format', 'apa'); | ||
updateUi(); | ||
}); | ||
$citationCopyBibtex.on('click', () => { | ||
localStorage.setItem('citation-copy-format', 'bibtex'); | ||
updateUi(); | ||
}); | ||
|
||
$inputContent.on('click', () => { | ||
$inputContent.select(); | ||
}); | ||
|
||
$('#cite-repo-button').on('click', () => { | ||
$('#cite-repo-modal').modal('show'); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters