Post is working now

This commit is contained in:
2023-11-20 21:58:11 +01:00
parent 201579ad87
commit 477db1afa0
2 changed files with 12 additions and 9 deletions

View File

@@ -71,7 +71,7 @@ const editorTemplate = `
<input type="text" name="title" placeholder="Naslov" value="{{.Title}}" /> <input type="text" name="title" placeholder="Naslov" value="{{.Title}}" />
<input name="ID" type="hidden" value="{{.ID}}" /> <input name="ID" type="hidden" value="{{.ID}}" />
<div id="editorcontainer"> <div id="editorcontainer">
<textarea id="editor">{{.GemtextContent}}</textarea> <textarea id="editor" name="editor">{{.GemtextContent.String}}</textarea>
</div> </div>
<input type="submit" value="Sačuvaj" /> <input type="submit" value="Sačuvaj" />
</form> </form>
@@ -85,6 +85,16 @@ const editorTemplate = `
` `
func editorHtml5Page(post *database.Post) string { func editorHtml5Page(post *database.Post) string {
if post.GemtextContent.Valid {
if strings.HasPrefix(post.GemtextContent.String, "{") {
post.GemtextContent.String = strings.TrimPrefix(post.GemtextContent.String, "{")
}
if strings.HasSuffix(post.GemtextContent.String, "true}") {
post.GemtextContent.String = strings.TrimSuffix(post.GemtextContent.String, "true}")
}
} else {
post.GemtextContent.String = ""
}
t1 := template.New("editorHtml5Page") t1 := template.New("editorHtml5Page")
t1, _ = t1.Parse(editorTemplate) t1, _ = t1.Parse(editorTemplate)
result := new(strings.Builder) result := new(strings.Builder)

View File

@@ -27,14 +27,6 @@ func (p *Post) HTMLPage() string {
var content string var content string
if p.GemtextContent.Valid { if p.GemtextContent.Valid {
content = p.GemtextContent.String content = p.GemtextContent.String
if strings.HasPrefix(content, "{") {
content = strings.TrimPrefix(content, "{")
}
if strings.HasSuffix(content, "true}") {
content = strings.TrimSuffix(content, "true}")
}
} else {
content = ""
} }
lines := strings.Split(content, "\n") lines := strings.Split(content, "\n")
@@ -61,6 +53,7 @@ func (p *Post) HTMLPage() string {
url := parts[0] url := parts[0]
htmlLines = append(htmlLines, fmt.Sprintf(`<a href="%s.html">%s</a>`, url, url)) htmlLines = append(htmlLines, fmt.Sprintf(`<a href="%s.html">%s</a>`, url, url))
} }
} else { } else {
htmlLines = append(htmlLines, "<p>"+line+"</p>") htmlLines = append(htmlLines, "<p>"+line+"</p>")
} }