-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
refactor: Jinja experiment for AffiliateLinks template #12776
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
base: master
Are you sure you want to change the base?
Changes from all commits
8261ef3
9559a8d
4cdaf21
01464bf
f02bc8c
03be76b
d12cb5c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| from functools import cache as functools_cache | ||
| from pathlib import Path | ||
|
|
||
|
|
||
| @functools_cache | ||
| def get_jinja_env(): | ||
| """Lazily initialize and return the Jinja2 environment (cached after first call). | ||
|
|
||
| Per Jinja docs, a single Environment instance should be reused to take | ||
| advantage of template compilation caching. | ||
| """ | ||
| from jinja2 import Environment, FileSystemLoader, StrictUndefined | ||
|
|
||
| from openlibrary.i18n import gettext as _ | ||
|
|
||
| env = Environment( | ||
| loader=FileSystemLoader(Path(__file__).resolve().parents[1] / "macros"), | ||
| autoescape=True, | ||
| undefined=StrictUndefined, | ||
| trim_blocks=True, | ||
| lstrip_blocks=True, | ||
| ) | ||
| env.globals["_"] = _ | ||
| return env |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| {% macro affiliate_link(store) %} | ||
| <li class="prices-{{ store.key }}"> | ||
|
Sanket17052006 marked this conversation as resolved.
Sanket17052006 marked this conversation as resolved.
Sanket17052006 marked this conversation as resolved.
Sanket17052006 marked this conversation as resolved.
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. WCAG 1.3.1:
DetailsList items ( |
||
| <a href="{{ store.link }}" | ||
| title="{{ _('Look for this edition for sale at %(store)s', store=store.name) }}" | ||
| data-ol-link-track="BuyLink|{{ store.analytics_key }}" | ||
| target="_blank" rel="noopener noreferrer">{{ store.name }}</a> | ||
| {% if store.price %} | ||
| <br> | ||
| <span name="price">{{ store.price }}{{ store.price_note }}</span> | ||
| {% endif %} | ||
| </li> | ||
| {% endmacro %} | ||
|
|
||
| <span class="affiliate-links-section"> | ||
| <ul class="buy-options-table"> | ||
|
Sanket17052006 marked this conversation as resolved.
Sanket17052006 marked this conversation as resolved.
Sanket17052006 marked this conversation as resolved.
Sanket17052006 marked this conversation as resolved.
Sanket17052006 marked this conversation as resolved.
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. WCAG 1.3.1:
DetailsScreen readers announce list structure ('list with 5 items') based on proper markup. Placing non- |
||
| {% for store in primary_stores %} | ||
| {{ affiliate_link(store) | safe }} | ||
| {% endfor %} | ||
| {% if more_stores %} | ||
| <li class="more"> | ||
| <details> | ||
| <summary>{{ _('More') }}</summary> | ||
| <ul> | ||
| {% for store in more_stores %} | ||
| {{ affiliate_link(store) | safe }} | ||
| {% endfor %} | ||
| </ul> | ||
| </details> | ||
| </li> | ||
| {% endif %} | ||
| </ul> | ||
| <small>{{ _('When you buy books using these links the Internet Archive may earn a <a class="nostyle" href="/help/faq/about#selling">small commission</a>.') | safe }}</small> | ||
| </span> | ||
Uh oh!
There was an error while loading. Please reload this page.