Skip to content
This repository was archived by the owner on Jan 31, 2022. It is now read-only.

Commit 5e145f8

Browse files
authored
all: add redirect from /pkg.go.dev to pkg.go.dev/cuelang.org/go@$version (#90)
This is more relevant for tip.cuelang.org, because the master docs on pkg.go.dev are not currently easily accessible. Hence the advice is: golang/go#36811 (comment) Therefore we code generate a redirect file based on the required version of cuelang.org/go (which is automatically updated for tip)
1 parent fd4e9c9 commit 5e145f8

File tree

5 files changed

+72
-0
lines changed

5 files changed

+72
-0
lines changed

build.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ set -x
1010
if [ "$NETLIFY" = "true" ] && [ "$BRANCH" = "tip" ]
1111
then
1212
GOPROXY=direct go get cuelang.org/go@master
13+
# Now force it through the proxy so that the /pkg.go.dev redirect works
14+
go get cuelang.org/go@$(go list -m -f={{.Version}} cuelang.org/go)
1315
fi
1416

1517
git submodule update -f --init --recursive

content/en/gen.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package en
2+
3+
//go:generate go run github.com/cuelang/cuelang.org/internal/gentipredirect

content/en/pkg.go.dev.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
type: redirect
3+
redirectURL: https://pkg.go.dev/cuelang.org/[email protected]
4+
---

internal/gentipredirect/main.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright 2019 CUE Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
// gentipredirect regenerates a simple Hugo markdown file that acts as a redirect
16+
// to the @master module documentation root on pkg.go.dev
17+
package main
18+
19+
import (
20+
"bytes"
21+
"fmt"
22+
"io/ioutil"
23+
"log"
24+
"os/exec"
25+
"strings"
26+
27+
// imported for side effect of module being available in cache
28+
_ "cuelang.org/go/pkg"
29+
)
30+
31+
func main() {
32+
log.SetFlags(log.Lshortfile)
33+
34+
var cueVersion bytes.Buffer
35+
cmd := exec.Command("go", "list", "-m", "-f={{.Version}}", "cuelang.org/go")
36+
cmd.Stdout = &cueVersion
37+
if err := cmd.Run(); err != nil {
38+
log.Fatalf("failed to run %v; %v", strings.Join(cmd.Args, " "), err)
39+
}
40+
41+
content := fmt.Sprintf(`---
42+
type: redirect
43+
redirectURL: https://pkg.go.dev/cuelang.org/go@%v
44+
---`, strings.TrimSpace(cueVersion.String()))
45+
46+
const target = "pkg.go.dev.md"
47+
48+
if err := ioutil.WriteFile(target, []byte(content), 0666); err != nil {
49+
log.Fatalf("failed to write to %v; %v", target, err)
50+
}
51+
}

layouts/redirect/single.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html lang="en-US">
3+
<meta charset="utf-8">
4+
<title>Redirecting&hellip;</title>
5+
<link rel="canonical" href="{{.Params.redirectURL}}">
6+
<script>location="{{.Params.redirectURL}}"</script>
7+
<meta http-equiv="refresh" content="0; url={{.Params.redirectURL}}">
8+
<meta name="robots" content="noindex">
9+
<h1>Redirecting&hellip;</h1>
10+
<a href="{{.Params.redirectURL}}">Click here if you are not redirected.</a>
11+
</html>
12+

0 commit comments

Comments
 (0)