mirror of
https://github.com/Eggbertx/gochan.git
synced 2025-08-17 10:56:24 -07:00
Replace strings.ReplaceAll with strings.Replace for compatibility
This commit is contained in:
parent
55317504a1
commit
e375750e97
7 changed files with 20 additions and 38 deletions
2
go.mod
2
go.mod
|
@ -12,6 +12,6 @@ require (
|
|||
github.com/nranchev/go-libGeoIP v0.0.0-20170629073846-d6d4a9a4c7e8 // indirect
|
||||
github.com/tdewolff/minify v2.3.6+incompatible
|
||||
github.com/tdewolff/parse v2.3.4+incompatible // indirect
|
||||
golang.org/x/crypto v0.0.0-20200707235045-ab33eee955e0
|
||||
golang.org/x/crypto v0.0.0-20200709230013-948cd5f35899
|
||||
golang.org/x/net v0.0.0-20200707034311-ab3426394381
|
||||
)
|
||||
|
|
2
go.sum
2
go.sum
|
@ -37,6 +37,8 @@ golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnk
|
|||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20200707235045-ab33eee955e0 h1:eIYIE7EC5/Wv5Kbz8bJPaq+TN3kq3W8S+LSm62vM0DY=
|
||||
golang.org/x/crypto v0.0.0-20200707235045-ab33eee955e0/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20200709230013-948cd5f35899 h1:DZhuSZLsGlFL4CmhA8BcRA0mnthyA/nZ00AqCUo7vHg=
|
||||
golang.org/x/crypto v0.0.0-20200709230013-948cd5f35899/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/image v0.0.0-20190501045829-6d32002ffd75/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
|
||||
golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8 h1:hVwzHzIUGRjiF7EcUjqNxk3NCfkPxbDKRdnNE1Rpg0U=
|
||||
golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
|
||||
|
|
|
@ -3,7 +3,6 @@ package building
|
|||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
|
||||
|
@ -92,32 +91,11 @@ func BuildBoardListJSON() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// BuildJS minifies (if enabled) gochan.js and consts.js (the latter is built from a template)
|
||||
// BuildJS minifies (if enabled) consts.js, which is built from a template
|
||||
func BuildJS() error {
|
||||
// minify gochan.js (if enabled)
|
||||
gochanMinJSPath := path.Join(config.Config.DocumentRoot, "javascript", "gochan.min.js")
|
||||
gochanMinJSFile, err := os.OpenFile(gochanMinJSPath, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0644)
|
||||
if err != nil {
|
||||
return errors.New(gclog.Printf(gclog.LErrorLog,
|
||||
"Error opening %q for writing: %s", gochanMinJSPath, err.Error()))
|
||||
}
|
||||
defer gochanMinJSFile.Close()
|
||||
|
||||
gochanJSPath := path.Join(config.Config.DocumentRoot, "javascript", "gochan.js")
|
||||
gochanJSBytes, err := ioutil.ReadFile(gochanJSPath)
|
||||
if err != nil {
|
||||
return errors.New(gclog.Printf(gclog.LErrorLog,
|
||||
"Error opening %q for writing: %s", gochanJSPath, err.Error()))
|
||||
}
|
||||
if _, err = gcutil.MinifyWriter(gochanMinJSFile, gochanJSBytes, "text/javascript"); err != nil {
|
||||
config.Config.UseMinifiedGochanJS = false
|
||||
return errors.New(gclog.Printf(gclog.LErrorLog,
|
||||
"Error minifying %q: %s:", gochanMinJSPath, err.Error()))
|
||||
}
|
||||
config.Config.UseMinifiedGochanJS = true
|
||||
|
||||
// build consts.js from template
|
||||
if err = gctemplates.InitTemplates("js"); err != nil {
|
||||
err := gctemplates.InitTemplates("js")
|
||||
if err != nil {
|
||||
return errors.New(gclog.Println(gclog.LErrorLog,
|
||||
"Error loading consts.js template:", err.Error()))
|
||||
}
|
||||
|
|
|
@ -12,7 +12,10 @@ import (
|
|||
"github.com/gochan-org/gochan/pkg/gclog"
|
||||
)
|
||||
|
||||
var Config GochanConfig
|
||||
var (
|
||||
Config GochanConfig
|
||||
cfgPath string
|
||||
)
|
||||
|
||||
// Style represents a theme (Pipes, Dark, etc)
|
||||
type Style struct {
|
||||
|
@ -82,9 +85,8 @@ type GochanConfig struct {
|
|||
NewTabOnOutlinks bool `description:"If checked, links to external sites will open in a new tab." default:"checked"`
|
||||
DisableBBcode bool `description:"If checked, gochan will not compile bbcode into HTML" default:"unchecked"`
|
||||
|
||||
MinifyHTML bool `description:"If checked, gochan will minify html files when building" default:"checked"`
|
||||
MinifyJS bool `description:"If checked, gochan will minify js and json files when building" default:"checked"`
|
||||
UseMinifiedGochanJS bool `json:"-"`
|
||||
MinifyHTML bool `description:"If checked, gochan will minify html files when building" default:"checked"`
|
||||
MinifyJS bool `description:"If checked, gochan will minify js and json files when building" default:"checked"`
|
||||
|
||||
DateTimeFormat string `description:"The format used for dates. See <a href=\"https://golang.org/pkg/time/#Time.Format\">here</a> for more info." default:"Mon, January 02, 2006 15:04 PM"`
|
||||
AkismetAPIKey string `description:"The API key to be sent to Akismet for post spam checking. If the key is invalid, Akismet won't be used."`
|
||||
|
@ -134,7 +136,7 @@ func (cfg *GochanConfig) checkInt(val, defaultVal int, critical bool, msg string
|
|||
|
||||
// InitConfig loads and parses gochan.json and verifies its contents
|
||||
func InitConfig(versionStr string) {
|
||||
cfgPath := findResource("gochan.json", "/etc/gochan/gochan.json")
|
||||
cfgPath = findResource("gochan.json", "/etc/gochan/gochan.json")
|
||||
if cfgPath == "" {
|
||||
fmt.Println("gochan.json not found")
|
||||
os.Exit(1)
|
||||
|
|
|
@ -93,9 +93,9 @@ func MakePost(writer http.ResponseWriter, request *http.Request) {
|
|||
post.Password = gcutil.Md5Sum(password)
|
||||
|
||||
// Reverse escapes
|
||||
nameCookie = strings.ReplaceAll(formName, "&", "&")
|
||||
nameCookie = strings.ReplaceAll(nameCookie, "\\'", "'")
|
||||
nameCookie = strings.ReplaceAll(url.QueryEscape(nameCookie), "+", "%20")
|
||||
nameCookie = strings.Replace(formName, "&", "&", -1)
|
||||
nameCookie = strings.Replace(nameCookie, "\\'", "'", -1)
|
||||
nameCookie = strings.Replace(url.QueryEscape(nameCookie), "+", "%20", -1)
|
||||
|
||||
// add name and email cookies that will expire in a year (31536000 seconds)
|
||||
http.SetCookie(writer, &http.Cookie{Name: "name", Value: nameCookie, MaxAge: yearInSeconds})
|
||||
|
@ -223,8 +223,8 @@ func MakePost(writer http.ResponseWriter, request *http.Request) {
|
|||
}
|
||||
boardDir := _board.Dir
|
||||
filePath = path.Join(config.Config.DocumentRoot, "/"+boardDir+"/src/", post.Filename)
|
||||
thumbPath = path.Join(config.Config.DocumentRoot, "/"+boardDir+"/thumb/", strings.ReplaceAll(post.Filename, "."+filetype, "t."+thumbFiletype))
|
||||
catalogThumbPath = path.Join(config.Config.DocumentRoot, "/"+boardDir+"/thumb/", strings.ReplaceAll(post.Filename, "."+filetype, "c."+thumbFiletype))
|
||||
thumbPath = path.Join(config.Config.DocumentRoot, "/"+boardDir+"/thumb/", strings.Replace(post.Filename, "."+filetype, "t."+thumbFiletype, -1))
|
||||
catalogThumbPath = path.Join(config.Config.DocumentRoot, "/"+boardDir+"/thumb/", strings.Replace(post.Filename, "."+filetype, "c."+thumbFiletype, -1))
|
||||
|
||||
if err = ioutil.WriteFile(filePath, data, 0777); err != nil {
|
||||
gclog.Printf(gclog.LErrorLog, "Couldn't write file %q: %s", post.Filename, err.Error())
|
||||
|
|
|
@ -4,6 +4,6 @@
|
|||
<link rel="shortcut icon" href="{{.SiteWebfolder}}favicon.png" />
|
||||
<script type="text/javascript" src="{{.SiteWebfolder}}javascript/consts.js"></script>
|
||||
<script type="text/javascript" src="{{.SiteWebfolder}}javascript/jquery-3.3.1.min.js"></script>
|
||||
<script type="text/javascript" src="{{.SiteWebfolder}}javascript/gochan{{if .UseMinifiedGochanJS}}.min{{end}}.js"></script>
|
||||
<script type="text/javascript" src="{{.SiteWebfolder}}javascript/gochan.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
<link rel="shortcut icon" href="{{.config.SiteWebfolder}}favicon.png">
|
||||
<script type="text/javascript" src="{{$.config.SiteWebfolder}}javascript/consts.js"></script>
|
||||
<script type="text/javascript" src="{{$.config.SiteWebfolder}}javascript/jquery-3.3.1.min.js"></script>
|
||||
<script type="text/javascript" src="{{$.config.SiteWebfolder}}javascript/gochan{{if $.config.UseMinifiedGochanJS}}.min{{end}}.js"></script>
|
||||
<script type="text/javascript" src="{{$.config.SiteWebfolder}}javascript/gochan.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="topbar">
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue