This commit is contained in:
Liang Ding 2019-05-23 18:28:11 +08:00
parent 67c36e0089
commit 1857df995d
No known key found for this signature in database
GPG Key ID: 136F30F901A2231D
7 changed files with 32 additions and 14 deletions

View File

@ -17,6 +17,7 @@ package conf
import (
"encoding/json"
"html/template"
"io/ioutil"
"os"
"os/exec"
@ -24,7 +25,6 @@ import (
"sort"
"strconv"
"strings"
"text/template"
"time"
"github.com/b3log/wide/event"
@ -64,7 +64,7 @@ type conf struct {
HTTPSessionMaxAge int // HTTP session max age (in seciond)
StaticResourceVersion string // version of static resources
Locale string // default locale
Autocomplete bool // default autocomplete
SiteStatCode template.HTML // site statistic code
}
// Logger.
@ -83,8 +83,8 @@ var Docker bool
const DockerImageGo = "golang"
// Load loads the Wide configurations from wide.json and users' configurations from users/{userId}.json.
func Load(confPath, confData, confServer, confLogLevel string) {
initWide(confPath, confData, confServer, confLogLevel)
func Load(confPath, confData, confServer, confLogLevel string, confSiteStatCode template.HTML) {
initWide(confPath, confData, confServer, confLogLevel, confSiteStatCode)
initUsers()
cmd := exec.Command("docker", "version")
@ -158,7 +158,7 @@ func initUsers() {
initCustomizedConfs()
}
func initWide(confPath, confData, confServer, confLogLevel string) {
func initWide(confPath, confData, confServer, confLogLevel string, confSiteStatCode template.HTML) {
bytes, err := ioutil.ReadFile(confPath)
if nil != err {
logger.Error(err)
@ -220,6 +220,11 @@ func initWide(confPath, confData, confServer, confLogLevel string) {
Wide.Server = confServer
}
// SiteStatCode
if "" != confSiteStatCode {
Wide.SiteStatCode = confSiteStatCode
}
time := strconv.FormatInt(time.Now().UnixNano(), 10)
logger.Debugf("${time} [%s]", time)
Wide.StaticResourceVersion = strings.Replace(Wide.StaticResourceVersion, "${time}", time, 1)

View File

@ -6,5 +6,5 @@
"HTTPSessionMaxAge": 86400,
"StaticResourceVersion": "${time}",
"Locale": "zh_CN",
"Autocomplete": true
"SiteStatCode": ""
}

View File

@ -51,6 +51,7 @@ func init() {
confData := flag.String("data", "", "path of data dir")
confServer := flag.String("server", "", "this will overwrite Wide.Server if specified")
confLogLevel := flag.String("log_level", "", "this will overwrite Wide.LogLevel if specified")
confSiteStatCode := flag.String("site_stat_code", "", "this will overrite Wide.SiteStatCode if specified")
flag.Parse()
@ -66,7 +67,7 @@ func init() {
i18n.Load()
event.Load()
conf.Load(*confPath, *confData, *confServer, *confLogLevel)
conf.Load(*confPath, *confData, *confServer, *confLogLevel, template.HTML(*confSiteStatCode))
conf.FixedTimeCheckEnv()
session.FixedTimeSave()

View File

@ -31,6 +31,9 @@
<link rel="stylesheet" href="/static/css/themes/{{.user.Theme}}.css?{{.conf.StaticResourceVersion}}" id="themesLink">
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
{{if ne "" .conf.SiteStatCode}}
{{.conf.SiteStatCode}}
{{end}}
</head>
<body>
<!-- menu bar -->

View File

@ -9,6 +9,9 @@
<meta name="author" content="B3log">
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
{{if ne "" .conf.SiteStatCode}}
{{.conf.SiteStatCode}}
{{end}}
</head>
<body>
<h2>{{.i18n.editor}}</h2>

View File

@ -11,6 +11,9 @@
<link rel="stylesheet" href="/static/css/base.css?{{.conf.StaticResourceVersion}}">
<link rel="stylesheet" href="/static/css/sign.css?{{.conf.StaticResourceVersion}}">
<link rel="icon" type="image/x-icon" href="/favicon.ico"/>
{{if ne "" .conf.SiteStatCode}}
{{.conf.SiteStatCode}}
{{end}}
</head>
<body>
<div class="header">

View File

@ -24,6 +24,9 @@
<link rel="stylesheet" href="/static/css/playground.css?{{.conf.StaticResourceVersion}}">
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
{{if ne "" .conf.SiteStatCode}}
{{.conf.SiteStatCode}}
{{end}}
</head>
<body>
<div class="header menu fn-clear">