Skip to content
Merged
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
6 changes: 6 additions & 0 deletions assets/css/doors/glossary.css
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ main:lang(ar) .post-nav-next .term-en{text-align:left}
.glossary-letters{display:flex;flex-wrap:wrap;gap:4px;margin:14px 0 8px}
.glossary-letters a{display:inline-flex;align-items:center;justify-content:center;min-width:36px;height:36px;border-radius:var(--r-small);background:var(--surface);color:var(--ink);font:600 16px/1 var(--text);text-decoration:none}
.glossary-letters a:hover{background:var(--edu-bg)}
/* On phones each letter is a 44 px target (DESIGN.md §9). */
@media(max-width:760px){.glossary-letters a{min-width:44px;height:44px}}
.term-group{scroll-margin-top:16px}
.term-group h2{margin:28px 0 10px;font-size:28px;color:var(--edu)}
.term-group ul{display:grid;grid-template-columns:repeat(auto-fill,minmax(min(100%,300px),1fr));gap:12px;margin:0;padding:0;list-style:none}
Expand Down Expand Up @@ -99,8 +101,12 @@ main:lang(ar) .post-nav-next .term-en{text-align:left}
.glossary-search-row input{flex:1}
.glossary-clear{flex:none;padding:10px 16px;border:1.5px solid var(--ink);border-radius:999px;background:#fff;color:var(--ink);font:600 16px/1.2 var(--text);cursor:pointer}
.glossary-clear[hidden]{display:none}
/* A letter's heading lands below the sticky search and letters: site.js sets --glossary-tools to their height,
which grows when the letters wrap (34 on the Arabic hub). The fixed values are the fallback without JavaScript. */
.term-group{scroll-margin-top:200px}
@media(max-width:760px){.glossary-tools .glossary-find label{font-size:17px;margin-bottom:6px}.glossary-find{margin-top:10px}.term-group{scroll-margin-top:150px}}
.glossary-hub:has(.glossary-tools) .term-group{scroll-margin-top:calc(var(--glossary-tools,212px) + 12px)}
@media(max-width:760px){.glossary-hub:has(.glossary-tools) .term-group{scroll-margin-top:calc(var(--glossary-tools,160px) + 12px)}}
.glossary-language-select{display:none}
@media(max-width:760px){
.glossary-hub .glossary-languages{display:none}
Expand Down
25 changes: 20 additions & 5 deletions assets/js/doors/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -469,18 +469,33 @@ if (chatWidget) {

// Glossary pages: filter the list of terms, and show the current term inside its card.
const termFilter = document.getElementById('glossary-search');
// Arabic terms are written with their vowel marks, which visitors seldom type: both sides drop them (fathatan to sukun,
// and the dagger alef) and the tatweel, and an alef with a hamza, madda or wasla counts as a plain alef. The hamza on
// ئ and ؤ stays, so they remain apart from ي and و. A final ة counts as ه and ى as ي, as people often type them.
// NFC first, so a decomposed alef and hamza (pasted text) folds too.
const foldTerm = (text) => text.normalize('NFC').replace(/[أإآٱ]/g, 'ا').replace(/ة/g, 'ه').replace(/ى/g, 'ي')
.replace(/[\u064B-\u0652\u0670\u0640]/g, '').toLowerCase();
const termGrid = document.querySelector('.term-grid');
if (termFilter && termGrid) {
// The search and letters stay at the top; a letter's heading must land below them, whatever their height.
const tools = document.querySelector('.glossary-tools');
// A page opened at a letter (#letter-…) scrolled before the toolbar was measured, so it scrolls there once more.
let aligned = false;
if (tools) new ResizeObserver(() => {
document.documentElement.style.setProperty('--glossary-tools', `${tools.offsetHeight}px`);
if (!aligned && location.hash.startsWith('#letter-')) document.getElementById(location.hash.slice(1))?.scrollIntoView();
aligned = true;
}).observe(tools);
// The glossary hub: match on the term's name, hide letters left empty, and say when nothing matches.
const terms = [...termGrid.querySelectorAll('li[data-term]')];
const groups = [...termGrid.querySelectorAll('.term-group')];
const none = document.querySelector('.glossary-none');
termFilter.addEventListener('input', () => {
const query = termFilter.value.trim().toLowerCase();
const query = foldTerm(termFilter.value.trim());
// Names first; when no name matches, the definitions (a related term may be named only inside them).
const byName = terms.some((term) => term.dataset.term.includes(query));
const byName = terms.some((term) => foldTerm(term.dataset.term).includes(query));
terms.forEach((term) => {
term.hidden = !(byName ? term.dataset.term : term.textContent.toLowerCase()).includes(query);
term.hidden = !foldTerm(byName ? term.dataset.term : term.textContent).includes(query);
});
groups.forEach((group) => { group.hidden = !group.querySelector('li:not([hidden])'); });
none.hidden = groups.some((group) => !group.hidden);
Expand Down Expand Up @@ -551,8 +566,8 @@ if (termFilter && termGrid) {
termFilter.after(status, clearTerms);
clearTerms.addEventListener('click', () => { termFilter.value = ''; termFilter.dispatchEvent(new Event('input')); termFilter.focus(); });
termFilter.addEventListener('input', () => {
const query = termFilter.value.toLowerCase();
terms.forEach((term) => { term.hidden = !term.textContent.toLowerCase().includes(query); });
const query = foldTerm(termFilter.value);
terms.forEach((term) => { term.hidden = !foldTerm(term.textContent).includes(query); });
const shown = terms.filter((term) => !term.hidden).length;
status.textContent = !query ? '' : shown ? `${shown} ${shown === 1 ? 'term' : 'terms'}` : 'No matching terms.';
clearTerms.hidden = !query;
Expand Down
15 changes: 13 additions & 2 deletions layouts/glossary/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
{{ range $pages }}
{{ $first := upper (substr (strings.TrimLeft "\"“”'*[(_ " (.Params.sort_key | default .Title)) 0 1) }}
{{ if eq $lang "german" }}{{ $first = $first | replaceRE "Ä" "A" | replaceRE "Ö" "O" | replaceRE "Ü" "U" }}{{ end }}
{{/* Arabic files أ, إ, آ and ٱ under ا, as its dictionaries do; apart, they also shared one anchor, as urlize drops the hamza. */}}
{{ if eq $lang "arabic" }}{{ $first = $first | replaceRE "[أإآٱ]" "ا" }}{{ end }}
{{ if not (findRE `^\p{L}$` $first) }}{{ $first = "#" }}{{ end }}
{{ if ne $first $current }}
{{ if $items }}{{ $groups = $groups | append (dict "letter" $current "pages" $items) }}{{ end }}
Expand All @@ -25,6 +27,15 @@
{{ $items = $items | append . }}
{{ end }}
{{ if $items }}{{ $groups = $groups | append (dict "letter" $current "pages" $items) }}{{ end }}
{{/* Each letter's anchor in plain ASCII: urlize percent-encodes an Arabic or Chinese letter, and the link then encodes
it a second time, so link and section did not match and site.js could not mark or dim those letters. */}}
{{ $withIds := slice }}
{{ range $i, $g := $groups }}
{{ $id := printf "letter-n%d" $i }}
{{ if eq $g.letter "#" }}{{ $id = "letter-other" }}{{ else if findRE `^[A-Za-z]$` $g.letter }}{{ $id = printf "letter-%s" (lower $g.letter) }}{{ end }}
{{ $withIds = $withIds | append (merge $g (dict "id" $id)) }}
{{ end }}
{{ $groups = $withIds }}
<div class="wrap">
<div class="article-layout article-layout-single article-layout-wide glossary-layout glossary-hub">
<article class="reading">
Expand Down Expand Up @@ -58,12 +69,12 @@ <h1>{{ .Title }}</h1>
<p class="glossary-count" aria-live="polite"></p>
</div>
<nav class="glossary-letters" aria-label="{{ $l.letters }}">
{{ range $groups }}<a href="#letter-{{ .letter | urlize | default "other" }}">{{ .letter }}</a>{{ end }}
{{ range $groups }}<a href="#{{ .id }}">{{ .letter }}</a>{{ end }}
</nav>
</div>
<div class="term-grid">
{{ range $groups }}
<section class="term-group" id="letter-{{ .letter | urlize | default "other" }}">
<section class="term-group" id="{{ .id }}">
<h2>{{ .letter }}</h2>
<ul>
{{ range .pages }}
Expand Down
Loading