Skip to content

Commit

Permalink
Add BibTeX citation box (#1325)
Browse files Browse the repository at this point in the history
Implemented a citation box in BibTeX format as per the discussion in issue #1325. Details: #1325
  • Loading branch information
nrllh committed Aug 9, 2024
1 parent 90e7e8a commit cca5d80
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/static/css/page.css
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@
}

.authors,
.citation-box h2,
.authors h2,
.chapter-links,
.chapter-links h2,
Expand Down Expand Up @@ -382,6 +383,20 @@
margin-right: 0.25rem;
}

.citation-box pre {
padding: 16px;
border: 1px solid #e0e0e0;
border-radius: 4px;
background-color: #ffffff;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
margin-bottom: 20px;
font-family: monospace;
background-color: #f9f9f9;
overflow-x: auto;
white-space: pre-wrap; /* Allow wrapping of long lines */
margin: 0;
}

#chapter-navigation {
padding: 16px 36px 50px 36px;
padding: 1rem 2.25rem 3.125rem 2.25rem;
Expand Down
27 changes: 27 additions & 0 deletions src/templates/base/base_chapter.html
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,31 @@ <h2 id="authors">
</ul>
{% endmacro %}

{% macro render_bibtex() %}
<h2 id="cite">
<a href="#cite" class="anchor-link">BibTeX</a>
</h2>
<pre id="bibtex-citation">
@inbook{WebAlmanac.{{ year }}.{{ metadata.get('title').replace(' ', '') }},
author = "{% for author in metadata.get('authors') -%}
{%- set authordata = config.contributors.get(author, None) -%}
{%- if authordata %}
{%- set full_name = authordata.name.split(' ') -%}
{{ full_name[-1] }}, {{ full_name[0] }}{% if full_name|length > 2 %} {{ full_name[1:-1]|join(' ') }}{% endif %}{% if not loop.last %} and {% endif %}
{%- else %}
{%- set full_name = author.split(' ') -%}
{{ full_name[-1] }}, {{ full_name[0] }}{% if full_name|length > 2 %} {{ full_name[1:-1]|join(' ') }}{% endif %}{% if not loop.last %} and {% endif %}
{%- endif %}
{%- endfor %}",
title = "{{ metadata.get('title') }}",
booktitle = "The {{ year }} Web Almanac",
chapter = {{ chapter_config.chapter_number }},
publisher = "HTTP Archive",
year = "{{ year }}",
url = "https://almanac.httparchive.org/en/{{ year }}/{{ metadata.get('chapter') }}"
}</pre>
{% endmacro %}

{% macro render_prevnext() %}
{% if prev_chapter %}
{% if chapter_lang_exists(lang, year, prev_chapter['slug']) %}
Expand Down Expand Up @@ -423,6 +448,8 @@ <h1 class="title title-lg">
{% endif %}
<section class="authors">
{{ render_authors() }}
</section><section class="citation-box">
{{ render_bibtex() }}
</section>
<div id="cta-container" class="invisible">
{% if metadata.get('discuss') %}
Expand Down

0 comments on commit cca5d80

Please sign in to comment.