diff --git a/golang/README.md b/golang/README.md new file mode 100644 index 000000000..f688883a5 --- /dev/null +++ b/golang/README.md @@ -0,0 +1,2 @@ +This Directory is AUTO-GENERATED. Do not modify directly, run ./tools/redir-gen. + diff --git a/golang/_redirects b/golang/_redirects new file mode 100755 index 000000000..af5db0ad4 --- /dev/null +++ b/golang/_redirects @@ -0,0 +1,66 @@ + +# This file is AUTO-GENERATED +# +# DO NOT EDIT! +# +# To regenerate, run: +# redir-gen +/actions-downstream-test/* go-get=1 /golang/actions-downstream-test.html 200 +/actions-kind/* go-get=1 /golang/actions-kind.html 200 +/async-component/* go-get=1 /golang/async-component.html 200 +/build-spike/* go-get=1 /golang/build-spike.html 200 +/caching/* go-get=1 /golang/caching.html 200 +/client/* go-get=1 /golang/client.html 200 +/community/* go-get=1 /golang/community.html 200 +/control-protocol/* go-get=1 /golang/control-protocol.html 200 +/discovery/* go-get=1 /golang/discovery.html 200 +/docs/* go-get=1 /golang/docs.html 200 +/eventing/* go-get=1 /golang/eventing.html 200 +/eventing-autoscaler-keda/* go-get=1 /golang/eventing-autoscaler-keda.html 200 +/eventing-awssqs/* go-get=1 /golang/eventing-awssqs.html 200 +/eventing-camel/* go-get=1 /golang/eventing-camel.html 200 +/eventing-ceph/* go-get=1 /golang/eventing-ceph.html 200 +/eventing-couchdb/* go-get=1 /golang/eventing-couchdb.html 200 +/eventing-github/* go-get=1 /golang/eventing-github.html 200 +/eventing-gitlab/* go-get=1 /golang/eventing-gitlab.html 200 +/eventing-kafka/* go-get=1 /golang/eventing-kafka.html 200 +/eventing-kafka-broker/* go-get=1 /golang/eventing-kafka-broker.html 200 +/eventing-natss/* go-get=1 /golang/eventing-natss.html 200 +/eventing-prometheus/* go-get=1 /golang/eventing-prometheus.html 200 +/eventing-rabbitmq/* go-get=1 /golang/eventing-rabbitmq.html 200 +/eventing-redis/* go-get=1 /golang/eventing-redis.html 200 +/hack/* go-get=1 /golang/hack.html 200 +/homebrew-client/* go-get=1 /golang/homebrew-client.html 200 +/homebrew-kn-plugins/* go-get=1 /golang/homebrew-kn-plugins.html 200 +/integration/* go-get=1 /golang/integration.html 200 +/kn-plugin-admin/* go-get=1 /golang/kn-plugin-admin.html 200 +/kn-plugin-diag/* go-get=1 /golang/kn-plugin-diag.html 200 +/kn-plugin-event/* go-get=1 /golang/kn-plugin-event.html 200 +/kn-plugin-migration/* go-get=1 /golang/kn-plugin-migration.html 200 +/kn-plugin-quickstart/* go-get=1 /golang/kn-plugin-quickstart.html 200 +/kn-plugin-sample/* go-get=1 /golang/kn-plugin-sample.html 200 +/kn-plugin-service-log/* go-get=1 /golang/kn-plugin-service-log.html 200 +/kn-plugin-source-kafka/* go-get=1 /golang/kn-plugin-source-kafka.html 200 +/kn-plugin-source-kamelet/* go-get=1 /golang/kn-plugin-source-kamelet.html 200 +/kn-plugin-source-pkg/* go-get=1 /golang/kn-plugin-source-pkg.html 200 +/knobots/* go-get=1 /golang/knobots.html 200 +/kperf/* go-get=1 /golang/kperf.html 200 +/net-certmanager/* go-get=1 /golang/net-certmanager.html 200 +/net-contour/* go-get=1 /golang/net-contour.html 200 +/net-http01/* go-get=1 /golang/net-http01.html 200 +/net-ingressv2/* go-get=1 /golang/net-ingressv2.html 200 +/net-istio/* go-get=1 /golang/net-istio.html 200 +/net-kourier/* go-get=1 /golang/net-kourier.html 200 +/networking/* go-get=1 /golang/networking.html 200 +/operator/* go-get=1 /golang/operator.html 200 +/pkg/* go-get=1 /golang/pkg.html 200 +/reconciler-test/* go-get=1 /golang/reconciler-test.html 200 +/release/* go-get=1 /golang/release.html 200 +/sample-controller/* go-get=1 /golang/sample-controller.html 200 +/sample-source/* go-get=1 /golang/sample-source.html 200 +/serving/* go-get=1 /golang/serving.html 200 +/specs/* go-get=1 /golang/specs.html 200 +/test-infra/* go-get=1 /golang/test-infra.html 200 +/ux/* go-get=1 /golang/ux.html 200 +/website/* go-get=1 /golang/website.html 200 +/wg-repository/* go-get=1 /golang/wg-repository.html 200 diff --git a/golang/actions-downstream-test.html b/golang/actions-downstream-test.html new file mode 100644 index 000000000..967e1a0e7 --- /dev/null +++ b/golang/actions-downstream-test.html @@ -0,0 +1,4 @@ +
+ + + diff --git a/golang/actions-kind.html b/golang/actions-kind.html new file mode 100644 index 000000000..af9f2fa49 --- /dev/null +++ b/golang/actions-kind.html @@ -0,0 +1,4 @@ + + + + diff --git a/golang/async-component.html b/golang/async-component.html new file mode 100644 index 000000000..64149ccb6 --- /dev/null +++ b/golang/async-component.html @@ -0,0 +1,4 @@ + + + + diff --git a/golang/build-spike.html b/golang/build-spike.html new file mode 100644 index 000000000..5a12e71dd --- /dev/null +++ b/golang/build-spike.html @@ -0,0 +1,4 @@ + + + + diff --git a/golang/caching.html b/golang/caching.html new file mode 100644 index 000000000..43d9b71a0 --- /dev/null +++ b/golang/caching.html @@ -0,0 +1,4 @@ + + + + diff --git a/golang/client.html b/golang/client.html new file mode 100644 index 000000000..c983c9901 --- /dev/null +++ b/golang/client.html @@ -0,0 +1,4 @@ + + + + diff --git a/golang/community.html b/golang/community.html new file mode 100644 index 000000000..7c8039492 --- /dev/null +++ b/golang/community.html @@ -0,0 +1,4 @@ + + + + diff --git a/golang/control-protocol.html b/golang/control-protocol.html new file mode 100644 index 000000000..8d5738c8b --- /dev/null +++ b/golang/control-protocol.html @@ -0,0 +1,4 @@ + + + + diff --git a/golang/discovery.html b/golang/discovery.html new file mode 100644 index 000000000..f8a91111b --- /dev/null +++ b/golang/discovery.html @@ -0,0 +1,4 @@ + + + + diff --git a/golang/docs.html b/golang/docs.html new file mode 100644 index 000000000..4e4c44867 --- /dev/null +++ b/golang/docs.html @@ -0,0 +1,4 @@ + + + + diff --git a/golang/eventing-autoscaler-keda.html b/golang/eventing-autoscaler-keda.html new file mode 100644 index 000000000..958740848 --- /dev/null +++ b/golang/eventing-autoscaler-keda.html @@ -0,0 +1,4 @@ + + + + diff --git a/golang/eventing-awssqs.html b/golang/eventing-awssqs.html new file mode 100644 index 000000000..5251ed0d1 --- /dev/null +++ b/golang/eventing-awssqs.html @@ -0,0 +1,4 @@ + + + + diff --git a/golang/eventing-camel.html b/golang/eventing-camel.html new file mode 100644 index 000000000..b2f1e645b --- /dev/null +++ b/golang/eventing-camel.html @@ -0,0 +1,4 @@ + + + + diff --git a/golang/eventing-ceph.html b/golang/eventing-ceph.html new file mode 100644 index 000000000..bdf8693b3 --- /dev/null +++ b/golang/eventing-ceph.html @@ -0,0 +1,4 @@ + + + + diff --git a/golang/eventing-couchdb.html b/golang/eventing-couchdb.html new file mode 100644 index 000000000..11e09e4c7 --- /dev/null +++ b/golang/eventing-couchdb.html @@ -0,0 +1,4 @@ + + + + diff --git a/golang/eventing-github.html b/golang/eventing-github.html new file mode 100644 index 000000000..736567746 --- /dev/null +++ b/golang/eventing-github.html @@ -0,0 +1,4 @@ + + + + diff --git a/golang/eventing-gitlab.html b/golang/eventing-gitlab.html new file mode 100644 index 000000000..470786b85 --- /dev/null +++ b/golang/eventing-gitlab.html @@ -0,0 +1,4 @@ + + + + diff --git a/golang/eventing-kafka-broker.html b/golang/eventing-kafka-broker.html new file mode 100644 index 000000000..ad2ec0a91 --- /dev/null +++ b/golang/eventing-kafka-broker.html @@ -0,0 +1,4 @@ + + + + diff --git a/golang/eventing-kafka.html b/golang/eventing-kafka.html new file mode 100644 index 000000000..d908c3819 --- /dev/null +++ b/golang/eventing-kafka.html @@ -0,0 +1,4 @@ + + + + diff --git a/golang/eventing-natss.html b/golang/eventing-natss.html new file mode 100644 index 000000000..7fa0bad91 --- /dev/null +++ b/golang/eventing-natss.html @@ -0,0 +1,4 @@ + + + + diff --git a/golang/eventing-prometheus.html b/golang/eventing-prometheus.html new file mode 100644 index 000000000..943cbf156 --- /dev/null +++ b/golang/eventing-prometheus.html @@ -0,0 +1,4 @@ + + + + diff --git a/golang/eventing-rabbitmq.html b/golang/eventing-rabbitmq.html new file mode 100644 index 000000000..57dcf3a45 --- /dev/null +++ b/golang/eventing-rabbitmq.html @@ -0,0 +1,4 @@ + + + + diff --git a/golang/eventing-redis.html b/golang/eventing-redis.html new file mode 100644 index 000000000..0747d9397 --- /dev/null +++ b/golang/eventing-redis.html @@ -0,0 +1,4 @@ + + + + diff --git a/golang/eventing.html b/golang/eventing.html new file mode 100644 index 000000000..934d3d4c1 --- /dev/null +++ b/golang/eventing.html @@ -0,0 +1,4 @@ + + + + diff --git a/golang/hack.html b/golang/hack.html new file mode 100644 index 000000000..a4b200fb2 --- /dev/null +++ b/golang/hack.html @@ -0,0 +1,4 @@ + + + + diff --git a/golang/homebrew-client.html b/golang/homebrew-client.html new file mode 100644 index 000000000..a4ccc281c --- /dev/null +++ b/golang/homebrew-client.html @@ -0,0 +1,4 @@ + + + + diff --git a/golang/homebrew-kn-plugins.html b/golang/homebrew-kn-plugins.html new file mode 100644 index 000000000..99e03f67c --- /dev/null +++ b/golang/homebrew-kn-plugins.html @@ -0,0 +1,4 @@ + + + + diff --git a/golang/integration.html b/golang/integration.html new file mode 100644 index 000000000..06cedf4b8 --- /dev/null +++ b/golang/integration.html @@ -0,0 +1,4 @@ + + + + diff --git a/golang/kn-plugin-admin.html b/golang/kn-plugin-admin.html new file mode 100644 index 000000000..8ac167170 --- /dev/null +++ b/golang/kn-plugin-admin.html @@ -0,0 +1,4 @@ + + + + diff --git a/golang/kn-plugin-diag.html b/golang/kn-plugin-diag.html new file mode 100644 index 000000000..b5886e9f6 --- /dev/null +++ b/golang/kn-plugin-diag.html @@ -0,0 +1,4 @@ + + + + diff --git a/golang/kn-plugin-event.html b/golang/kn-plugin-event.html new file mode 100644 index 000000000..ecfc62ae7 --- /dev/null +++ b/golang/kn-plugin-event.html @@ -0,0 +1,4 @@ + + + + diff --git a/golang/kn-plugin-migration.html b/golang/kn-plugin-migration.html new file mode 100644 index 000000000..0d3b37def --- /dev/null +++ b/golang/kn-plugin-migration.html @@ -0,0 +1,4 @@ + + + + diff --git a/golang/kn-plugin-quickstart.html b/golang/kn-plugin-quickstart.html new file mode 100644 index 000000000..67ef92c78 --- /dev/null +++ b/golang/kn-plugin-quickstart.html @@ -0,0 +1,4 @@ + + + + diff --git a/golang/kn-plugin-sample.html b/golang/kn-plugin-sample.html new file mode 100644 index 000000000..4ef085f15 --- /dev/null +++ b/golang/kn-plugin-sample.html @@ -0,0 +1,4 @@ + + + + diff --git a/golang/kn-plugin-service-log.html b/golang/kn-plugin-service-log.html new file mode 100644 index 000000000..129ebad3a --- /dev/null +++ b/golang/kn-plugin-service-log.html @@ -0,0 +1,4 @@ + + + + diff --git a/golang/kn-plugin-source-kafka.html b/golang/kn-plugin-source-kafka.html new file mode 100644 index 000000000..7a3d7cabe --- /dev/null +++ b/golang/kn-plugin-source-kafka.html @@ -0,0 +1,4 @@ + + + + diff --git a/golang/kn-plugin-source-kamelet.html b/golang/kn-plugin-source-kamelet.html new file mode 100644 index 000000000..4fed232a0 --- /dev/null +++ b/golang/kn-plugin-source-kamelet.html @@ -0,0 +1,4 @@ + + + + diff --git a/golang/kn-plugin-source-pkg.html b/golang/kn-plugin-source-pkg.html new file mode 100644 index 000000000..dbb50c02c --- /dev/null +++ b/golang/kn-plugin-source-pkg.html @@ -0,0 +1,4 @@ + + + + diff --git a/golang/knobots.html b/golang/knobots.html new file mode 100644 index 000000000..43213ee8e --- /dev/null +++ b/golang/knobots.html @@ -0,0 +1,4 @@ + + + + diff --git a/golang/kperf.html b/golang/kperf.html new file mode 100644 index 000000000..9fc15f1ee --- /dev/null +++ b/golang/kperf.html @@ -0,0 +1,4 @@ + + + + diff --git a/golang/net-certmanager.html b/golang/net-certmanager.html new file mode 100644 index 000000000..a7d73a4e4 --- /dev/null +++ b/golang/net-certmanager.html @@ -0,0 +1,4 @@ + + + + diff --git a/golang/net-contour.html b/golang/net-contour.html new file mode 100644 index 000000000..c013f69e6 --- /dev/null +++ b/golang/net-contour.html @@ -0,0 +1,4 @@ + + + + diff --git a/golang/net-http01.html b/golang/net-http01.html new file mode 100644 index 000000000..6ee8daf18 --- /dev/null +++ b/golang/net-http01.html @@ -0,0 +1,4 @@ + + + + diff --git a/golang/net-ingressv2.html b/golang/net-ingressv2.html new file mode 100644 index 000000000..5bb401bd1 --- /dev/null +++ b/golang/net-ingressv2.html @@ -0,0 +1,4 @@ + + + + diff --git a/golang/net-istio.html b/golang/net-istio.html new file mode 100644 index 000000000..6e0b5108a --- /dev/null +++ b/golang/net-istio.html @@ -0,0 +1,4 @@ + + + + diff --git a/golang/net-kourier.html b/golang/net-kourier.html new file mode 100644 index 000000000..d020a8ade --- /dev/null +++ b/golang/net-kourier.html @@ -0,0 +1,4 @@ + + + + diff --git a/golang/networking.html b/golang/networking.html new file mode 100644 index 000000000..a49e30390 --- /dev/null +++ b/golang/networking.html @@ -0,0 +1,4 @@ + + + + diff --git a/golang/operator.html b/golang/operator.html new file mode 100644 index 000000000..1769ebb97 --- /dev/null +++ b/golang/operator.html @@ -0,0 +1,4 @@ + + + + diff --git a/golang/pkg.html b/golang/pkg.html new file mode 100644 index 000000000..447efb9a2 --- /dev/null +++ b/golang/pkg.html @@ -0,0 +1,4 @@ + + + + diff --git a/golang/reconciler-test.html b/golang/reconciler-test.html new file mode 100644 index 000000000..cade4d8f2 --- /dev/null +++ b/golang/reconciler-test.html @@ -0,0 +1,4 @@ + + + + diff --git a/golang/release.html b/golang/release.html new file mode 100644 index 000000000..66f9a6f76 --- /dev/null +++ b/golang/release.html @@ -0,0 +1,4 @@ + + + + diff --git a/golang/sample-controller.html b/golang/sample-controller.html new file mode 100644 index 000000000..772b8a6c9 --- /dev/null +++ b/golang/sample-controller.html @@ -0,0 +1,4 @@ + + + + diff --git a/golang/sample-source.html b/golang/sample-source.html new file mode 100644 index 000000000..8b665ab1a --- /dev/null +++ b/golang/sample-source.html @@ -0,0 +1,4 @@ + + + + diff --git a/golang/serving.html b/golang/serving.html new file mode 100644 index 000000000..c32be6dbf --- /dev/null +++ b/golang/serving.html @@ -0,0 +1,4 @@ + + + + diff --git a/golang/specs.html b/golang/specs.html new file mode 100644 index 000000000..37041434d --- /dev/null +++ b/golang/specs.html @@ -0,0 +1,4 @@ + + + + diff --git a/golang/test-infra.html b/golang/test-infra.html new file mode 100644 index 000000000..3e515323d --- /dev/null +++ b/golang/test-infra.html @@ -0,0 +1,4 @@ + + + + diff --git a/golang/ux.html b/golang/ux.html new file mode 100644 index 000000000..b39a3b204 --- /dev/null +++ b/golang/ux.html @@ -0,0 +1,4 @@ + + + + diff --git a/golang/website.html b/golang/website.html new file mode 100644 index 000000000..e09ba44df --- /dev/null +++ b/golang/website.html @@ -0,0 +1,4 @@ + + + + diff --git a/golang/wg-repository.html b/golang/wg-repository.html new file mode 100644 index 000000000..dae98924e --- /dev/null +++ b/golang/wg-repository.html @@ -0,0 +1,4 @@ + + + + diff --git a/hack/build.sh b/hack/build.sh index 33fcdf450..2e20b8a8e 100755 --- a/hack/build.sh +++ b/hack/build.sh @@ -116,6 +116,11 @@ if [ -z "$SKIP_BLOG" ]; then for d in blog community css scss webfonts images js; do mv temp/website/public/$d site/ done + + # Copy go mod files so knative.dev/blahblah vanity URLs work + mkdir site/golang + cp golang/*.html site/golang/ + cat golang/_redirects >> site/_redirects fi # Home page is served from docs, so add a redirect. diff --git a/tools/redir-gen/go.mod b/tools/redir-gen/go.mod new file mode 100644 index 000000000..735ee0105 --- /dev/null +++ b/tools/redir-gen/go.mod @@ -0,0 +1,5 @@ +module knative.dev/website/tools/redir-gen + +go 1.15 + +require github.com/google/go-github/v32 v32.1.0 diff --git a/tools/redir-gen/go.sum b/tools/redir-gen/go.sum new file mode 100644 index 000000000..c9f59917d --- /dev/null +++ b/tools/redir-gen/go.sum @@ -0,0 +1,13 @@ +github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/google/go-github v17.0.0+incompatible h1:N0LgJ1j65A7kfXrZnUDaYCs/Sf4rEjNlfyDHW9dolSY= +github.com/google/go-github/v32 v32.1.0 h1:GWkQOdXqviCPx7Q7Fj+KyPoGm4SwHRh8rheoPhd27II= +github.com/google/go-github/v32 v32.1.0/go.mod h1:rIEpZD9CTDQwDK9GDrtMTycQNA4JU3qBsCizh3q2WCI= +github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk= +github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= diff --git a/tools/redir-gen/main.go b/tools/redir-gen/main.go new file mode 100644 index 000000000..d21e4d1ef --- /dev/null +++ b/tools/redir-gen/main.go @@ -0,0 +1,184 @@ +/* +Copyright 2020 The Knative Authors +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package main + +import ( + "context" + "fmt" + "html/template" + "io/ioutil" + "log" + "os" + "regexp" + "sort" + "strings" + + "github.com/google/go-github/v32/github" +) + +var ( + knativeOrgs = []string{"knative", "knative-sandbox"} + allowedRepoRe = regexp.MustCompile("^[a-z][-a-z0-9]+$") +) + +// repoInfo provides a simple holder for GitHub repo information needed to +// generate go mod redirects. +type repoInfo struct { + // Org is the name of the github organization the repo is in. + Org string + // Repo is the name of the github repo within the organizatiøon (e.g. + // "serving", NOT "knative/serving") + Repo string + // DefaultBranch is the name of the default branch. This will be changing + // from "master" to "main" over time. + DefaultBranch string +} + +type riSlice []repoInfo + +func main() { + repos, err := fetchRepos(knativeOrgs) + if err != nil { + log.Fatal("Failed to fetch repos: ", err) + } + for _, repo := range repos { + if err := createGoGetFile(repo); err != nil { + log.Fatalf("Unable to create go mod file for %s: %v", repo, err) + } + } + if err := appendRedirs(repos); err != nil { + log.Fatal("Failed to write redir file: ", err) + } +} + +func fetchRepos(orgs []string) ([]repoInfo, error) { + ctx := context.Background() + allRepos := riSlice{} + client := github.NewClient(nil) + for _, org := range orgs { + opts := &github.RepositoryListByOrgOptions{ + ListOptions: github.ListOptions{PerPage: 50}, + } + for { + repos, resp, err := client.Repositories.ListByOrg(ctx, org, opts) + if err != nil { + return nil, err + } + for _, r := range repos { + if !allowedRepoRe.MatchString(*r.Name) { + log.Printf("Ignoring repo %s, matched by ignore %q", *r.Name, allowedRepoRe) + continue + } + if *r.Archived { + log.Print("Ignoring archived repo: ", *r.Name) + continue + } + allRepos = append(allRepos, repoInfo{org, *r.Name, *r.DefaultBranch}) + } + if resp.NextPage == 0 { + break + } + } + } + sort.Sort(allRepos) + return allRepos, nil +} + +const ( + goHTML = ` + + + +` + redirText = `/{{.Repo}}/* go-get=1 /golang/{{.Repo}}.html 200 +` + + autogenPrefix = ` +# This file is AUTO-GENERATED +# +# DO NOT EDIT! +# +# To regenerate, run: +` +) + +func appendRedirs(ris []repoInfo) error { + redirFilename := "golang/_redirects" + redirFile, err := os.OpenFile(redirFilename, os.O_RDWR|os.O_CREATE, 0755) + if err != nil { + return fmt.Errorf("unable to open %q: %w", redirFilename, err) + } + defer redirFile.Close() + + redirs, err := ioutil.ReadAll(redirFile) + if err != nil { + return fmt.Errorf("unable to read %q: %w", redirFilename, err) + } + + seekTo := int64(strings.Index(string(redirs), autogenPrefix)) + if seekTo == -1 { + seekTo = int64(len(redirs)) + } + if _, err := redirFile.Seek(seekTo, 0); err != nil { + return fmt.Errorf("unable to seek in %q: %w", redirFilename, err) + } + if redirFile.Truncate(seekTo) != nil { + return fmt.Errorf("unable to truncate %q: %w", redirFilename, err) + } + + if _, err := redirFile.WriteString(autogenPrefix); err != nil { + return fmt.Errorf("unable to write to %q: %w", redirFilename, err) + } + if _, err := redirFile.WriteString(fmt.Sprintf("# %s\n", strings.Join(os.Args, " "))); err != nil { + return fmt.Errorf("unable to write to %q: %w", redirFilename, err) + } + for _, ri := range ris { + if redirTemplate.Execute(redirFile, ri) != nil { + return fmt.Errorf("unable to write %s to %q: %w", ri.Repo, redirFilename, err) + } + } + return nil +} + +var fileTemplate = template.Must(template.New("gohtml").Parse(goHTML)) +var redirTemplate = template.Must(template.New("redir").Parse(redirText)) + +// createGoGetFile creates a static HTML file providing a knative.dev mapping +// for the specified org and repo. +func createGoGetFile(ri repoInfo) error { + filename := fmt.Sprintf("golang/%s.html", ri.Repo) + file, err := os.Create(filename) + if err != nil { + return err + } + defer file.Close() + return fileTemplate.Execute(file, ri) +} + +func (ri repoInfo) String() string { + return ri.Org + "/" + ri.Repo +} + +func (ris riSlice) Len() int { + return len(ris) +} + +func (ris riSlice) Less(i, j int) bool { + return ris[i].Repo < ris[j].Repo +} + +func (ris riSlice) Swap(i, j int) { + ris[i], ris[j] = ris[j], ris[i] + +} diff --git a/tools/redir-gen/redirtemplate.gohtml b/tools/redir-gen/redirtemplate.gohtml new file mode 100644 index 000000000..9d3efa51e --- /dev/null +++ b/tools/redir-gen/redirtemplate.gohtml @@ -0,0 +1,4 @@ + + + +