From 1a1bb4bea637065a54846a959d1d4dfbfe6bc38d Mon Sep 17 00:00:00 2001
From: tamnd <1218621+tamnd@users.noreply.github.com>
Date: Tue, 17 Nov 2026 10:56:10 +0700
Subject: [PATCH] Add the Areas tab in place of Subjects
The Areas page lists the area topics, each with its sub-area topics in the order of the area body and the count of the ideas in each. A node page shows its area and sub-area in the crumbs. The MSC subject pages stay, with a link in the footer.
---
site/areas.go | 144 +++++++++++++++++++++++++++++++++++++
site/areas_test.go | 31 ++++++++
site/assets/site.css | 8 +++
site/pages.go | 1 +
site/site.go | 2 +-
site/templates/areas.html | 21 ++++++
site/templates/layout.html | 5 +-
site/templates/node.html | 2 +-
8 files changed, 210 insertions(+), 4 deletions(-)
create mode 100644 site/areas.go
create mode 100644 site/areas_test.go
create mode 100644 site/templates/areas.html
diff --git a/site/areas.go b/site/areas.go
new file mode 100644
index 0000000..bd29243
--- /dev/null
+++ b/site/areas.go
@@ -0,0 +1,144 @@
+package site
+
+import (
+ "regexp"
+ "slices"
+ "strings"
+)
+
+// The areas of the site come from the topic nodes. An area is a topic with no parent topic and at least one child topic. Its sub-areas are its child topics, in the order of the links in the body of the area, and then by name.
+
+// areaView is one area on the Areas page.
+type areaView struct {
+ Topic *nodeView
+ Subs []*subAreaView
+ Count int // the nodes of the area and of its sub-areas, the topics not counted
+}
+
+type subAreaView struct {
+ Topic *nodeView
+ Count int // the nodes in the sub-area, the topics not counted
+}
+
+type areasData struct {
+ Areas []*areaView
+ Others []*nodeView // the topics that are neither an area nor a sub-area
+}
+
+// bodyTag matches the target of a wiki link in a body, [[text|TAG]].
+var bodyTag = regexp.MustCompile(`\[\[[^\]|]*\|([0-9A-Z]{6}|[0-9A-Z]{10})\]\]`)
+
+// parentTopics returns the topics that the node is a part of, the topics that exist only.
+func (b *builder) parentTopics(v *nodeView) []*nodeView {
+ var out []*nodeView
+ for _, r := range refsOf(v.Meta["topics"]) {
+ if t, ok := b.nodes[r.Text]; ok && t.Kind == "topic" && t != v {
+ out = append(out, t)
+ }
+ }
+ return out
+}
+
+// areas returns the areas of the site, the areas with the most specific MSC code first, and the other topics.
+func (b *builder) topicAreas() areasData {
+ children := map[*nodeView][]*nodeView{}
+ members := map[*nodeView]int{}
+ var roots []*nodeView
+ for _, v := range b.order {
+ if v.Retired != nil {
+ continue
+ }
+ ps := b.parentTopics(v)
+ if v.Kind == "topic" {
+ if len(ps) == 0 {
+ roots = append(roots, v)
+ }
+ for _, p := range ps {
+ children[p] = append(children[p], v)
+ }
+ continue
+ }
+ for _, p := range ps {
+ members[p]++
+ }
+ }
+ var d areasData
+ for _, r := range roots {
+ subs := children[r]
+ if len(subs) == 0 {
+ d.Others = append(d.Others, r)
+ continue
+ }
+ pos := map[string]int{}
+ for i, m := range bodyTag.FindAllStringSubmatch(r.Body, -1) {
+ if _, ok := pos[m[1]]; !ok {
+ pos[m[1]] = i
+ }
+ }
+ slices.SortStableFunc(subs, func(x, y *nodeView) int {
+ px, okx := pos[x.Tag]
+ py, oky := pos[y.Tag]
+ switch {
+ case okx && oky:
+ return px - py
+ case okx:
+ return -1
+ case oky:
+ return 1
+ }
+ return strings.Compare(x.Name, y.Name)
+ })
+ a := &areaView{Topic: r, Count: members[r]}
+ for _, s := range subs {
+ a.Subs = append(a.Subs, &subAreaView{Topic: s, Count: members[s]})
+ a.Count += members[s]
+ }
+ d.Areas = append(d.Areas, a)
+ }
+ slices.SortStableFunc(d.Areas, func(x, y *areaView) int { return compareMSC(x.Topic, y.Topic) })
+ slices.SortStableFunc(d.Others, compareMSC)
+ return d
+}
+
+// compareMSC orders two topics by their first MSC code, and then by name.
+func compareMSC(x, y *nodeView) int {
+ first := func(v *nodeView) string {
+ if len(v.MSC) == 0 {
+ return "~"
+ }
+ return v.MSC[0]
+ }
+ if c := strings.Compare(first(x), first(y)); c != 0 {
+ return c
+ }
+ return strings.Compare(x.Name, y.Name)
+}
+
+// TopicPath returns the topics above a node, the area first: the first topic of the node and the first topic of that topic, and so on.
+func (b *builder) TopicPath(v *nodeView) []*nodeView {
+ var path []*nodeView
+ seen := map[*nodeView]bool{v: true}
+ for cur := v; ; {
+ ps := b.parentTopics(cur)
+ if len(ps) == 0 || seen[ps[0]] {
+ break
+ }
+ cur = ps[0]
+ seen[cur] = true
+ path = append(path, cur)
+ }
+ slices.Reverse(path)
+ return path
+}
+
+func (b *builder) writeAreas() error {
+ return b.writePage("areas", "areas", b.topicAreas(), page{Title: "Areas", Description: "The areas of mathematics in Math 2.0, each with its sub-areas.", Section: "areas"})
+}
+
+// Code returns the top level MSC class of the area, for its colour, or "".
+func (a *areaView) Code() string {
+ if len(a.Topic.MSC) == 0 || len(a.Topic.MSC[0]) < 2 {
+ return ""
+ }
+ return a.Topic.MSC[0][:2]
+}
diff --git a/site/areas_test.go b/site/areas_test.go
new file mode 100644
index 0000000..64e895a
--- /dev/null
+++ b/site/areas_test.go
@@ -0,0 +1,31 @@
+package site
+
+import (
+ "strings"
+ "testing"
+)
+
+func TestAreas(t *testing.T) {
+ content := newContent(t)
+ writeFile(t, content, "nodes/AAA/AAAAAA.md", "---\ntag: AAAAAA\nkind: topic\nname: Group theory\nmsc: [\"20-XX\"]\n---\n## Summary\n\nGroup theory is the study of groups.\n\n## Remarks\n\n1. [[Subgroups|BBBBBB]]\n1. [[Groups|CCCCCC]]\n")
+ writeFile(t, content, "nodes/BBB/BBBBBB.md", "---\ntag: BBBBBB\nkind: topic\nname: Subgroups\nmsc: [\"20A05\"]\ntopics: [AAAAAA]\n---\n## Summary\n\nSubgroups.\n")
+ writeFile(t, content, "nodes/CCC/CCCCCC.md", "---\ntag: CCCCCC\nkind: topic\nname: Groups\nmsc: [\"20A05\"]\ntopics: [AAAAAA]\n---\n## Summary\n\nGroups.\n")
+ writeFile(t, content, "nodes/DDD/DDDDDD.md", "---\ntag: DDDDDD\nkind: topic\nname: Proof methods\nmsc: [\"00A35\"]\n---\n## Summary\n\nMethods.\n")
+ writeFile(t, content, "nodes/EEE/EEEEEE.md", "---\ntag: EEEEEE\nkind: concept\nname: Subgroup\nmsc: [\"20A05\"]\ntopics: [BBBBBB]\n---\n## Summary\n\nA subgroup.\n")
+ out := buildSite(t, content, "")
+
+ page := readFile(t, out, "areas/index.html")
+ sub, grp := strings.Index(page, ">Subgroups"), strings.Index(page, ">Groups")
+ if sub < 0 || grp < 0 || sub > grp {
+ t.Error("the sub-areas are not on the Areas page in the order of the body of the area")
+ }
+ for _, want := range []string{"2 sub-areas, 1 idea", "Other topics", ">Proof methods", `href="/math2/areas/" aria-current="page">Areas`} {
+ if !strings.Contains(page, want) {
+ t.Errorf("the Areas page does not contain %s", want)
+ }
+ }
+ node := readNode(t, out, "EEEEEE")
+ if !strings.Contains(node, `Areas Group theory Subgroups`) {
+ t.Error("the crumbs of a node do not show its area and sub-area")
+ }
+}
diff --git a/site/assets/site.css b/site/assets/site.css
index 2b9d04a..8cf0bcf 100644
--- a/site/assets/site.css
+++ b/site/assets/site.css
@@ -484,3 +484,11 @@ ul.bare, .bare > ul { list-style: none; padding-left: 0; }
.step-course { font-weight: 600; }
.step-prev { margin-left: auto; }
.button { display: inline-block; padding: 0.5rem 1rem; background: hsl(var(--hue, 250) 60% 28%); color: #fff; text-decoration: none; font-weight: 600; border-radius: 4px; }
+.area-section { margin-top: 2.2rem; scroll-margin-top: 4rem; }
+.area-section h2 a { text-decoration: none; }
+.area-section h2 a:hover { text-decoration: underline; }
+.area-lead { color: var(--muted); max-width: 46rem; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; line-clamp: 3; overflow: hidden; }
+.sub-areas { columns: 2 22rem; column-gap: 2.5rem; padding-left: 1.6rem; margin: 0.6rem 0 0; }
+.sub-areas li { break-inside: avoid; padding: 0.22rem 0; }
+.sub-areas a { text-decoration: none; }
+.sub-areas a:hover { text-decoration: underline; }
diff --git a/site/pages.go b/site/pages.go
index 01a3bc9..443e5d6 100644
--- a/site/pages.go
+++ b/site/pages.go
@@ -31,6 +31,7 @@ func parseTemplates(b *builder) (*template.Template, error) {
"hue": hue,
"steps": b.Steps,
"area": b.Area,
+ "topicPath": b.TopicPath,
"skeleton": func(code string) *learnPath { return b.skeletons[code] },
"top": func(code string) string {
if len(code) < 2 {
diff --git a/site/site.go b/site/site.go
index 99e5709..c91b3ec 100644
--- a/site/site.go
+++ b/site/site.go
@@ -238,7 +238,7 @@ func Build(opt Options) error {
b.spool = &shardSpool{dir: filepath.Join(opt.Out, spoolDir)}
steps = append(steps, b.writeSocialPacks)
}
- steps = append(steps, b.writeNodes, b.writeLists, b.writeLearn, b.writeExplore, b.writeSpec, b.writeDocs, b.writeHome, b.writeReviewers, b.writeProjects, b.writeAgents, b.writeInventory, b.writeResources, b.writeLevels, b.writeWikipedia, b.writeFeeds)
+ steps = append(steps, b.writeNodes, b.writeLists, b.writeAreas, b.writeLearn, b.writeExplore, b.writeSpec, b.writeDocs, b.writeHome, b.writeReviewers, b.writeProjects, b.writeAgents, b.writeInventory, b.writeResources, b.writeLevels, b.writeWikipedia, b.writeFeeds)
if opt.Cloudflare {
steps = append(steps, b.writeWorker)
}
diff --git a/site/templates/areas.html b/site/templates/areas.html
new file mode 100644
index 0000000..514d085
--- /dev/null
+++ b/site/templates/areas.html
@@ -0,0 +1,21 @@
+{{define "areas"}}
+ Pick an area of mathematics, and then one of its sub-areas. Each sub-area page lists its ideas.Areas
+
No area has a topic page yet.
{{end}} +{{with .Others}}