mirror of
https://github.com/documize/community.git
synced 2025-07-18 20:59:43 +02:00
Fix regression for robots.txt and sitemap.xml
This commit is contained in:
parent
e0e3f0c141
commit
6993dc678f
2 changed files with 18 additions and 4 deletions
|
@ -48,8 +48,8 @@ func WriteServerError(w http.ResponseWriter, method string, err error) {
|
|||
|
||||
// WriteError notifies HTTP client of general application error.
|
||||
func WriteError(w http.ResponseWriter, method string) {
|
||||
writeStatus(w, http.StatusBadRequest)
|
||||
w.Write([]byte("{Error: 'Internal server error'}"))
|
||||
writeStatus(w, http.StatusBadRequest)
|
||||
w.Write([]byte("{Error: 'Internal server error'}"))
|
||||
}
|
||||
|
||||
// WriteDuplicateError notifies HTTP client of duplicate data that has been rejected.
|
||||
|
@ -114,3 +114,17 @@ func WriteJSON(w http.ResponseWriter, v interface{}) {
|
|||
j, _ := json.Marshal(v)
|
||||
w.Write(j)
|
||||
}
|
||||
|
||||
// WriteText to HTTP response
|
||||
func WriteText(w http.ResponseWriter, data []byte) {
|
||||
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write(data)
|
||||
}
|
||||
|
||||
// WriteXML to HTTP response
|
||||
func WriteXML(w http.ResponseWriter, data []byte) {
|
||||
w.Header().Set("Content-Type", "application/xml; charset=utf-8")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write(data)
|
||||
}
|
||||
|
|
|
@ -138,7 +138,7 @@ Disallow: /attachment/*
|
|||
Sitemap: %s`, sitemap)
|
||||
}
|
||||
|
||||
response.WriteBytes(w, []byte(robots))
|
||||
response.WriteText(w, []byte(robots))
|
||||
}
|
||||
|
||||
// Sitemap returns URLs that can be indexed.
|
||||
|
@ -205,7 +205,7 @@ func (h *Handler) Sitemap(w http.ResponseWriter, r *http.Request) {
|
|||
t := template.Must(template.New("tmp").Parse(sitemap))
|
||||
t.Execute(buffer, &items)
|
||||
|
||||
response.WriteBytes(w, buffer.Bytes())
|
||||
response.WriteXML(w, buffer.Bytes())
|
||||
}
|
||||
|
||||
type sitemapItem struct {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue