aboutsummaryrefslogtreecommitdiff
path: root/blog
diff options
context:
space:
mode:
authorDmitri Shuralyov <dmitshur@golang.org>2019-10-01 18:52:16 -0400
committerDmitri Shuralyov <dmitshur@golang.org>2019-10-02 16:18:51 +0000
commit3769738f410bfa407254646cfd352f867d0281f6 (patch)
treeab8391c369f675280cda7afec18f7474a1007a74 /blog
parent329c8d646ebe56d31ab9699c2223c7daf1d77991 (diff)
downloadgolang-x-tools-3769738f410bfa407254646cfd352f867d0281f6.tar.gz
blog: add support for optional analytics HTML
This change makes it possible for users of the blog package to provide analytics HTML, which can then be inserted on pages. Previously, this was possible by making ad-hoc modifications to the template files. It's easier to have a dedicated field. Change-Id: Id7c24dc9c7b5b9e23d18f3987f2f1af27c709681 Reviewed-on: https://go-review.googlesource.com/c/tools/+/198323 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'blog')
-rw-r--r--blog/blog.go24
1 files changed, 15 insertions, 9 deletions
diff --git a/blog/blog.go b/blog/blog.go
index 73c184d4b..11b95c9f5 100644
--- a/blog/blog.go
+++ b/blog/blog.go
@@ -38,10 +38,11 @@ type Config struct {
ContentPath string // Relative or absolute location of article files and related content.
TemplatePath string // Relative or absolute location of template files.
- BaseURL string // Absolute base URL (for permalinks; no trailing slash).
- BasePath string // Base URL path relative to server root (no trailing slash).
- GodocURL string // The base URL of godoc (for menu bar; no trailing slash).
- Hostname string // Server host name, used for rendering ATOM feeds.
+ BaseURL string // Absolute base URL (for permalinks; no trailing slash).
+ BasePath string // Base URL path relative to server root (no trailing slash).
+ GodocURL string // The base URL of godoc (for menu bar; no trailing slash).
+ Hostname string // Server host name, used for rendering ATOM feeds.
+ AnalyticsHTML template.HTML // Optional analytics HTML to insert at the beginning of <head>.
HomeArticles int // Articles to display on the home page.
FeedArticles int // Articles to include in Atom and JSON feeds.
@@ -379,17 +380,22 @@ func summary(d *Doc) string {
// rootData encapsulates data destined for the root template.
type rootData struct {
- Doc *Doc
- BasePath string
- GodocURL string
- Data interface{}
+ Doc *Doc
+ BasePath string
+ GodocURL string
+ AnalyticsHTML template.HTML
+ Data interface{}
}
// ServeHTTP serves the front, index, and article pages
// as well as the ATOM and JSON feeds.
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
var (
- d = rootData{BasePath: s.cfg.BasePath, GodocURL: s.cfg.GodocURL}
+ d = rootData{
+ BasePath: s.cfg.BasePath,
+ GodocURL: s.cfg.GodocURL,
+ AnalyticsHTML: s.cfg.AnalyticsHTML,
+ }
t *template.Template
)
switch p := strings.TrimPrefix(r.URL.Path, s.cfg.BasePath); p {