浏览代码

svg run ok

Help-14 3 年之前
父节点
当前提交
17a57bbcd4
共有 2 个文件被更改,包括 17 次插入13 次删除
  1. 2 1
      .gitignore
  2. 15 12
      src/main.go

+ 2 - 1
.gitignore

@@ -105,4 +105,5 @@ dist
 
 src/temp
 src/build
-src/data
+src/data
+data

+ 15 - 12
src/main.go

@@ -30,14 +30,7 @@ func main() {
 		os.MkdirAll(dataPath, os.ModePerm)
 		modules.CopyDir(filepath.Join(pwd, "common"), dataPath)
 	}
-
-	appConfig = modules.LoadConfig()
-	websiteData.Config = appConfig.Website
-	websiteData.Language = modules.LoadLanguage(appConfig.Website.Language)
-	websiteData.Contents = modules.LoadContent().Data
-
-	tmpl, _ := template.ParseFiles(filepath.Join(pwd, "themes", appConfig.Website.Theme, "index.html"))
-	webTemplate = tmpl
+	loadData()
 
 	commonfs := http.FileServer(http.Dir(dataPath))
 	http.Handle("/common/", http.StripPrefix("/common/", commonfs))
@@ -58,6 +51,20 @@ func main() {
 	}
 }
 
+func loadData() {
+	appConfig = modules.LoadConfig()
+	websiteData.Config = appConfig.Website
+	websiteData.Language = modules.LoadLanguage(appConfig.Website.Language)
+	websiteData.Contents = modules.LoadContent().Data
+
+	tmpl, _ := template.ParseFiles(filepath.Join(pwd, "themes", appConfig.Website.Theme, "index.html"))
+	webTemplate = tmpl
+}
+
+func serveTemplate(w http.ResponseWriter, r *http.Request) {
+	webTemplate.Execute(w, websiteData)
+}
+
 var weatherTimeOut int64
 var weatherCache []byte
 
@@ -79,7 +86,3 @@ func serveWeather(w http.ResponseWriter, r *http.Request) {
 	w.Header().Set("Content-Type", "application/json")
 	w.Write(weatherCache)
 }
-
-func serveTemplate(w http.ResponseWriter, r *http.Request) {
-	webTemplate.Execute(w, websiteData)
-}