|
|
@ -29,22 +29,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
package main
|
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"errors"
|
|
|
|
"io/ioutil"
|
|
|
|
"io/ioutil"
|
|
|
|
|
|
|
|
"os"
|
|
|
|
"regexp"
|
|
|
|
"regexp"
|
|
|
|
"errors"
|
|
|
|
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func prepare_paste_page(title, date, content, templ_dir string) (string, error) {
|
|
|
|
func prepare_paste_page(c *Config, paste_ID string) (string, error) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
s := ""
|
|
|
|
s := ""
|
|
|
|
|
|
|
|
|
|
|
|
// insert header
|
|
|
|
// insert header
|
|
|
|
|
|
|
|
|
|
|
|
head_file := c.templ_dir + "/header.html"
|
|
|
|
head_file := templ_dir + "/header.html"
|
|
|
|
|
|
|
|
|
|
|
|
f_head, err := os.Open(head_file)
|
|
|
|
f_head, err := os.Open(head_file)
|
|
|
|
defer f_head.Close()
|
|
|
|
defer f_head.Close()
|
|
|
@ -58,28 +56,23 @@ func prepare_paste_page(c *Config, paste_ID string) (string, error) {
|
|
|
|
|
|
|
|
|
|
|
|
// insert content
|
|
|
|
// insert content
|
|
|
|
|
|
|
|
|
|
|
|
cont_file := c.paste_dir + "/" + paste_ID
|
|
|
|
|
|
|
|
f_cont, err := os.Open(cont_file)
|
|
|
|
|
|
|
|
defer f_cont.Close()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if err == nil {
|
|
|
|
|
|
|
|
// Let's read the content of the paste
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cont, err := ioutil.ReadFile(cont_file)
|
|
|
|
|
|
|
|
if err == nil {
|
|
|
|
|
|
|
|
paste_buf := string(cont)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ...Let's read the template
|
|
|
|
// ...Let's read the template
|
|
|
|
templ_file := c.templ_dir + "/templ.html"
|
|
|
|
templ_file := templ_dir + "/templ.html"
|
|
|
|
f_templ, err := os.Open(templ_file)
|
|
|
|
f_templ, err := os.Open(templ_file)
|
|
|
|
defer f_templ.Close()
|
|
|
|
defer f_templ.Close()
|
|
|
|
|
|
|
|
|
|
|
|
cont, err := ioutil.ReadFile(templ_file)
|
|
|
|
|
|
|
|
if err == nil {
|
|
|
|
if cont, err := ioutil.ReadFile(templ_file); err == nil {
|
|
|
|
tmpl := string(cont)
|
|
|
|
tmpl := string(cont)
|
|
|
|
// ...and replace {{CONTENT}} with the paste itself!
|
|
|
|
// ...and replace {{CONTENT}} with the paste itself!
|
|
|
|
re,_ := regexp.Compile("{{CONTENT}}")
|
|
|
|
re, _ := regexp.Compile("{{TITLE}}")
|
|
|
|
tmpl = string(re.ReplaceAll([]byte(tmpl), []byte(paste_buf)))
|
|
|
|
tmpl = string(re.ReplaceAll([]byte(tmpl), []byte(title)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
re, _ = regexp.Compile("{{DATE}}")
|
|
|
|
|
|
|
|
tmpl = string(re.ReplaceAll([]byte(tmpl), []byte(date)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
re, _ = regexp.Compile("{{CONTENT}}")
|
|
|
|
|
|
|
|
tmpl = string(re.ReplaceAll([]byte(tmpl), []byte(content)))
|
|
|
|
|
|
|
|
|
|
|
|
s += tmpl
|
|
|
|
s += tmpl
|
|
|
|
|
|
|
|
|
|
|
@ -87,12 +80,8 @@ func prepare_paste_page(c *Config, paste_ID string) (string, error) {
|
|
|
|
return "", errors.New("Error opening template file")
|
|
|
|
return "", errors.New("Error opening template file")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
return "", errors.New("Error opening paste")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// insert footer
|
|
|
|
// insert footer
|
|
|
|
foot_file := c.templ_dir + "/footer.html"
|
|
|
|
foot_file := templ_dir + "/footer.html"
|
|
|
|
f_foot, err := os.Open(foot_file)
|
|
|
|
f_foot, err := os.Open(foot_file)
|
|
|
|
defer f_foot.Close()
|
|
|
|
defer f_foot.Close()
|
|
|
|
|
|
|
|
|
|
|
|