enhance(citation): render citations server-side (#39373)

Replace citation-js with a Go port of ruby-cff, which GitHub uses for
"Cite this repository", rendering APA and BibTeX server-side and
dropping about 770KB of JS. Output matches GitHub on 1568 of 1571
real-world files, the rest are improvements over GitHub.

- `CITATION.cff` wins over `CITATION.bib`, matched case-insensitively
and through symlinks
- `CITATION.bib` is offered as-is, without APA

Signed-off-by: silverwind <me@silverwind.io>
This commit is contained in:
silverwind authored and GitHub committed 2026-10-03 02:28:34 +00:00
1 parent fb067e1115
commit 2baa5a16f8
15 files changed
+704 -361

No files matched your search

-11
View File
@@ -1,11 +0,0 @@
<button type="button" class="ui citation button" id="citation-copy-apa" data-text="">
APA
</button>
<button type="button" class="ui 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 type="button" class="ui icon button" id="citation-clipboard-btn" data-tooltip-content="{{ctx.Locale.Tr "copy"}}" data-clipboard-target="#citation-copy-content">
{{svg "octicon-copy"}}
</button>
+14 -3
View File
@@ -4,9 +4,20 @@
</div>
<div class="content">
<div class="ui stackable secondary menu">
<div class="ui action input" id="citation-panel">
{{template "repo/cite/cite_buttons" .}}
<a id="goto-citation-btn" class="ui basic jump icon button" href="{{$.RepoLink}}/src/{{$.BranchName}}/CITATION.cff" data-tooltip-content="{{ctx.Locale.Tr "repo.find_file.go_to_file"}}">
<div class="ui action input tw-flex tw-w-full" data-global-init="initRepoCitationPanel">
{{if .CitationAPA}}
<button type="button" class="ui citation button citation-apa" data-text="{{.CitationAPA}}">
APA
</button>
{{end}}
<button type="button" class="ui citation button citation-bibtex" data-text="{{.CitationBibTeX}}">
BibTeX
</button>
<input value="" size="1" readonly autofocus>
<button type="button" class="ui icon button citation-copy" data-tooltip-content="{{ctx.Locale.Tr "copy"}}">
{{svg "octicon-copy"}}
</button>
<a class="ui basic jump icon button" href="{{$.RepoLink}}/src/{{$.RefTypeNameSubURL}}/{{PathEscapeSegments $.CitationFileName}}" data-tooltip-content="{{ctx.Locale.Tr "repo.find_file.go_to_file"}}">
{{svg "octicon-file-moved"}}
</a>
</div>
+2 -2
View File
@@ -58,9 +58,9 @@
</a>
{{end}}
{{if .CitiationExist}}
{{if .CitationFileName}}
{{template "repo/cite/cite_modal" .}}
<a class="flex-text-block muted" id="cite-repo-button">
<a class="flex-text-block muted show-modal" href="#" data-modal="#cite-repo-modal">
{{svg "octicon-cross-reference"}} {{ctx.Locale.Tr "repo.cite_this_repo"}}
</a>
{{end}}