Add baseurl

This commit is contained in:
Peter Stuifzand 2020-06-09 20:36:41 +02:00
parent 354c6ea294
commit 5be5548634
3 changed files with 5 additions and 4 deletions

View File

@ -8,10 +8,11 @@ import (
type editorJsJson struct { type editorJsJson struct {
Page string Page string
ContentType string ContentType string
BaseURL string
Data template.JS Data template.JS
} }
func renderEditor(pageName, inputText, contentType string) (template.HTML, error) { func renderEditor(pageName, inputText, contentType string, baseurl string) (template.HTML, error) {
if contentType == "json" { if contentType == "json" {
t, err := template.ParseFiles("templates/editorjs.html") t, err := template.ParseFiles("templates/editorjs.html")
if err != nil { if err != nil {
@ -20,7 +21,7 @@ func renderEditor(pageName, inputText, contentType string) (template.HTML, error
if inputText == "" { if inputText == "" {
inputText = "null" inputText = "null"
} }
data := editorJsJson{Page: pageName, Data: template.JS(inputText), ContentType: contentType} data := editorJsJson{Page: pageName, Data: template.JS(inputText), ContentType: contentType, BaseURL: baseurl}
var buf bytes.Buffer var buf bytes.Buffer
err = t.Execute(&buf, data) err = t.Execute(&buf, data)
if err != nil { if err != nil {

View File

@ -384,7 +384,7 @@ func (h *editHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
var editor template.HTML var editor template.HTML
if jsonEditor { if jsonEditor {
editor, err = renderEditor(page, pageText, "json") editor, err = renderEditor(page, pageText, "json", *baseurl)
if err != nil { if err != nil {
http.Error(w, err.Error(), 500) http.Error(w, err.Error(), 500)
return return

View File

@ -1 +1 @@
<div id="editor" data-input="{{ .Data }}" data-saveurl="/save/" data-page="{{ .Page }}" save-type="{{ .ContentType }}"></div> <div id="editor" data-input="{{ .Data }}" data-saveurl="/save/" data-base-url="{{ .BaseURL }}" data-page="{{ .Page }}" save-type="{{ .ContentType }}"></div>