[x/go.dev] all: replace aliases with redirects

Putting an "aliases" list into a page means that you cannot serve
any page at all until you have loaded every single page in the site,
because maybe one will list the URL you want to serve as an alias.

Turning it around, we can create pages for the URLs we want to
serve and simply mark them as redirects to the real pages.
Now you can serve any page by opening the file and looking at
what is there. There's no need to reload every single page in the
site just to answer a single request.

We made (and corrected) this mistake in the main site as well.
It is an obvious thing to do.

Replace aliases with redirects.

Change-Id: Ib31bf48e2a6fa6f384011381dcae6bbfcaf11f95
X-GoDev-Commit: 8dcbcab6097450c570ca42101c2ea3218a8f1c62
diff --git a/go.dev/_content/solutions/chrome.md b/go.dev/_content/solutions/chrome.md
new file mode 100644
index 0000000..3420414
--- /dev/null
+++ b/go.dev/_content/solutions/chrome.md
@@ -0,0 +1,3 @@
+---
+redirect: /solutions/google/chrome
+---
diff --git a/go.dev/_content/solutions/coredata.md b/go.dev/_content/solutions/coredata.md
new file mode 100644
index 0000000..6f5663e
--- /dev/null
+++ b/go.dev/_content/solutions/coredata.md
@@ -0,0 +1,3 @@
+---
+redirect: /solutions/google/coredata
+---
diff --git a/go.dev/_content/solutions/firebase.md b/go.dev/_content/solutions/firebase.md
new file mode 100644
index 0000000..968708b
--- /dev/null
+++ b/go.dev/_content/solutions/firebase.md
@@ -0,0 +1,3 @@
+---
+redirect: /solutions/google/firebase
+---
diff --git a/go.dev/_content/solutions/google/chrome.md b/go.dev/_content/solutions/google/chrome.md
index b0ee9d0..6a77f2c 100644
--- a/go.dev/_content/solutions/google/chrome.md
+++ b/go.dev/_content/solutions/google/chrome.md
@@ -12,8 +12,6 @@
   In this case study, the Chrome Optimization Guide
   team shared how they experimented with Go, ramped up quickly, and their plans to
   use Go going forward.
-aliases:
-    - /solutions/chrome
 ---
 
 When the product Chrome comes to mind, you probably think solely of the
diff --git a/go.dev/_content/solutions/google/coredata.md b/go.dev/_content/solutions/google/coredata.md
index e9bbb0a..4c1f7d6 100644
--- a/go.dev/_content/solutions/google/coredata.md
+++ b/go.dev/_content/solutions/google/coredata.md
@@ -15,8 +15,6 @@
   improve the development process.
 authors:
   - Prasanna Meda, Software Engineer, Core Data Solutions
-aliases:
-    - /solutions/coredata
 ---
 
 Google's mission is “to organize the world's information and make it universally
diff --git a/go.dev/_content/solutions/google/firebase.md b/go.dev/_content/solutions/google/firebase.md
index f46fba9..aa6cf60 100644
--- a/go.dev/_content/solutions/google/firebase.md
+++ b/go.dev/_content/solutions/google/firebase.md
@@ -12,8 +12,6 @@
   The Firebase Hosting team shared their journey with Go, including their
   backend migration from Node.js, the ease of onboarding new Go developers, and
   how Go has helped them scale.
-aliases:
-    - /solutions/firebase
 ---
 
 The Firebase Hosting team provides static web hosting services for Google Cloud
diff --git a/go.dev/_content/solutions/google/sitereliability.md b/go.dev/_content/solutions/google/sitereliability.md
index 251a4b1..3bdc7d7 100644
--- a/go.dev/_content/solutions/google/sitereliability.md
+++ b/go.dev/_content/solutions/google/sitereliability.md
@@ -11,8 +11,6 @@
   They shared their experience building core production management systems with Go, coming from experience with Python and C++.
 authors:
   - Pierre Palatin, Site Reliability Engineer
-aliases:
-    - /solutions/sitereliability
 ---
 
 Google runs a small number of very large services. Those services are powered
diff --git a/go.dev/_content/solutions/sitereliability.md b/go.dev/_content/solutions/sitereliability.md
new file mode 100644
index 0000000..b3c80b5
--- /dev/null
+++ b/go.dev/_content/solutions/sitereliability.md
@@ -0,0 +1,3 @@
+---
+redirect: /solutions/google/sitereliability
+---
diff --git a/go.dev/cmd/internal/site/page.go b/go.dev/cmd/internal/site/page.go
index fcb263f..5c9a7da 100644
--- a/go.dev/cmd/internal/site/page.go
+++ b/go.dev/cmd/internal/site/page.go
@@ -44,6 +44,11 @@
 	p := site.newPage(id)
 	p.file = file
 
+	urlPath := "/" + p.id
+	if strings.HasSuffix(p.file, "/index.md") && p.id != "" {
+		urlPath += "/"
+	}
+
 	// Load content, including leading yaml.
 	data, err := ioutil.ReadFile(site.file(file))
 	if err != nil {
@@ -99,10 +104,6 @@
 	}
 
 	// Path, Dir, URL
-	urlPath := "/" + p.id
-	if strings.HasSuffix(p.file, "/index.md") && p.id != "" {
-		urlPath += "/"
-	}
 	p.params["Path"] = urlPath
 	p.params["Dir"] = path.Dir(urlPath)
 	p.params["URL"] = strings.TrimRight(site.URL, "/") + urlPath
@@ -125,13 +126,6 @@
 	}
 	p.params["Section"] = section
 
-	// Register aliases. Needs URL.
-	aliases, _ := p.params["aliases"].([]interface{})
-	for _, alias := range aliases {
-		if a, ok := alias.(string); ok {
-			site.redirects[strings.Trim(a, "/")] = p.params["URL"].(string)
-		}
-	}
 	return p, nil
 }
 
diff --git a/go.dev/cmd/internal/site/site.go b/go.dev/cmd/internal/site/site.go
index 9abe247..f54077e 100644
--- a/go.dev/cmd/internal/site/site.go
+++ b/go.dev/cmd/internal/site/site.go
@@ -31,7 +31,6 @@
 
 	pagesByID map[string]*page
 	dir       string
-	redirects map[string]string
 	base      *template.Template
 }
 
@@ -43,7 +42,6 @@
 	}
 	site := &Site{
 		dir:       dir,
-		redirects: make(map[string]string),
 		pagesByID: make(map[string]*page),
 	}
 	if err := site.initTemplate(); err != nil {
@@ -179,11 +177,11 @@
 		if name == "index.html" {
 			id = ""
 		}
-		if target := site.redirects[id]; target != "" {
-			s := fmt.Sprintf(redirectFmt, target)
-			return &httpFile{strings.NewReader(s), int64(len(s))}, nil
-		}
 		if p := site.pagesByID[id]; p != nil {
+			if redir, ok := p.params["redirect"].(string); ok {
+				s := fmt.Sprintf(redirectFmt, redir)
+				return &httpFile{strings.NewReader(s), int64(len(s))}, nil
+			}
 			return &httpFile{bytes.NewReader(p.html), int64(len(p.html))}, nil
 		}
 	}
diff --git a/go.dev/testdata/golden/solutions/chrome/index.html b/go.dev/testdata/golden/solutions/chrome/index.html
index 7e4c4c6..6cc9549 100644
--- a/go.dev/testdata/golden/solutions/chrome/index.html
+++ b/go.dev/testdata/golden/solutions/chrome/index.html
@@ -1 +1 @@
-<!DOCTYPE html><html><head><title>https://go.dev/solutions/google/chrome</title><link rel="canonical" href="https://go.dev/solutions/google/chrome"/><meta name="robots" content="noindex"><meta charset="utf-8" /><meta http-equiv="refresh" content="0; url=https://go.dev/solutions/google/chrome" /></head></html>
+<!DOCTYPE html><html><head><title>/solutions/google/chrome</title><link rel="canonical" href="/solutions/google/chrome"/><meta name="robots" content="noindex"><meta charset="utf-8" /><meta http-equiv="refresh" content="0; url=/solutions/google/chrome" /></head></html>
diff --git a/go.dev/testdata/golden/solutions/coredata/index.html b/go.dev/testdata/golden/solutions/coredata/index.html
index 254599f..5e2d4bd 100644
--- a/go.dev/testdata/golden/solutions/coredata/index.html
+++ b/go.dev/testdata/golden/solutions/coredata/index.html
@@ -1 +1 @@
-<!DOCTYPE html><html><head><title>https://go.dev/solutions/google/coredata</title><link rel="canonical" href="https://go.dev/solutions/google/coredata"/><meta name="robots" content="noindex"><meta charset="utf-8" /><meta http-equiv="refresh" content="0; url=https://go.dev/solutions/google/coredata" /></head></html>
+<!DOCTYPE html><html><head><title>/solutions/google/coredata</title><link rel="canonical" href="/solutions/google/coredata"/><meta name="robots" content="noindex"><meta charset="utf-8" /><meta http-equiv="refresh" content="0; url=/solutions/google/coredata" /></head></html>
diff --git a/go.dev/testdata/golden/solutions/firebase/index.html b/go.dev/testdata/golden/solutions/firebase/index.html
index 3c56dc4..8cd7d16 100644
--- a/go.dev/testdata/golden/solutions/firebase/index.html
+++ b/go.dev/testdata/golden/solutions/firebase/index.html
@@ -1 +1 @@
-<!DOCTYPE html><html><head><title>https://go.dev/solutions/google/firebase</title><link rel="canonical" href="https://go.dev/solutions/google/firebase"/><meta name="robots" content="noindex"><meta charset="utf-8" /><meta http-equiv="refresh" content="0; url=https://go.dev/solutions/google/firebase" /></head></html>
+<!DOCTYPE html><html><head><title>/solutions/google/firebase</title><link rel="canonical" href="/solutions/google/firebase"/><meta name="robots" content="noindex"><meta charset="utf-8" /><meta http-equiv="refresh" content="0; url=/solutions/google/firebase" /></head></html>
diff --git a/go.dev/testdata/golden/solutions/sitereliability/index.html b/go.dev/testdata/golden/solutions/sitereliability/index.html
index 71867aa..8c17ec9 100644
--- a/go.dev/testdata/golden/solutions/sitereliability/index.html
+++ b/go.dev/testdata/golden/solutions/sitereliability/index.html
@@ -1 +1 @@
-<!DOCTYPE html><html><head><title>https://go.dev/solutions/google/sitereliability</title><link rel="canonical" href="https://go.dev/solutions/google/sitereliability"/><meta name="robots" content="noindex"><meta charset="utf-8" /><meta http-equiv="refresh" content="0; url=https://go.dev/solutions/google/sitereliability" /></head></html>
+<!DOCTYPE html><html><head><title>/solutions/google/sitereliability</title><link rel="canonical" href="/solutions/google/sitereliability"/><meta name="robots" content="noindex"><meta charset="utf-8" /><meta http-equiv="refresh" content="0; url=/solutions/google/sitereliability" /></head></html>