Skip to content

Commit cca5d80

Browse files
committed
Add BibTeX citation box (#1325)
Implemented a citation box in BibTeX format as per the discussion in issue #1325. Details: #1325
1 parent 90e7e8a commit cca5d80

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

src/static/css/page.css

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@
292292
}
293293

294294
.authors,
295+
.citation-box h2,
295296
.authors h2,
296297
.chapter-links,
297298
.chapter-links h2,
@@ -382,6 +383,20 @@
382383
margin-right: 0.25rem;
383384
}
384385

386+
.citation-box pre {
387+
padding: 16px;
388+
border: 1px solid #e0e0e0;
389+
border-radius: 4px;
390+
background-color: #ffffff;
391+
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
392+
margin-bottom: 20px;
393+
font-family: monospace;
394+
background-color: #f9f9f9;
395+
overflow-x: auto;
396+
white-space: pre-wrap; /* Allow wrapping of long lines */
397+
margin: 0;
398+
}
399+
385400
#chapter-navigation {
386401
padding: 16px 36px 50px 36px;
387402
padding: 1rem 2.25rem 3.125rem 2.25rem;

src/templates/base/base_chapter.html

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,31 @@ <h2 id="authors">
318318
</ul>
319319
{% endmacro %}
320320

321+
{% macro render_bibtex() %}
322+
<h2 id="cite">
323+
<a href="#cite" class="anchor-link">BibTeX</a>
324+
</h2>
325+
<pre id="bibtex-citation">
326+
@inbook{WebAlmanac.{{ year }}.{{ metadata.get('title').replace(' ', '') }},
327+
author = "{% for author in metadata.get('authors') -%}
328+
{%- set authordata = config.contributors.get(author, None) -%}
329+
{%- if authordata %}
330+
{%- set full_name = authordata.name.split(' ') -%}
331+
{{ full_name[-1] }}, {{ full_name[0] }}{% if full_name|length > 2 %} {{ full_name[1:-1]|join(' ') }}{% endif %}{% if not loop.last %} and {% endif %}
332+
{%- else %}
333+
{%- set full_name = author.split(' ') -%}
334+
{{ full_name[-1] }}, {{ full_name[0] }}{% if full_name|length > 2 %} {{ full_name[1:-1]|join(' ') }}{% endif %}{% if not loop.last %} and {% endif %}
335+
{%- endif %}
336+
{%- endfor %}",
337+
title = "{{ metadata.get('title') }}",
338+
booktitle = "The {{ year }} Web Almanac",
339+
chapter = {{ chapter_config.chapter_number }},
340+
publisher = "HTTP Archive",
341+
year = "{{ year }}",
342+
url = "https://almanac.httparchive.org/en/{{ year }}/{{ metadata.get('chapter') }}"
343+
}</pre>
344+
{% endmacro %}
345+
321346
{% macro render_prevnext() %}
322347
{% if prev_chapter %}
323348
{% if chapter_lang_exists(lang, year, prev_chapter['slug']) %}
@@ -423,6 +448,8 @@ <h1 class="title title-lg">
423448
{% endif %}
424449
<section class="authors">
425450
{{ render_authors() }}
451+
</section><section class="citation-box">
452+
{{ render_bibtex() }}
426453
</section>
427454
<div id="cta-container" class="invisible">
428455
{% if metadata.get('discuss') %}

0 commit comments

Comments
 (0)