internal/frontend: add split documentation sections to the unit page struct
Adds sections for doc body, doc outline, and mobile outline
to the unit page struct for documentaion rendering
Change-Id: I68e89679d2664714b05cf1a65ab9d9d17756d330
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/256038
Trust: Jamal Carvalho <jamal@golang.org>
Run-TryBot: Jamal Carvalho <jamal@golang.org>
Reviewed-by: Julie Qiu <julie@golang.org>
TryBot-Result: kokoro <noreply+kokoro@google.com>
diff --git a/internal/frontend/unit.go b/internal/frontend/unit.go
index 6aeec90..b34a5bc 100644
--- a/internal/frontend/unit.go
+++ b/internal/frontend/unit.go
@@ -11,6 +11,7 @@
"github.com/google/safehtml"
"golang.org/x/pkgsite/internal"
"golang.org/x/pkgsite/internal/derrors"
+ "golang.org/x/pkgsite/internal/godoc"
"golang.org/x/pkgsite/internal/middleware"
"golang.org/x/pkgsite/internal/stdlib"
)
@@ -71,6 +72,10 @@
// Settings contains settings for the selected tab.
SelectedTab TabSettings
+
+ DocBody *safehtml.HTML
+ DocOutline *safehtml.HTML
+ MobileOutline *safehtml.HTML
}
var (
@@ -138,6 +143,25 @@
return err
}
+ var docBody, docOutline, mobileOutline *safehtml.HTML
+ if unit.Documentation != nil {
+ b, err := godoc.Parse(unit.Documentation.HTML, godoc.BodySection)
+ if err != nil {
+ return err
+ }
+ docBody = &b
+ o, err := godoc.Parse(unit.Documentation.HTML, godoc.SidenavSection)
+ if err != nil {
+ return err
+ }
+ docOutline = &o
+ m, err := godoc.Parse(unit.Documentation.HTML, godoc.SidenavMobileSection)
+ if err != nil {
+ return err
+ }
+ mobileOutline = &m
+ }
+
tab := r.FormValue("tab")
if tab == "" {
// Default to details tab when there is no tab param.
@@ -179,6 +203,9 @@
UnitContentName: tabSettings.DisplayName,
Readme: readme,
ExpandReadme: expandReadme,
+ DocOutline: docOutline,
+ DocBody: docBody,
+ MobileOutline: mobileOutline,
}
s.servePage(ctx, w, tabSettings.TemplateName, page)
@@ -208,7 +235,6 @@
}
return &readme, nil
}
-
return nil, nil
}