StaticGen update Bash
Update zh-cn.yaml (#194) Address #184 build assets Update zh-cn.yaml (#194) Former-commit-id: 4572f93371647c0a6b53cc375ec5bb00356a37c9 [formerly e58e4793ac0ca6915b605d7b2a8a77f0aec31172] [formerly 43635f6b98f546ec0e2656d26031388aef63a902 [formerly da4fd84002f4cac1d4e04f65c96237a553203d83]] Former-commit-id: 15422887ad29dea63bdf861d9da8f8d28b4fbc8f [formerly 3949ffa499cf999c3f4b50ee18802c0f87a23807] Former-commit-id: fac5ceeee3fa969239d9ef5e04ef5542a61d2761
This commit is contained in:
62
http.go
62
http.go
@@ -58,28 +58,11 @@ func serveHTTP(c *RequestContext, w http.ResponseWriter, r *http.Request) (int,
|
||||
return apiHandler(c, w, r)
|
||||
}
|
||||
|
||||
// Checks if any plugin has an handler for this URL.
|
||||
for p := range c.Plugins {
|
||||
var h PluginHandler
|
||||
|
||||
for path, handler := range plugins[p].Handlers {
|
||||
if strings.HasPrefix(r.URL.Path, path) {
|
||||
h = handler
|
||||
r.URL.Path = strings.TrimPrefix(r.URL.Path, path)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if h == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
valid, _ := validateAuth(c, r)
|
||||
if !valid {
|
||||
return http.StatusForbidden, nil
|
||||
}
|
||||
|
||||
return h(c, w, r)
|
||||
// If it is a request to the preview and a static website generator is
|
||||
// active, build the preview.
|
||||
if strings.HasPrefix(r.URL.Path, "/preview") && c.StaticGen != nil {
|
||||
r.URL.Path = strings.TrimPrefix(r.URL.Path, "/preview")
|
||||
return c.StaticGen.Preview(c, w, r)
|
||||
}
|
||||
|
||||
// Any other request should show the index.html file.
|
||||
@@ -131,12 +114,15 @@ func apiHandler(c *RequestContext, w http.ResponseWriter, r *http.Request) (int,
|
||||
return http.StatusForbidden, nil
|
||||
}
|
||||
|
||||
for p := range c.Plugins {
|
||||
if plugins[p].BeforeAPI == nil {
|
||||
continue
|
||||
if c.StaticGen != nil {
|
||||
// If we are using the 'magic url' for the settings,
|
||||
// we should redirect the request for the acutual path.
|
||||
if r.URL.Path == "/settings" {
|
||||
r.URL.Path = c.StaticGen.SettingsPath()
|
||||
}
|
||||
|
||||
code, err := plugins[p].BeforeAPI(c, w, r)
|
||||
// Executes the Static website generator hook.
|
||||
code, err := c.StaticGen.Hook(c, w, r)
|
||||
if code != 0 || err != nil {
|
||||
return code, err
|
||||
}
|
||||
@@ -172,21 +158,6 @@ func apiHandler(c *RequestContext, w http.ResponseWriter, r *http.Request) (int,
|
||||
code = http.StatusNotFound
|
||||
}
|
||||
|
||||
if code >= 300 || err != nil {
|
||||
return code, err
|
||||
}
|
||||
|
||||
for p := range c.Plugins {
|
||||
if plugins[p].AfterAPI == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
code, err := plugins[p].AfterAPI(c, w, r)
|
||||
if code != 0 || err != nil {
|
||||
return code, err
|
||||
}
|
||||
}
|
||||
|
||||
return code, err
|
||||
}
|
||||
|
||||
@@ -227,14 +198,9 @@ func renderFile(w http.ResponseWriter, file string, contentType string, c *Reque
|
||||
tpl := template.Must(template.New("file").Parse(file))
|
||||
w.Header().Set("Content-Type", contentType+"; charset=utf-8")
|
||||
|
||||
var javascript = ""
|
||||
for name := range c.Plugins {
|
||||
javascript += plugins[name].JavaScript + "\n"
|
||||
}
|
||||
|
||||
err := tpl.Execute(w, map[string]interface{}{
|
||||
"BaseURL": c.RootURL(),
|
||||
"JavaScript": template.JS(javascript),
|
||||
"BaseURL": c.RootURL(),
|
||||
"StaticGen": c.staticgen,
|
||||
})
|
||||
if err != nil {
|
||||
return http.StatusInternalServerError, err
|
||||
|
||||
Reference in New Issue
Block a user