-
-
Notifications
You must be signed in to change notification settings - Fork 9
Bs7 citations #305
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
stumbo
wants to merge
5
commits into
main
Choose a base branch
from
bs7_citations
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Bs7 citations #305
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
298633d
Initial attempt to build citation modal dialog box.
stumbo 17ca929
Update Citation modal to include both rendered text and html
stumbo ab75d60
Fix reference to prettier js files in script.
stumbo 882630d
Convert 'View on Zotero' and 'Citation' into buttons.
stumbo 8b5d28a
Move Zotero group id from hardcoded to a site parameter
stumbo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -53,6 +53,7 @@ <h1>{{ .Title }}</h1> | |
| {{ end }} | ||
| <br> | ||
| </p> | ||
|
|
||
| <p> | ||
| <strong>Abstract</strong> | ||
| <br> | ||
|
|
@@ -209,13 +210,215 @@ <h1>{{ .Title }}</h1> | |
| {{ end }} | ||
| </p> | ||
| <p> | ||
| {{- if .Params.zotero_url }} | ||
| <a href="{{ .Params.zotero_url | safeURL }}" target="_blank" rel="noopener noreferrer">View on Zotero</a> | ||
| {{- end -}} | ||
| {{- if .Params.zotero_url }} | ||
| <a class="btn btn-primary btn-sm" | ||
| href="{{ .Params.zotero_url | safeURL }}" | ||
| target="_blank" rel="noopener noreferrer">View on Zotero</a> | ||
| {{- end -}} | ||
|
|
||
| <!-- Citation --> | ||
| {{/* Build Zotero API params (group id + item key + style) */}} | ||
| {{ $gid := site.Params.zotero_group_id }} | ||
|
|
||
| {{ $key := .File.TranslationBaseName }} | ||
|
|
||
| {{ $style := or site.Params.zotero.style "apa" }} | ||
|
|
||
| {{ if and $gid $key }} | ||
| <button type="button" id="citeBtn" | ||
| class="btn btn-primary btn-sm" | ||
| data-gid="{{ $gid }}" | ||
| data-key="{{ $key }}" | ||
| data-style="{{ $style }}"> | ||
| Citation | ||
| </button> | ||
| {{ end }} | ||
| </p> | ||
|
|
||
| <div class="summary"> | ||
| {{ .Content }} | ||
| </div> | ||
| </article> | ||
| <!-- Citation modal --> | ||
| <div id="citationModal" class="citation-modal" hidden> | ||
| <div class="citation-dialog"> | ||
| <div class="citation-header"> | ||
| <strong>Citation</strong> | ||
| <button type="button" class="citation-close" aria-label="Close">×</button> | ||
| </div> | ||
|
|
||
| <!-- Tabs --> | ||
| <div class="citation-tabs" role="tablist" aria-label="Citation views"> | ||
| <button type="button" class="tab-btn is-active" data-tab="formatted" role="tab" aria-selected="true" aria-controls="tab-formatted">Formatted</button> | ||
| <button type="button" class="tab-btn" data-tab="raw" role="tab" aria-selected="false" aria-controls="tab-raw">HTML</button> | ||
| </div> | ||
|
|
||
| <div class="citation-body"> | ||
| <!-- Formatted view --> | ||
| <div id="tab-formatted" class="tab-panel is-active" role="tabpanel" aria-labelledby="tabbtn-formatted"> | ||
| <div id="citationContent">Loading…</div> | ||
| </div> | ||
|
|
||
| <!-- Raw HTML view --> | ||
| <div id="tab-raw" class="tab-panel" role="tabpanel" aria-labelledby="tabbtn-raw"> | ||
| <pre class="codebox"><code id="citationRaw" class="language-html"></code></pre> | ||
| </div> | ||
| </div> | ||
|
|
||
| <div class="citation-actions"> | ||
| <button type="button" id="copyCitation">Copy Text</button> | ||
| <button type="button" id="copyCitationHtml">Copy HTML</button> | ||
| <button type="button" class="citation-close">Close</button> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This "Close" is a larger font, and no border, compared to the two buttons adjacent. |
||
| </div> | ||
| </div> | ||
| <div class="citation-backdrop"></div> | ||
| </div> | ||
|
|
||
|
|
||
| <style> | ||
| .citation-modal[hidden] { display: none; } | ||
| .citation-modal { position: fixed; inset: 0; z-index: 1050; } | ||
| .citation-dialog { | ||
| position: absolute; top: 10%; left: 50%; transform: translateX(-50%); | ||
| max-width: 720px; width: calc(100% - 2rem); | ||
| background: #fff; border-radius: 6px; box-shadow: 0 10px 30px rgba(0,0,0,.2); | ||
| overflow: hidden; | ||
| } | ||
| .citation-header { display:flex; justify-content:space-between; align-items:center; padding:.75rem 1rem; border-bottom:1px solid #eee; } | ||
| .citation-close { background:none; border:0; font-size:1.25rem; line-height:1; cursor:pointer; } | ||
| .citation-tabs { display:flex; gap:.25rem; padding:.5rem 1rem; border-bottom:1px solid #eee; } | ||
| .tab-btn { | ||
| border: 1px solid #ddd; background:#f8f9fa; border-radius:4px; padding:.35rem .6rem; cursor:pointer; | ||
| } | ||
| .tab-btn.is-active { background:#fff; border-color:#bbb; } | ||
| .citation-body { padding:1rem; max-height:50vh; overflow:auto; } | ||
| #citationContent { font-size:1rem; line-height:1.4; } | ||
| .codebox { | ||
| background:#f6f8fa; border:1px solid #e1e4e8; border-radius:6px; | ||
| padding:.75rem; font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; | ||
| font-size:.9rem; line-height:1.4; white-space:pre-wrap; word-break:break-word; | ||
| } | ||
| .tab-panel { display:none; } | ||
| .tab-panel.is-active { display:block; } | ||
| .citation-actions { display:flex; gap:.5rem; justify-content:flex-end; padding:.75rem 1rem; border-top:1px solid #eee; } | ||
| </style> | ||
|
|
||
| <script src="{{ "js/vendor/prettier/standalone.js" | relURL }}" defer></script> | ||
| <script src="{{ "js/vendor/prettier/plugins/html.js" | relURL }}" defer></script> | ||
|
|
||
| <script> | ||
| (function () { | ||
| const modal = document.getElementById('citationModal'); | ||
| const contentBox = document.getElementById('citationContent'); | ||
| const rawBox = document.getElementById('citationRaw'); | ||
|
|
||
| function openModal() { modal.hidden = false; } | ||
| function closeModal() { modal.hidden = true; } | ||
|
|
||
| function setActiveTab(name) { | ||
| document.querySelectorAll('.tab-btn').forEach(btn => { | ||
| const isActive = btn.dataset.tab === name; | ||
| btn.classList.toggle('is-active', isActive); | ||
| btn.setAttribute('aria-selected', isActive ? 'true' : 'false'); | ||
| }); | ||
| document.querySelectorAll('.tab-panel').forEach(panel => { | ||
| const isActive = panel.id === ('tab-' + name); | ||
| panel.classList.toggle('is-active', isActive); | ||
| }); | ||
| } | ||
|
|
||
| function copyTextToClipboard(text, button) { | ||
| const done = () => { | ||
| if (button) { | ||
| const original = button.textContent; | ||
| button.textContent = 'Copied'; | ||
| setTimeout(() => (button.textContent = original), 1200); | ||
| } | ||
| }; | ||
| if (navigator.clipboard && window.isSecureContext) { | ||
| navigator.clipboard.writeText(text).then(done).catch(done); | ||
| } else { | ||
| const ta = document.createElement('textarea'); | ||
| ta.value = text; document.body.appendChild(ta); | ||
| ta.select(); try { document.execCommand('copy'); } catch(e) {} | ||
| document.body.removeChild(ta); done(); | ||
| } | ||
| } | ||
|
|
||
| document.addEventListener('click', function (e) { | ||
| // Open + fetch | ||
| if (e.target.matches('#citeBtn')) { | ||
| e.preventDefault(); | ||
| const btn = e.target; | ||
| const gid = btn.dataset.gid; | ||
| const key = btn.dataset.key; | ||
| const style = btn.dataset.style || 'apa'; | ||
| // Use Zotero API; format=bib returns HTML bibliography item(s) | ||
| const url = `https://api.zotero.org/groups/${encodeURIComponent(gid)}/items/${encodeURIComponent(key)}?format=bib&style=${encodeURIComponent(style)}&linkwrap=1`; | ||
|
|
||
| contentBox.textContent = 'Loading…'; | ||
| rawBox.textContent = ''; | ||
| setActiveTab('formatted'); | ||
| openModal(); | ||
|
|
||
| fetch(url, { headers: { 'Accept': 'text/html' }}) | ||
| .then(r => { | ||
| if (!r.ok) throw new Error(`HTTP ${r.status}`); | ||
| return r.text(); | ||
| }) | ||
| .then(html => { | ||
| contentBox.innerHTML = html; | ||
| try { | ||
| const formatted = window.prettier.format(html, { parser: "html", plugins: window.prettierPlugins, tabWidth: 2 }); | ||
| // prettier.format may return a string or a Promise depending on plugin loading; normalize to a Promise | ||
| return Promise.resolve(formatted).then(pretty => { | ||
| rawBox.textContent = pretty; | ||
| return html; | ||
| }); | ||
| } catch (err) { | ||
| // synchronous error formatting | ||
| rawBox.textContent = String(err); | ||
| return html; | ||
| } | ||
| }) | ||
| .catch(err => { | ||
| const msg = `Failed to load citation (${err})`; | ||
| contentBox.textContent = msg; | ||
| rawBox.textContent = msg; | ||
| }); | ||
| } | ||
|
|
||
| // Close | ||
| if (e.target.matches('.citation-close')) { | ||
| e.preventDefault(); | ||
| closeModal(); | ||
| } | ||
|
|
||
| // Copy buttons | ||
| if (e.target.matches('#copyCitation')) { | ||
| e.preventDefault(); | ||
| copyTextToClipboard(contentBox.innerText.trim(), e.target); | ||
| } | ||
| if (e.target.matches('#copyCitationHtml')) { | ||
| e.preventDefault(); | ||
| copyTextToClipboard(rawBox.textContent.trim(), e.target); | ||
| } | ||
|
|
||
| // Tabs | ||
| if (e.target.matches('.tab-btn')) { | ||
| e.preventDefault(); | ||
| setActiveTab(e.target.dataset.tab); | ||
| } | ||
| }); | ||
|
|
||
| // Close when clicking backdrop or pressing Escape | ||
| modal.addEventListener('click', function (e) { | ||
| if (e.target.classList.contains('citation-backdrop')) closeModal(); | ||
| }); | ||
| document.addEventListener('keydown', function (e) { | ||
| if (e.key === 'Escape') closeModal(); | ||
| }); | ||
| })(); | ||
| </script> | ||
|
|
||
| {{ end }} | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The lines that are only Hugo operations should have {{- & -}} delimiters so whitespace between them is stripped from the output. (Generally, no functional effect, but helps with readability if looking at "page source" in the browser. Also, smaller pages.