Skip to content

Commit

Permalink
Merge pull request #88 from w3c/perf-sitemaps
Browse files Browse the repository at this point in the history
Update translations sitemaps for better performances
  • Loading branch information
remibetin authored May 2, 2024
2 parents 84c8c82 + 20a7443 commit b521afb
Show file tree
Hide file tree
Showing 3 changed files with 278 additions and 79 deletions.
45 changes: 0 additions & 45 deletions _includes/t-github-issue.html

This file was deleted.

71 changes: 37 additions & 34 deletions _includes/t-status.html
Original file line number Diff line number Diff line change
@@ -1,39 +1,42 @@
{% assign original=alldocs | where_exp:"item", "item.lang == 'en' or item.lang == nil" | where_exp:"item", "item.ref == include.page.url or item.url == include.page.url" | first %}
{% assign t=alldocs | where_exp:"item", "item.lang == page.tlang and item.ref == include.page.url" | first %}
{%- capture page_title -%}
{%- if t != nil -%}
<a href="{{ t.permalink | relative_url }}"> {{ t.title }} ({{ original.title }})
{%- elsif t == nil and original.permalink != nil -%}
<a href="{{ original.permalink | relative_url }}">{{ original.title }}
{%- elsif t == nil and original.permalink == nil and include.page.name.en != nil -%}
<a href="{{ include.page.url | relative_url }}">{{ include.page.name.en }}
{% assign versions=alldocs | where_exp:"item", "item.ref == include.page.url or item.url == include.page.url" %}
{% assign original=versions | where_exp:"item", "item.lang == 'en' or item.lang == nil" | first %}
{% assign translation=versions | where_exp:"item", "item.lang == page.tlang" | first %}

{%- capture original-title -%}
{%- if original.permalink != nil -%}
<p><a href="{{ original.permalink | relative_url }}">{{ original.title }}</a></p>
{%- elsif original.permalink == nil and include.page.name.en != nil -%}
<p><a href="{{ include.page.url | relative_url }}">{{ include.page.name.en }}</a></p>
{%- else -%}
<a href="{{ include.page.url | relative_url }}">{{ include.page.name }}
<p><a href="{{ include.page.url | relative_url }}">{{ include.page.name }}</a></p>
{%- endif -%}
</a>
{%- endcapture -%}
{% capture t-date %}{{t.last_updated | date: '%s' | plus: 0 }}{% endcapture %}
{% capture en-date %}{{original.last_updated | date: '%s' | plus: 0 }}{% endcapture %}
{%- capture t_status -%}
{%- if t == nil -%}none
{%- elsif t.size != 0 and t-date < en-date -%}outdated
{%- elsif t.size != 0 and t-date >= en-date -%}uptodate

{% capture translation-date %}{{ translation.last_updated | date: '%s' | plus: 0 }}{% endcapture %}
{% capture original-date %}{{ original.last_updated | date: '%s' | plus: 0 }}{% endcapture %}
{%- capture t-status -%}
{%- if translation == nil -%}none
{%- elsif translation.size != 0 and translation-date < original-date -%}outdated
{%- elsif translation.size != 0 and translation-date >= original-date -%}uptodate
{%- endif -%}
{%- endcapture -%}
{% include box.html type="start" title=page_title h=include.h %}
{%- case t_status -%}
{%- when "none" -%}
{%- capture issue_body_new | newline_to_br -%}
{%- include t-github-issue.html status="new" tname=tlangname page=original -%}
{%- endcapture -%}
<p>{% include_cached icon.html name="ex-circle" %} No translation available</p>
<p><a href="https://github.com/w3c/wai-translations/issues/new?title=[{{ tlangname }}]+{{original.title | url_encode}}&body={{issue_body_new | url_encode}}">Volunteer to translate this page</a></p>
{%- when "outdated" -%}
{%- capture issue_body_update | newline_to_br -%}
{%- include t-github-issue.html status="update" tname=tlangname page=t -%}
{%- endcapture -%}
<p><mark>{% include_cached icon.html name="warning" %} Translation needs update</mark><p>
<p><a href="https://github.com/w3c/wai-translations/issues/new?title=[{{ tlangname }}]+{{original.title | url_encode}}&body={{issue_body_update | url_encode}}">Volunteer to update the translation</a></p>
{%- when "uptodate" -%}
<p>{% include_cached icon.html name="check-circle" %} Up-to-date</p>
{%- endcase -%}

<tr>
<th>{{ original-title }}</th>
<td>
{%- case t-status -%}
{%- when "none" -%}
<p>{% include_cached icon.html name="ex-circle" %} No translation</p>
{%- capture github-file-path -%}{% include_cached github-file-path.html p=original %}{%- endcapture -%}
<p><a class="button button-secondary" href="https://github.com/remibetin/wai-translations/issues/new?template=new-translation.yml&title=[{{ tlangname }}]+{{original.title | url_encode}}&url={{original.permalink | absolute_url | url_encode }}&github-link={{ github-file-path }}"><span>Volunteer to translate this page</span></a></p>
{%- when "outdated" -%}
<p>{% include_cached icon.html name="warning" %} Translation needs update<p>
<p><mark><a href="{{ translation.permalink | relative_url }}" lang="{{ tlang }}"> {{ translation.title }}</a></mark></p>
{%- capture github-file-path -%}{% include_cached github-file-path.html p=translation %}{%- endcapture -%}
<p><a class="button button-secondary" href="https://github.com/remibetin/wai-translations/issues/new?template=update-translation.yml&title=[{{ tlangname }}]+{{original.title | url_encode}}&url={{translation.permalink | absolute_url | url_encode }}&github-link={{ github-file-path }}"><span>Volunteer to update the translation</span></a></p>
{%- when "uptodate" -%}
<p>{% include_cached icon.html name="check-circle" %} Up-to-date</p>
<p><a href="{{ translation.permalink | relative_url }}" lang="{{ tlang }}"> {{ translation.title }}</a></p>
{%- endcase -%}
</td>
</tr>
241 changes: 241 additions & 0 deletions _layouts/translation-sitemap.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,241 @@
{%- assign pagelang = 'en' -%}
{%- if page.lang -%}
{%- assign pagelang = page.lang -%}
{%- endif -%}
{%- if pagelang == 'en' -%}
{%- assign enpage = page -%}
{%- else -%}
{%- assign enpage=site.documents | where:"ref", page.ref | where: "lang", "en" | first -%}
{%- unless enpage.ref -%}
{%- assign enpage=site.pages | where:"ref", page.ref | where: "lang", "en" | first -%}
{%- endunless -%}
{%- endif -%}
{%- assign englishpageurl = enpage.url %}
{%- assign translations=site.documents | where:"ref", page.ref | where_exp:"item", "item.lang != 'en'" | sort: 'lang' -%}
{%- unless translations[0].ref -%}
{% assign translations=site.pages | where:"ref", page.ref | where_exp:"item", "item.lang != 'en'" | sort: 'lang' %}
{%- endunless -%}
<!DOCTYPE html>
<html class="no-js" lang="{% if page.lang %}{{page.lang}}{% else %}en{% endif %}" dir="{% if site.data.lang[pagelang].rtl %}rtl{% else %}ltr{% endif %}" prefix="og: http://ogp.me/ns#">
{%- assign timestamp = site.time | date: '%s%N' -%}
{%- assign timestamp = '?' | append: timestamp -%}
{%- include_cached head.html type="start" timestamp=timestamp -%}
{%- if site.data.lang[pagelang].rtl -%}
<title> W3C | {{ site.title | escape }} | {{ page.title | escape }} {%if page.doc-note-type == "archived" %}[{% include t.html t="Archived" %}]{% endif%}{%if page.doc-note-type == "draft" %}[{% include t.html t="Draft" %}]{% endif%}</title>
{%- else -%}
<title>{%if page.doc-note-type == "archived" %}[{% include t.html t="Archived" %}]{% endif%}{%if page.doc-note-type == "draft" %}[{% include t.html t="Draft" %}]{% endif%} {{ page.title | escape }} | {{ site.title | escape }} | W3C</title>
{%- endif -%}
{%- if page.external_css %}<link rel="stylesheet" href="{{ page.external_css | relative_url | append: timestamp }}">{% endif -%}
{%- if page.ext_css %}<link rel="stylesheet" href="{{ page.ext_css | prepend: '/css/' | prepend: page.collection | prepend: '/' | relative_url | append: timestamp }}">{% endif -%}
{%- if page.inline_css %}<style>{{ page.inline_css }}</style>{% endif -%}
{%- capture seo -%}
{%- seo title=false -%}
{%- endcapture -%}
{{- seo | replace: '<meta name="twitter:card" content="summary" />', '<meta name="twitter:card" content="summary_large_image" />' -}}
{%- unless page.image -%}{%- if site.twitter.image -%}{% assign twimage = site.twitter.image -%}{%- else -%}{% assign twimage = '/assets/images/social-sharing-default.jpg' -%}{%- endif -%}
<meta name="twitter:image" property="og:image" content="{{ twimage | relative_url | prepend: site.url }}">
{%- endunless -%}
{% include_cached head.html type="end" %}
<body id="top" class="page-{{page.title | slugify}} {% include_cached body-class.html collection=page.collection doc-note-type=page.doc-note-type pageclass=page.class%}"{%if page.footnotestitle %} data-footnotestitle="{{page.footnotestitle}}"{% endif %}>
{% include header.html translations=translations %}
<div class="default-grid with-gap{% unless page.noleftcol %} leftcol{% endunless %}">

{% if page.sidebaricon %}
<div class="sidenav">
{% include_cached icon.html name=page.sidebaricon class="sidebaricon" %}
</div>
{% else %}
{% unless page.sidebar == false %}
{% include secondarynav.html parent=page.parent %}
{% endunless %}
{% endif %}

<main id="main"{% if page.lang %} lang="{{page.lang}}"{% endif %}>

{% comment %}

Header will be displayed in three ways, depending on which frontmatter was provided:

- with 'in [Resource]' under the h1 (if page.resource.ref is provided)
- with 'in [Resource X], [Resource Y]' inside the h1 (if page.parent_in_h1 is provided)
- just the title (if neither are provided)

{% endcomment %}

{% if page.resource.ref %}
<header class="in-resource">
<h1>
{% if page.title_icon %}
<svg class="icon-in-title" aria-hidden="true"><use xlink:href="{{page.title_icon | relative_url}}"></use></svg>
{% endif %}
{% if page.title_image %}
<img src="{{page.title_image | relative_url }}" alt="" class="title-image right" style="height: 2em;">
{% endif %}
{% if page.title_html %}
{{ page.title_html }}
{% else %}
{{ page.title | xml_escape }}
{% endif %}</h1>
{%- if page.resource.ref -%}{%- unless page.ref == page.resource.ref -%}
<p>{% include t.html t="in" %} {% include link.html to=page.resource.ref %}</p>
{%- endunless -%}{%- endif -%}
</header>
{% elsif page.parent_in_h1 %}
<header class="in-resource">
<h1>{% if page.title_icon %}
<svg class="icon-in-title" aria-hidden="true">
<use xlink:href="{{page.title_icon | relative_url}}"></use>
</svg> {% endif %}
{% if page.title_image %}
<img src="{{page.title_image | relative_url }}" alt="" class="title-image right" style="height: 2em;">
{% endif %}
{% if page.title_html %}
{{ page.title_html }}
{% else %}
{{ page.title | xml_escape }}
{% endif %}
<span class="in-resource-sub">
{% include t.html t="in" %}{{ ' ' }}
{%- for link in page.parent_in_h1 -%}
{%- unless forloop.first == true -%},{{ ' ' }}{%- endunless -%}
{%- if link.ref -%}{%- unless page.ref == link.ref -%}
{%- if link.name == "title" -%}
{% include link.html to=link.ref %}
{%- elsif link.name == "nav_title" -%}
{% include link.html to=link.ref usenavtitle="true" %}
{%- elsif link.name == "title_html" -%}
{% include link.html to=link.ref usetitlehtml="true" %}
{%- else -%}
{% include link.html to=link.ref text=link.name %}
{%- endif -%}
{%- endunless -%}{%- endif -%}
{%- endfor -%}
</span>
</h1>
</header>
{% else %}
<header>
<h1>
{% if page.title_html %}
{{ page.title_html }}
{% else %}
{{ page.title | xml_escape }}
{% endif %}
</h1>
{%- if page.resource.ref -%}{%- unless page.ref == page.resource.ref -%}
<p>{% include t.html t="in" %} {% include link.html to=page.resource.ref %}</p>
{%- endunless -%}{%- endif -%}
{%- if page.collection == "posts" -%}
<section class="meta">
<p><strong>Date:</strong> {{ page.date | date: "%d %B %Y" }}</p>
</section>
{%- endif -%}
</header>
{% endif %}

{%- include doc-note-msg.html -%}

<!-- Start Translations sitemaps -->
{% assign tlangname=site.data.lang[page.tlang].name %}
{% assign alldocs=site.documents | concat: site.pages %}

{% include box.html type="start" h="2" title="Summary" class="full" %}

<p>This page lists the status of {{ tlangname }} translations, for WAI resources for which we welcome translations.</p>

<p>Learn how to use this translation sitemap in <a href="{{ '/about/translating/sitemaps/' | relative_url }}#how-to-use">Translations Sitemaps</a> page.</p>

{% include box.html type="end" %}

{% include_cached excol.html type="all" %}

{% include_cached excol.html type="start" %}

<h2>Priorities Status</h2>

{% include excol.html type="middle" %}

{% if site.data.translations-priorities %}
<table class="quiet translations-table">
<thead>
<tr>
<th scope="col">WAI Resource</th>
<th scope="col">Translation Status</th>
</tr>
</thead>
<tbody>
{%- for prio in site.data.translations-priorities -%}
{%- include t-status.html page=prio -%}
{%- for priosub in prio.pages -%}
{%- include t-status.html page=priosub -%}
{%- endfor -%}
{%- endfor -%}
</tbody>
</table>
{% endif %}

{% include_cached excol.html type="end" %}

<h2>Sitemap</h2>

{% assign sections=site.data.navigation | where_exp:"item", "item.mainnav != false and item.hide != true and item.translate == true" -%}
{%- for section in sections -%}
{% include excol.html type="start" %}
<h3>
{%- if section.name.en -%}
{{ section.name.en }}
{%- else -%}
{{ section.name }}
{%- endif -%}
</h3>
{% include excol.html type="middle" %}
<table class="quiet translations-table">
<thead>
<tr>
<th scope="col">WAI Resource</th>
<th scope="col">Translation Status</th>
</tr>
</thead>
<tbody>
{%- assign pages=section.pages | where_exp:"item", "item.mainnav != false and item.hide != true" -%}
{%- for p in pages -%}
{% if p.translate == true %}
{%- include t-status.html page=p -%}
{% endif %}
{%- assign subpages=p.pages | where_exp:"item", "item.mainnav != false and item.hide != true" -%}
{%- for subpage in subpages -%}
{% if subpage.translate == true %}
{%- include t-status.html page=subpage -%}
{% endif %}
{%- assign subsubpages=subpage.pages | where_exp:"item", "item.mainnav != false and item.hide != true" -%}
{%- for subsubpage in subsubpages -%}
{% if subsubpage.translate == true %}
{%- include t-status.html page=subsubpage -%}
{% endif %}
{%- endfor -%}
{%- endfor -%}
{%- endfor -%}
</tbody>
</table>
{% include excol.html type="end" %}
{% endfor %}
<!-- End Translations sitemaps -->

{%- if page.navigation -%}
{%- include prevnext-navigation.html -%}
{%- else -%}
{%- if page.order -%}
{%- include prevnext-order.html -%}
{%- endif -%}
{%- endif -%}

{% include feedback-box.html %}

{% include_cached backtotop.html lang=page.lang %}
</main>
</div>

{% include footer.html lang=pagelang %}

</body>
</html>

0 comments on commit b521afb

Please sign in to comment.