-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex-list.qmd
More file actions
65 lines (52 loc) · 1.85 KB
/
index-list.qmd
File metadata and controls
65 lines (52 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
---
title: "Index"
---
<!-- This is the start of the index for the web version.
We will likely need to manually construct much of the index.
* _support/scripts/collect-index.lua generates the list of index entries.
* _index_entries.txt is now grouped with each chapter and are in a bunch of sub-folders.
-->
```{python}
#| echo: false
#| output: asis
# Read the index entries
entries = {}
try:
with open('_index_entries.txt', 'r') as f:
for line in f:
parts = line.strip().split('|')
if len(parts) >= 3:
term = parts[0]
file_path = parts[1]
title = parts[2]
if term not in entries:
entries[term] = []
# Avoid duplicates
entry = {"file": file_path, "title": title}
if entry not in entries[term]:
entries[term].append(entry)
except FileNotFoundError:
print("No index entries found.")
# Sort terms alphabetically
sorted_terms = sorted(entries.keys())
# Group by first letter
current_letter = None
for term in sorted_terms:
first_letter = term[0].upper()
# Add letter heading when changing letter
if first_letter != current_letter:
current_letter = first_letter
print(f"\n## {current_letter}\n")
# Format term (replace hyphens with commas)
formatted_term = term.replace('-', ', ')
# Create links to pages
page_links = []
for entry in entries[term]:
file_path = entry.get("file", "")
page_title = entry.get("title", file_path)
if file_path and page_title:
# Create link to the page
page_links.append(f"[{page_title}]({file_path})")
# Output the index entry
print(f"**{formatted_term}** — {', '.join(set(page_links))}\n")
```