1
0
mirror of https://github.com/golang/go synced 2024-11-05 17:46:16 -07:00

go.tools/godoc/blog: add PlayEnabled and GodocURL options

Also make NewServer take a Config, not *Config.

R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/13755044
This commit is contained in:
Andrew Gerrand 2013-09-18 14:59:34 +10:00
parent 72d39cf585
commit 03c8be29db

View File

@ -33,12 +33,15 @@ type Config struct {
ContentPath string // Relative or absolute location of article files and related content. ContentPath string // Relative or absolute location of article files and related content.
TemplatePath string // Relative or absolute location of template files. TemplatePath string // Relative or absolute location of template files.
BaseURL string // Absolute base URL (for permalinks; no trailing slash). BaseURL string // Absolute base URL (for permalinks; no trailing slash).
BasePath string // Base URL path relative to server root (no trailing slash). BasePath string // Base URL path relative to server root (no trailing slash).
HomeArticles int // Articles to display on the home page. GodocURL string // The base URL of godoc (for menu bar; no trailing slash).
Hostname string // Server host name, used for rendering ATOM feeds.
Hostname string // Server host name, used for rendering ATOM feeds. HomeArticles int // Articles to display on the home page.
FeedArticles int // Articles to include in Atom and JSON feeds. FeedArticles int // Articles to include in Atom and JSON feeds.
PlayEnabled bool
} }
// Doc represents an article adorned with presentation data. // Doc represents an article adorned with presentation data.
@ -54,7 +57,7 @@ type Doc struct {
// Server implements an http.Handler that serves blog articles. // Server implements an http.Handler that serves blog articles.
type Server struct { type Server struct {
cfg *Config cfg Config
docs []*Doc docs []*Doc
tags []string tags []string
docPaths map[string]*Doc // key is path without BasePath. docPaths map[string]*Doc // key is path without BasePath.
@ -68,8 +71,8 @@ type Server struct {
} }
// NewServer constructs a new Server using the specified config. // NewServer constructs a new Server using the specified config.
func NewServer(cfg *Config) (*Server, error) { func NewServer(cfg Config) (*Server, error) {
present.PlayEnabled = true present.PlayEnabled = cfg.PlayEnabled
root := filepath.Join(cfg.TemplatePath, "root.tmpl") root := filepath.Join(cfg.TemplatePath, "root.tmpl")
parse := func(name string) (*template.Template, error) { parse := func(name string) (*template.Template, error) {
@ -363,6 +366,7 @@ func summary(d *Doc) string {
type rootData struct { type rootData struct {
Doc *Doc Doc *Doc
BasePath string BasePath string
GodocURL string
Data interface{} Data interface{}
} }
@ -370,7 +374,7 @@ type rootData struct {
// as well as the ATOM and JSON feeds. // as well as the ATOM and JSON feeds.
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
var ( var (
d = rootData{BasePath: s.cfg.BasePath} d = rootData{BasePath: s.cfg.BasePath, GodocURL: s.cfg.GodocURL}
t *template.Template t *template.Template
) )
switch p := strings.TrimPrefix(r.URL.Path, s.cfg.BasePath); p { switch p := strings.TrimPrefix(r.URL.Path, s.cfg.BasePath); p {