Skip to content
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

Add BibTeX citation box (#1325) #3718

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
17 changes: 16 additions & 1 deletion 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 Expand Up @@ -772,7 +787,7 @@ figure .fig-desktop {
.index-box ul {
max-height: 0;
display: none;
border-top: 0 solid #fff;
border-top: 0 solid #ffffff;
transition: max-height 0.15s ease-out;
overflow: hidden;
}
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