diff options
author | Jaewoong Jung <jungjw@google.com> | 2019-02-22 13:44:38 -0800 |
---|---|---|
committer | Jaewoong Jung <jungjw@google.com> | 2019-02-25 10:26:46 -0800 |
commit | 90e115513597b72f54f220575a9076a4abef8425 (patch) | |
tree | 731b5584e68468032921c3b21e6204ca31e9901f | |
parent | e608a51b06031d3765541859068a2be298d19374 (diff) | |
download | build_soong-90e115513597b72f54f220575a9076a4abef8425.tar.gz build_soong-90e115513597b72f54f220575a9076a4abef8425.tar.bz2 build_soong-90e115513597b72f54f220575a9076a4abef8425.zip |
soong_docs build link error fix.
This adds a script to copy the current page's base url to hrefs in the
doc.
Fixes: 123473548
Test: m soong_docs
Change-Id: I8a8ac0f9ba6c0d57ed83db2155955a95e070a265
-rw-r--r-- | cmd/soong_build/writedocs.go | 54 |
1 files changed, 33 insertions, 21 deletions
diff --git a/cmd/soong_build/writedocs.go b/cmd/soong_build/writedocs.go index de2182fe..e86ef827 100644 --- a/cmd/soong_build/writedocs.go +++ b/cmd/soong_build/writedocs.go @@ -108,14 +108,9 @@ func writeDocs(ctx *android.Context, filename string) error { } // Produce the top-level, package list page first. - tmpl, err := template.New("file").Parse(packageListTemplate) - if err != nil { - return err - } + tmpl := template.Must(template.Must(template.New("file").Parse(packageListTemplate)).Parse(copyBaseUrl)) buf := &bytes.Buffer{} - if err == nil { - err = tmpl.Execute(buf, packages) - } + err = tmpl.Execute(buf, packages) if err == nil { err = ioutil.WriteFile(filename, buf.Bytes(), 0666) } @@ -125,18 +120,16 @@ func writeDocs(ctx *android.Context, filename string) error { // We need a module name getter/setter function because I couldn't // find a way to keep it in a variable defined within the template. currentModuleName := "" - tmpl, err := template.New("file").Funcs(map[string]interface{}{ - "setModule": func(moduleName string) string { - currentModuleName = moduleName - return "" - }, - "getModule": func() string { - return currentModuleName - }, - }).Parse(perPackageTemplate) - if err != nil { - return err - } + tmpl := template.Must( + template.Must(template.New("file").Funcs(map[string]interface{}{ + "setModule": func(moduleName string) string { + currentModuleName = moduleName + return "" + }, + "getModule": func() string { + return currentModuleName + }, + }).Parse(perPackageTemplate)).Parse(copyBaseUrl)) buf := &bytes.Buffer{} modules := moduleTypeDocsToTemplates(pkg.ModuleTypes) data := perPackageTemplateData{Name: pkg.Name, Modules: modules} @@ -173,6 +166,7 @@ td { word-wrap:break-word; } </style> +{{template "copyBaseUrl"}} </head> <body> <div id="main"> @@ -203,9 +197,7 @@ files for the Soong build system. </body> </html> ` -) -const ( perPackageTemplate = ` <html> <head> @@ -243,6 +235,7 @@ li a:hover:not(.active) { color: white; } </style> +{{template "copyBaseUrl"}} </head> <body> {{- /* Fixed sidebar with module types */ -}} @@ -309,4 +302,23 @@ li a:hover:not(.active) { </script> </body> ` + + copyBaseUrl = ` +{{define "copyBaseUrl"}} +<script type="text/javascript"> +window.addEventListener('message', (e) => { + if (e != null && e.data != null && e.data.type === "SET_BASE" && e.data.base != null) { + const existingBase = document.querySelector('base'); + if (existingBase != null) { + existingBase.parentElement.removeChild(existingBase); + } + + const base = document.createElement('base'); + base.setAttribute('href', e.data.base); + document.head.appendChild(base); + } +}); +</script> +{{end}} +` ) |