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
144 changes: 144 additions & 0 deletions site/areas.go
Original file line number Diff line number Diff line change
@@ -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]
}
31 changes: 31 additions & 0 deletions site/areas_test.go
Original file line number Diff line number Diff line change
@@ -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</a>"), strings.Index(page, ">Groups</a>")
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</a>", `href="/math2/areas/" aria-current="page">Areas</a>`} {
if !strings.Contains(page, want) {
t.Errorf("the Areas page does not contain %s", want)
}
}
node := readNode(t, out, "EEEEEE")
if !strings.Contains(node, `<a href="/math2/areas/">Areas</a> <span aria-hidden="true">/</span> <a href="/math2/wiki/group-theory/">Group theory</a> <span aria-hidden="true">/</span> <a href="/math2/wiki/subgroups/">Subgroups</a>`) {
t.Error("the crumbs of a node do not show its area and sub-area")
}
}
8 changes: 8 additions & 0 deletions site/assets/site.css
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
1 change: 1 addition & 0 deletions site/pages.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion site/site.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
21 changes: 21 additions & 0 deletions site/templates/areas.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{{define "areas"}}
<header class="page-head">
<h1>Areas</h1>
<p class="lead">Pick an area of mathematics, and then one of its sub-areas. Each sub-area page lists its ideas.</p>
</header>
{{if .Areas}}<ul class="tiles">
{{range .Areas}}<li style="--hue: {{hue .Code}}"><a href="#{{.Topic.Slug}}"><span class="tile-name">{{.Topic.Name}}</span><span class="tile-count">{{len .Subs}} sub-areas, {{.Count}} {{if eq .Count 1}}idea{{else}}ideas{{end}}</span></a></li>
{{end}}
</ul>
{{range .Areas}}<section class="area-section" id="{{.Topic.Slug}}">
<h2><a href="{{.Topic.URL}}">{{.Topic.Name}}</a></h2>
{{with .Topic.Excerpt}}<div class="area-lead">{{.}}</div>{{end}}
<ol class="sub-areas">{{range .Subs}}<li><a href="{{.Topic.URL}}">{{.Topic.Name}}</a>{{if .Count}} <span class="count">{{.Count}}</span>{{end}}</li>{{end}}</ol>
</section>
{{end}}{{else}}<p>No area has a topic page yet.</p>{{end}}
{{with .Others}}<section class="area-section">
<h2>Other topics</h2>
<ul class="name-list">{{range .}}<li><a href="{{.URL}}">{{.Name}}</a></li>{{end}}</ul>
</section>
{{end}}
{{end}}
5 changes: 3 additions & 2 deletions site/templates/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<a class="brand" href="{{url ""}}" aria-label="Math 2.0, main page"><img src="{{url "assets/icon.svg"}}" alt="" width="26" height="26"><span>Math 2.0</span></a>
<nav class="main-nav" aria-label="Main">
<a href="{{url "learn/"}}"{{if eq .Section "learn"}} aria-current="page"{{end}}>Learn</a>
<a href="{{url "msc/"}}"{{if or (eq .Section "msc") (eq .Section "nodes")}} aria-current="page"{{end}}>Subjects</a>
<a href="{{url "areas/"}}"{{if or (eq .Section "areas") (eq .Section "nodes")}} aria-current="page"{{end}}>Areas</a>
<a href="{{url "latest/"}}"{{if eq .Section "latest"}} aria-current="page"{{end}}>Latest</a>
<a href="{{url "discover/"}}"{{if eq .Section "discover"}} aria-current="page"{{end}}>Discover</a>
<a href="{{url "res/"}}"{{if eq .Section "res"}} aria-current="page"{{end}}>Resources</a>
Expand All @@ -61,7 +61,8 @@
<h2>Learn</h2>
<ul>
<li><a href="{{url "learn/"}}">Courses</a></li>
<li><a href="{{url "msc/"}}">Subjects</a></li>
<li><a href="{{url "areas/"}}">Areas</a></li>
<li><a href="{{url "msc/"}}">Subjects (MSC)</a></li>
<li><a href="{{url "nodes/"}}">Every idea</a></li>
<li><a href="{{url "search/"}}">Search</a></li>
</ul>
Expand Down
2 changes: 1 addition & 1 deletion site/templates/node.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{define "node"}}
<article class="node" style="--hue: {{hue .SubjectCode}}">
<header class="node-head">
<p class="crumbs">{{with .SubjectCode}}<a href="{{url (print "msc/" . "/")}}">{{mscName .}}</a> <span aria-hidden="true">/</span> {{end}}{{with area .}}<a href="{{.URL}}">{{.Title}}</a> <span aria-hidden="true">/</span> {{end}}<a href="{{url (print "kind/" .Kind "/")}}">{{.Label}}</a></p>
<p class="crumbs">{{with topicPath .}}<a href="{{url "areas/"}}">Areas</a> <span aria-hidden="true">/</span> {{range .}}<a href="{{.URL}}">{{.Name}}</a> <span aria-hidden="true">/</span> {{end}}{{else}}{{with .SubjectCode}}<a href="{{url (print "msc/" . "/")}}">{{mscName .}}</a> <span aria-hidden="true">/</span> {{end}}{{with area .}}<a href="{{.URL}}">{{.Title}}</a> <span aria-hidden="true">/</span> {{end}}{{end}}<a href="{{url (print "kind/" .Kind "/")}}">{{.Label}}</a></p>
<h1>{{.Name}}</h1>
<p class="node-share"><button class="button" type="button" data-share="{{.URL}}" data-title="{{.Name}}">Share this page</button></p>
{{with .Uses}}<p class="builds"><span>Builds on</span> {{range $i, $l := .}}<a href="{{$l.URL}}"{{if $l.Missing}} class="missing" title="This page does not exist yet"{{end}}>{{$l.Text}}</a>{{end}}</p>{{end}}
Expand Down
Loading