From d3cf9818f879f3075c8f0a7aecf1bd64af779de0 Mon Sep 17 00:00:00 2001 From: The Magician Date: Thu, 23 Apr 2020 19:38:28 -0400 Subject: [PATCH] generate the sidebar (#3414) (#6192) * generate the sidebar * put back accidentally deleted lines * whitespace * empty commit Signed-off-by: Modular Magician --- .changelog/3414.txt | 3 + scripts/sidebar/sidebar.go | 112 ++ website/google.erb | 2778 +++++++++++++++++++++--------------- website/google.erb.tmpl | 70 + 4 files changed, 1781 insertions(+), 1182 deletions(-) create mode 100644 .changelog/3414.txt create mode 100644 scripts/sidebar/sidebar.go create mode 100644 website/google.erb.tmpl diff --git a/.changelog/3414.txt b/.changelog/3414.txt new file mode 100644 index 00000000000..ec13d79511a --- /dev/null +++ b/.changelog/3414.txt @@ -0,0 +1,3 @@ +```release-note:none +* This release includes website changes to put data sources and resources in submenus in t he products they're part of. +``` diff --git a/scripts/sidebar/sidebar.go b/scripts/sidebar/sidebar.go new file mode 100644 index 00000000000..d51f059ab58 --- /dev/null +++ b/scripts/sidebar/sidebar.go @@ -0,0 +1,112 @@ +//go:generate go run sidebar.go +package main + +import ( + "io/ioutil" + "log" + "os" + "path/filepath" + "regexp" + "runtime" + "strings" + "text/template" +) + +type Entry struct { + Filename string + Product string + Resource string +} + +type Entries struct { + Resources []Entry + DataSources []Entry +} + +func main() { + _, scriptPath, _, ok := runtime.Caller(0) + if !ok { + log.Fatal("Could not get current working directory") + } + tpgDir := scriptPath + for !strings.HasPrefix(filepath.Base(tpgDir), "terraform-provider-") && tpgDir != "/" { + tpgDir = filepath.Clean(tpgDir + "/..") + } + if tpgDir == "/" { + log.Fatal("Script was run outside of google provider directory") + } + + resourcesByProduct, err := entriesByProduct(tpgDir + "/website/docs/r") + if err != nil { + panic(err) + } + dataSourcesByProduct, err := entriesByProduct(tpgDir + "/website/docs/d") + if err != nil { + panic(err) + } + allEntriesByProduct := make(map[string]Entries) + for p, e := range resourcesByProduct { + v := allEntriesByProduct[p] + v.Resources = e + allEntriesByProduct[p] = v + } + for p, e := range dataSourcesByProduct { + v := allEntriesByProduct[p] + v.DataSources = e + allEntriesByProduct[p] = v + } + + tmpl, err := template.ParseFiles(tpgDir + "/website/google.erb.tmpl") + if err != nil { + panic(err) + } + f, err := os.Create(tpgDir + "/website/google.erb") + if err != nil { + panic(err) + } + defer f.Close() + err = tmpl.Execute(f, allEntriesByProduct) + if err != nil { + panic(err) + } +} + +func entriesByProduct(dir string) (map[string][]Entry, error) { + d, err := ioutil.ReadDir(dir) + if err != nil { + return nil, err + } + + entriesByProduct := make(map[string][]Entry) + for _, f := range d { + entry, err := getEntry(dir, f.Name()) + if err != nil { + return nil, err + } + entriesByProduct[entry.Product] = append(entriesByProduct[entry.Product], entry) + } + + return entriesByProduct, nil +} + +func getEntry(dir, filename string) (Entry, error) { + file, err := ioutil.ReadFile(dir + "/" + filename) + if err != nil { + return Entry{}, err + } + + return Entry{ + Filename: strings.TrimSuffix(filename, ".markdown"), + Product: findRegex(file, `subcategory: "(.*)"`), + Resource: findRegex(file, `page_title: "Google: (.*)"`), + }, nil +} + +func findRegex(contents []byte, regex string) string { + r := regexp.MustCompile(regex) + sm := r.FindStringSubmatch(string(contents)) + if len(sm) > 1 { + return sm[1] + } + return "" +} diff --git a/website/google.erb b/website/google.erb index 0bc87b9d1f2..10d56ef0875 100644 --- a/website/google.erb +++ b/website/google.erb @@ -30,1124 +30,1373 @@ -
  • - Provider Data Sources - -
  • - -
  • - Google Cloud Platform Resources - -
  • - - -
  • - App Engine - -
  • -
  • - BigQuery - -
  • - -
  • - BigQuery Data Transfer - -
  • - - -
  • - Binary Authorization - -
  • - -
  • - Cloud (Stackdriver) Logging - -
  • - -
  • - Cloud (Stackdriver) Monitoring - -
  • - -
  • - Cloud Bigtable - -
  • - -
  • - Cloud Build - -
  • - -
  • - Cloud Composer - -
  • - - -
  • - Cloud Deployment Manager - -
  • - -
  • - Cloud DNS - -
  • - -
  • - Cloud Endpoints - -
  • - -
  • - Cloud Functions - -
  • - -
  • - Cloud Healthcare - - -
  • - Cloud IoT Core - -
  • - -
  • - Cloud Key Management Service - -
  • - -
  • - Cloud Pub/Sub - -
  • - -
  • - Cloud Run - -
  • - - - -
  • - Cloud Source Repositories - -
  • - -
  • - Cloud Spanner - -
  • - -
  • - Cloud SQL - -
  • - -
  • - Cloud Storage - -
  • - -
  • - Cloud Tasks - -
  • - -
  • - Cloud TPU - -
  • - Compute Engine + Access Context Manager (VPC Service Controls) +
  • +
  • + App Engine + +
  • +
  • + BigQuery + +
  • +
  • + BigQuery Data Transfer + +
  • - +
  • + Binary Authorization + +
  • +
  • + Cloud (Stackdriver) Logging + +
  • +
  • + Cloud (Stackdriver) Monitoring + +
  • +
  • + Cloud Bigtable + +
  • +
  • + Cloud Build + +
  • +
  • + Cloud Composer + +
  • +
  • + Cloud DNS + +
  • +
  • + Cloud Deployment Manager + +
  • +
  • + Cloud Endpoints + +
  • +
  • + Cloud Functions + +
  • - +
  • + Cloud Healthcare + +
  • +
  • + Cloud IoT Core + +
  • +
  • + Cloud Key Management Service + +
  • +
  • + Cloud Platform + +
  • +
  • + Cloud Pub/Sub + +
  • +
  • + Cloud Run + +
  • +
  • + Cloud SQL + +
  • +
  • + Cloud Scheduler + +
  • +
  • + Cloud Source Repositories + +
  • +
  • + Cloud Spanner + +
  • +
  • + Cloud Storage + +
  • +
  • + Cloud TPU + +
  • +
  • + Cloud Tasks + +
  • +
  • + Compute Engine +
  • @@ -1156,10 +1405,32 @@ Container Registry @@ -1168,7 +1439,14 @@ Dataflow @@ -1177,39 +1455,30 @@ Dataproc @@ -1218,7 +1487,14 @@ Datastore @@ -1227,10 +1503,18 @@ Dialogflow @@ -1239,94 +1523,50 @@ Filestore -
  • - Firestore + Firebase
  • - -
  • - Identity-Aware Proxy + Firestore
  • @@ -1335,37 +1575,120 @@ Identity Platform
  • - Kubernetes (Container) Engine + Identity-Aware Proxy +
  • +
  • + Kubernetes (Container) Engine +
  • @@ -1374,7 +1697,14 @@ ML Engine @@ -1383,7 +1713,14 @@ Memorystore (Redis) @@ -1392,39 +1729,86 @@ OS Login
  • - Runtime Configurator + Resource Manager +
  • +
  • + Runtime Configurator + +
  • +
  • + Secret Manager +
  • -
  • Security Command Center (SCC)
  • @@ -1433,31 +1817,61 @@ Serverless VPC Access -
  • Service Networking
  • -
  • - Storage Transfer + Storage Transfer Service
  • + <% end %> diff --git a/website/google.erb.tmpl b/website/google.erb.tmpl new file mode 100644 index 00000000000..6032cf5b2e1 --- /dev/null +++ b/website/google.erb.tmpl @@ -0,0 +1,70 @@ +<% wrap_layout :inner do %> + <% content_for :sidebar do %> + + <% end %> + +<%= yield %> + <% end %>