This commit is contained in:
parent
67c36e0089
commit
1857df995d
29
conf/wide.go
29
conf/wide.go
|
@ -17,6 +17,7 @@ package conf
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"html/template"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
@ -24,7 +25,6 @@ import (
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"text/template"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/b3log/wide/event"
|
"github.com/b3log/wide/event"
|
||||||
|
@ -57,14 +57,14 @@ func main() {
|
||||||
|
|
||||||
// Configuration.
|
// Configuration.
|
||||||
type conf struct {
|
type conf struct {
|
||||||
Server string // server
|
Server string // server
|
||||||
LogLevel string // logging level: trace/debug/info/warn/error
|
LogLevel string // logging level: trace/debug/info/warn/error
|
||||||
Data string // data directory
|
Data string // data directory
|
||||||
RuntimeMode string // runtime mode (dev/prod)
|
RuntimeMode string // runtime mode (dev/prod)
|
||||||
HTTPSessionMaxAge int // HTTP session max age (in seciond)
|
HTTPSessionMaxAge int // HTTP session max age (in seciond)
|
||||||
StaticResourceVersion string // version of static resources
|
StaticResourceVersion string // version of static resources
|
||||||
Locale string // default locale
|
Locale string // default locale
|
||||||
Autocomplete bool // default autocomplete
|
SiteStatCode template.HTML // site statistic code
|
||||||
}
|
}
|
||||||
|
|
||||||
// Logger.
|
// Logger.
|
||||||
|
@ -83,8 +83,8 @@ var Docker bool
|
||||||
const DockerImageGo = "golang"
|
const DockerImageGo = "golang"
|
||||||
|
|
||||||
// Load loads the Wide configurations from wide.json and users' configurations from users/{userId}.json.
|
// Load loads the Wide configurations from wide.json and users' configurations from users/{userId}.json.
|
||||||
func Load(confPath, confData, confServer, confLogLevel string) {
|
func Load(confPath, confData, confServer, confLogLevel string, confSiteStatCode template.HTML) {
|
||||||
initWide(confPath, confData, confServer, confLogLevel)
|
initWide(confPath, confData, confServer, confLogLevel, confSiteStatCode)
|
||||||
initUsers()
|
initUsers()
|
||||||
|
|
||||||
cmd := exec.Command("docker", "version")
|
cmd := exec.Command("docker", "version")
|
||||||
|
@ -158,7 +158,7 @@ func initUsers() {
|
||||||
initCustomizedConfs()
|
initCustomizedConfs()
|
||||||
}
|
}
|
||||||
|
|
||||||
func initWide(confPath, confData, confServer, confLogLevel string) {
|
func initWide(confPath, confData, confServer, confLogLevel string, confSiteStatCode template.HTML) {
|
||||||
bytes, err := ioutil.ReadFile(confPath)
|
bytes, err := ioutil.ReadFile(confPath)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
logger.Error(err)
|
logger.Error(err)
|
||||||
|
@ -220,6 +220,11 @@ func initWide(confPath, confData, confServer, confLogLevel string) {
|
||||||
Wide.Server = confServer
|
Wide.Server = confServer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SiteStatCode
|
||||||
|
if "" != confSiteStatCode {
|
||||||
|
Wide.SiteStatCode = confSiteStatCode
|
||||||
|
}
|
||||||
|
|
||||||
time := strconv.FormatInt(time.Now().UnixNano(), 10)
|
time := strconv.FormatInt(time.Now().UnixNano(), 10)
|
||||||
logger.Debugf("${time} [%s]", time)
|
logger.Debugf("${time} [%s]", time)
|
||||||
Wide.StaticResourceVersion = strings.Replace(Wide.StaticResourceVersion, "${time}", time, 1)
|
Wide.StaticResourceVersion = strings.Replace(Wide.StaticResourceVersion, "${time}", time, 1)
|
||||||
|
|
|
@ -6,5 +6,5 @@
|
||||||
"HTTPSessionMaxAge": 86400,
|
"HTTPSessionMaxAge": 86400,
|
||||||
"StaticResourceVersion": "${time}",
|
"StaticResourceVersion": "${time}",
|
||||||
"Locale": "zh_CN",
|
"Locale": "zh_CN",
|
||||||
"Autocomplete": true
|
"SiteStatCode": ""
|
||||||
}
|
}
|
3
main.go
3
main.go
|
@ -51,6 +51,7 @@ func init() {
|
||||||
confData := flag.String("data", "", "path of data dir")
|
confData := flag.String("data", "", "path of data dir")
|
||||||
confServer := flag.String("server", "", "this will overwrite Wide.Server if specified")
|
confServer := flag.String("server", "", "this will overwrite Wide.Server if specified")
|
||||||
confLogLevel := flag.String("log_level", "", "this will overwrite Wide.LogLevel 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()
|
flag.Parse()
|
||||||
|
|
||||||
|
@ -66,7 +67,7 @@ func init() {
|
||||||
|
|
||||||
i18n.Load()
|
i18n.Load()
|
||||||
event.Load()
|
event.Load()
|
||||||
conf.Load(*confPath, *confData, *confServer, *confLogLevel)
|
conf.Load(*confPath, *confData, *confServer, *confLogLevel, template.HTML(*confSiteStatCode))
|
||||||
|
|
||||||
conf.FixedTimeCheckEnv()
|
conf.FixedTimeCheckEnv()
|
||||||
session.FixedTimeSave()
|
session.FixedTimeSave()
|
||||||
|
|
|
@ -31,6 +31,9 @@
|
||||||
<link rel="stylesheet" href="/static/css/themes/{{.user.Theme}}.css?{{.conf.StaticResourceVersion}}" id="themesLink">
|
<link rel="stylesheet" href="/static/css/themes/{{.user.Theme}}.css?{{.conf.StaticResourceVersion}}" id="themesLink">
|
||||||
|
|
||||||
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
|
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
|
||||||
|
{{if ne "" .conf.SiteStatCode}}
|
||||||
|
{{.conf.SiteStatCode}}
|
||||||
|
{{end}}
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<!-- menu bar -->
|
<!-- menu bar -->
|
||||||
|
|
|
@ -9,6 +9,9 @@
|
||||||
<meta name="author" content="B3log">
|
<meta name="author" content="B3log">
|
||||||
|
|
||||||
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
|
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
|
||||||
|
{{if ne "" .conf.SiteStatCode}}
|
||||||
|
{{.conf.SiteStatCode}}
|
||||||
|
{{end}}
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h2>{{.i18n.editor}}</h2>
|
<h2>{{.i18n.editor}}</h2>
|
||||||
|
|
|
@ -11,6 +11,9 @@
|
||||||
<link rel="stylesheet" href="/static/css/base.css?{{.conf.StaticResourceVersion}}">
|
<link rel="stylesheet" href="/static/css/base.css?{{.conf.StaticResourceVersion}}">
|
||||||
<link rel="stylesheet" href="/static/css/sign.css?{{.conf.StaticResourceVersion}}">
|
<link rel="stylesheet" href="/static/css/sign.css?{{.conf.StaticResourceVersion}}">
|
||||||
<link rel="icon" type="image/x-icon" href="/favicon.ico"/>
|
<link rel="icon" type="image/x-icon" href="/favicon.ico"/>
|
||||||
|
{{if ne "" .conf.SiteStatCode}}
|
||||||
|
{{.conf.SiteStatCode}}
|
||||||
|
{{end}}
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="header">
|
<div class="header">
|
||||||
|
|
|
@ -24,6 +24,9 @@
|
||||||
<link rel="stylesheet" href="/static/css/playground.css?{{.conf.StaticResourceVersion}}">
|
<link rel="stylesheet" href="/static/css/playground.css?{{.conf.StaticResourceVersion}}">
|
||||||
|
|
||||||
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
|
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
|
||||||
|
{{if ne "" .conf.SiteStatCode}}
|
||||||
|
{{.conf.SiteStatCode}}
|
||||||
|
{{end}}
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="header menu fn-clear">
|
<div class="header menu fn-clear">
|
||||||
|
|
Loading…
Reference in New Issue