Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions _plugins/bibtex_tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,23 @@ def initialize(tag_name, image_url, tokens)
@image_url = image_url.strip
end

# Generate a unique ID for this entry
unique_id = "bibtex-" + Random.hex(4)

def render(context)
text = super
site = context.registers[:site]
converter = site.find_converter_instance(Jekyll::Converters::Markdown)

# Wrap the BibTeX code in triple backticks and specify the language
bibtex_code = "```bibtex\n#{text.strip}\n```"

# Convert the BibTeX block using the Markdown converter
processed_bibtex = converter.convert(bibtex_code)

# Generate a unique ID for this entry
unique_id = "bibtex-" + Random.hex(4)

# Create the HTML structure
html = <<~HTML
<div class="bibtex-entry">
Expand All @@ -24,6 +36,10 @@ def render(context)
<div class="bibtex-buttons">
<a href="#" class="btn btn--bibtex btn--journal">Journal</a>
<a href="#" class="btn btn--bibtex btn--arxiv">arXiv</a>
<button class="btn btn--bibtex btn--bib" data-target="##{unique_id}">BibTeX</button>
</div>
<div id="#{unique_id}" class="bibtex-raw" style="display: none;">
#{processed_bibtex}
</div>
<div class="bibtex-data">
#{text}
Expand Down
2 changes: 1 addition & 1 deletion _sass/minimal-mistakes/_buttons.scss
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
(linkedin, $linkedin-color),
(journal, $facebook-color),
(arxiv, $danger-color),
(pdf, $lighter-gray);
(bib, $info-color);

@each $buttoncolor, $color in $buttoncolors {
&--#{$buttoncolor} {
Expand Down
15 changes: 14 additions & 1 deletion assets/css/bibtex.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
display: flex;
gap: 20px;
margin-bottom: 30px;
max-width: calc(100% - 60px);
width: calc(100% - 60px);
}

.bibtex-image {
Expand Down Expand Up @@ -45,3 +45,16 @@
display: flex;
gap: 10px;
}

.bibtex-raw {
font-size: 0.9em;
width: 600px;
}

.bibtex-raw pre {
margin: 0;
}

.btn--bib {
cursor: pointer;
}
15 changes: 14 additions & 1 deletion assets/js/bibtex-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ function formatCitation(bibData) {
if (fields.journal) {
journalElement.innerHTML = `${fields.journal}, ${fields.volume} (${fields.number}) ${fields.pages} (${fields.year})`;
} else if (fields.eprint && fields.archiveprefix === "arXiv") {
journalElement.innerHTML = `arXiv:${fields.eprint} [${fields.primaryclass}] (${fields.year})`;
journalElement.innerHTML = `arXiv:${fields.eprint} [${fields.primaryclass}] (${fields.year}), <em>${fields.misc}</em>`;
}

return {
Expand Down Expand Up @@ -208,4 +208,17 @@ document.addEventListener('DOMContentLoaded', function() {
bibtexData.style.display = 'none';
}
});

document.querySelectorAll('.btn--bib').forEach(button => {
button.addEventListener('click', function() {
const targetId = this.getAttribute('data-target');
const bibtexContent = document.querySelector(targetId);

if (bibtexContent) {
const isVisible = bibtexContent.style.display !== 'none';
bibtexContent.style.display = isVisible ? 'none' : 'block';
this.textContent = isVisible ? 'BibTeX' : 'Hide';
}
});
});
});
Loading