瀏覽代碼

project struct is ok

Help-14 3 年之前
父節點
當前提交
2bbab83d99
共有 37 個文件被更改,包括 57 次插入38 次删除
  1. 0 0
      src/common/assets/favicon.ico
  2. 0 0
      src/common/config.yaml
  3. 0 0
      src/common/css/core.css
  4. 0 0
      src/common/css/custom.css
  5. 0 0
      src/common/data.json
  6. 0 0
      src/common/js/custom.js
  7. 5 1
      src/go.mod
  8. 4 0
      src/go.sum
  9. 0 0
      src/languages/en.json
  10. 0 0
      src/languages/vi.json
  11. 28 15
      src/main.go
  12. 19 21
      src/modules/compile.go
  13. 1 1
      src/modules/config.go
  14. 0 0
      src/themes/custom/index.html
  15. 0 0
      src/themes/flame/css/all.min.css
  16. 0 0
      src/themes/flame/css/charts.css.map
  17. 0 0
      src/themes/flame/css/charts.min.css
  18. 0 0
      src/themes/flame/css/font.css
  19. 0 0
      src/themes/flame/css/magma.css
  20. 0 0
      src/themes/flame/css/normalize.min.css
  21. 0 0
      src/themes/flame/css/skeleton.min.css
  22. 0 0
      src/themes/flame/fonts/fa-brands-400.ttf
  23. 0 0
      src/themes/flame/fonts/fa-brands-400.woff2
  24. 0 0
      src/themes/flame/fonts/fa-regular-400.ttf
  25. 0 0
      src/themes/flame/fonts/fa-regular-400.woff2
  26. 0 0
      src/themes/flame/fonts/fa-solid-900.ttf
  27. 0 0
      src/themes/flame/fonts/fa-solid-900.woff2
  28. 0 0
      src/themes/flame/fonts/fa-v4compatibility.ttf
  29. 0 0
      src/themes/flame/fonts/fa-v4compatibility.woff2
  30. 0 0
      src/themes/flame/fonts/raleway-v26-latin-regular.eot
  31. 0 0
      src/themes/flame/fonts/raleway-v26-latin-regular.svg
  32. 0 0
      src/themes/flame/fonts/raleway-v26-latin-regular.ttf
  33. 0 0
      src/themes/flame/fonts/raleway-v26-latin-regular.woff
  34. 0 0
      src/themes/flame/fonts/raleway-v26-latin-regular.woff2
  35. 0 0
      src/themes/flame/index.html
  36. 0 0
      src/themes/flame/js/magma.js
  37. 0 0
      src/themes/flame/js/skycons.min.js

+ 0 - 0
src/public/assets/favicon.ico → src/common/assets/favicon.ico


+ 0 - 0
src/public/config.yaml → src/common/config.yaml


+ 0 - 0
src/public/css/core.css → src/common/css/core.css


+ 0 - 0
src/public/css/custom.css → src/common/css/custom.css


+ 0 - 0
src/public/data.json → src/common/data.json


+ 0 - 0
src/public/js/custom.js → src/common/js/custom.js


+ 5 - 1
src/go.mod

@@ -2,9 +2,13 @@ module github.com/help-14/magma
 
 go 1.18
 
-require gopkg.in/yaml.v2 v2.4.0
+require (
+	github.com/tdewolff/minify v2.3.6+incompatible
+	gopkg.in/yaml.v2 v2.4.0
+)
 
 require (
 	github.com/tdewolff/minify/v2 v2.10.0 // indirect
+	github.com/tdewolff/parse v2.3.4+incompatible // indirect
 	github.com/tdewolff/parse/v2 v2.5.27 // indirect
 )

+ 4 - 0
src/go.sum

@@ -4,8 +4,12 @@ github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25Kn
 github.com/fsnotify/fsnotify v1.5.1/go.mod h1:T3375wBYaZdLLcVNkcVbzGHY7f1l/uK5T5Ai1i3InKU=
 github.com/matryer/try v0.0.0-20161228173917-9ac251b645a2/go.mod h1:0KeJpeMD6o+O4hW7qJOT7vyQPKrWmj26uf5wMc/IiIs=
 github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
+github.com/tdewolff/minify v2.3.6+incompatible h1:2hw5/9ZvxhWLvBUnHE06gElGYz+Jv9R4Eys0XUzItYo=
+github.com/tdewolff/minify v2.3.6+incompatible/go.mod h1:9Ov578KJUmAWpS6NeZwRZyT56Uf6o3Mcz9CEsg8USYs=
 github.com/tdewolff/minify/v2 v2.10.0 h1:ovVAHUcjfGrBDf1EIvsodRUVJiZK/28mMose08B7k14=
 github.com/tdewolff/minify/v2 v2.10.0/go.mod h1:6XAjcHM46pFcRE0eztigFPm0Q+Cxsw8YhEWT+rDkcZM=
+github.com/tdewolff/parse v2.3.4+incompatible h1:x05/cnGwIMf4ceLuDMBOdQ1qGniMoxpP46ghf0Qzh38=
+github.com/tdewolff/parse v2.3.4+incompatible/go.mod h1:8oBwCsVmUkgHO8M5iCzSIDtpzXOT0WXX9cWhz+bIzJQ=
 github.com/tdewolff/parse/v2 v2.5.27 h1:PL3LzzXaOpmdrknnOlIeO2muIBHAwiKp6TxN1RbU5gI=
 github.com/tdewolff/parse/v2 v2.5.27/go.mod h1:WzaJpRSbwq++EIQHYIRTpbYKNA3gn9it1Ik++q4zyho=
 github.com/tdewolff/test v1.0.6/go.mod h1:6DAvZliBAAnD7rhVgwaM7DE5/d9NMOAJ09SqYqeK4QE=

+ 0 - 0
src/private/languages/en.json → src/languages/en.json


+ 0 - 0
src/private/languages/vi.json → src/languages/vi.json


+ 28 - 15
src/main.go

@@ -4,38 +4,51 @@ import (
 	"html/template"
 	"log"
 	"net/http"
-	"os"
 	"path/filepath"
 
-	modules "github.com/help-14/magma/modules"
+	"github.com/help-14/magma/modules"
 )
 
 func main() {
-	tempPath := filepath.Join(".", "temp")
-	err := os.MkdirAll(tempPath, os.ModePerm)
-	if err != nil {
-		log.Fatal(err)
-		return
-	}
+	appConfig := modules.LoadConfig()
+
+	commonfs := http.FileServer(http.Dir("./common"))
+	http.Handle("/common/", http.StripPrefix("/common/", commonfs))
 
-	fs := http.FileServer(http.Dir("./temp"))
-	http.Handle("/static/", http.StripPrefix("/static/", fs))
+	themePath := "/themes/" + appConfig.Website.Theme + "/"
+	themefs := http.FileServer(http.Dir("." + themePath))
+	http.Handle("/theme/", http.StripPrefix("/theme/", themefs))
 
-	modules.LoadConfig()
+	http.HandleFunc("/", serveTemplate)
+	// tempPath := filepath.Join(".", "temp")
+	// err := os.MkdirAll(tempPath, os.ModePerm)
+	// if err != nil {
+	// 	log.Fatal(err)
+	// 	return
+	// }
 
 	log.Println("Listening on :7001 ...")
-	err = http.ListenAndServe(":7001", nil)
+	err := http.ListenAndServe(":7001", nil)
 	if err != nil {
 		log.Fatal(err)
 	}
 }
 
+// func TemplatedHandler(response http.ResponseWriter, request *http.Request) {
+// 	tmplt := template.New("hello template")
+// 	tmplt, _ = tmplt.Parse("Top Student: {{.Id}} - {{.Name}}!")
+
+// 	p := Student{Id: 1, Name: "Aisha"} //define an instance with required field
+
+// 	tmplt.Execute(response, p) //merge template ‘t’ with content of ‘p’
+// }
+
 func serveTemplate(w http.ResponseWriter, r *http.Request) {
 	lp := filepath.Join("templates", "layout.html")
-	fp := filepath.Join("templates", filepath.Clean(r.URL.Path))
+	//fp := filepath.Join("templates", filepath.Clean(r.URL.Path))
 
-	tmpl, _ := template.ParseFiles(lp, fp)
-	tmpl.ExecuteTemplate(w, "layout", nil)
+	tmpl, _ := template.ParseFiles(lp)
+	tmpl.Execute(w, nil)
 }
 
 // templ.Execute(file, struct {

+ 19 - 21
src/modules/compile.go

@@ -1,8 +1,6 @@
 package modules
 
 import (
-	"fmt"
-	"io/ioutil"
 	"regexp"
 
 	"github.com/tdewolff/minify"
@@ -23,24 +21,24 @@ func Compile() {
 	m.AddFuncRegexp(regexp.MustCompile("[/+]json$"), json.Minify)
 	m.AddFuncRegexp(regexp.MustCompile("[/+]xml$"), xml.Minify)
 
-	items, _ := ioutil.ReadDir("./private")
-	for _, item := range items {
-		if item.IsDir() {
-			subitems, _ := ioutil.ReadDir(item.Name())
-			for _, subitem := range subitems {
-				if !subitem.IsDir() {
-					// handle file there
-					fmt.Println(item.Name() + "/" + subitem.Name())
-				}
-			}
-		} else {
-			// handle file there
-			fmt.Println(item.Name())
-		}
-	}
+	// items, _ := ioutil.ReadDir("./private")
+	// for _, item := range items {
+	// 	if item.IsDir() {
+	// 		subitems, _ := ioutil.ReadDir(item.Name())
+	// 		for _, subitem := range subitems {
+	// 			if !subitem.IsDir() {
+	// 				// handle file there
+	// 				fmt.Println(item.Name() + "/" + subitem.Name())
+	// 			}
+	// 		}
+	// 	} else {
+	// 		// handle file there
+	// 		fmt.Println(item.Name())
+	// 	}
+	// }
 
-	s, err = m.String(mediatype, s)
-	if err != nil {
-		panic(err)
-	}
+	// s, err = m.String(mediatype, s)
+	// if err != nil {
+	// 	panic(err)
+	// }
 }

+ 1 - 1
src/modules/config.go

@@ -41,7 +41,7 @@ func LoadConfig() Config {
 		Addons: []string{},
 	}
 
-	yamlFile, err := ioutil.ReadFile("./public/config.yaml")
+	yamlFile, err := ioutil.ReadFile("./common/config.yaml")
 	if err != nil {
 		fmt.Printf("Error reading YAML file: %s\n", err)
 		return defaultConfig

+ 0 - 0
src/private/themes/custom/index.html → src/themes/custom/index.html


+ 0 - 0
src/private/themes/flame/css/all.min.css → src/themes/flame/css/all.min.css


+ 0 - 0
src/private/themes/flame/css/charts.css.map → src/themes/flame/css/charts.css.map


+ 0 - 0
src/private/themes/flame/css/charts.min.css → src/themes/flame/css/charts.min.css


+ 0 - 0
src/private/themes/flame/css/font.css → src/themes/flame/css/font.css


+ 0 - 0
src/private/themes/flame/css/magma.css → src/themes/flame/css/magma.css


+ 0 - 0
src/private/themes/flame/css/normalize.min.css → src/themes/flame/css/normalize.min.css


+ 0 - 0
src/private/themes/flame/css/skeleton.min.css → src/themes/flame/css/skeleton.min.css


+ 0 - 0
src/private/themes/flame/fonts/fa-brands-400.ttf → src/themes/flame/fonts/fa-brands-400.ttf


+ 0 - 0
src/private/themes/flame/fonts/fa-brands-400.woff2 → src/themes/flame/fonts/fa-brands-400.woff2


+ 0 - 0
src/private/themes/flame/fonts/fa-regular-400.ttf → src/themes/flame/fonts/fa-regular-400.ttf


+ 0 - 0
src/private/themes/flame/fonts/fa-regular-400.woff2 → src/themes/flame/fonts/fa-regular-400.woff2


+ 0 - 0
src/private/themes/flame/fonts/fa-solid-900.ttf → src/themes/flame/fonts/fa-solid-900.ttf


+ 0 - 0
src/private/themes/flame/fonts/fa-solid-900.woff2 → src/themes/flame/fonts/fa-solid-900.woff2


+ 0 - 0
src/private/themes/flame/fonts/fa-v4compatibility.ttf → src/themes/flame/fonts/fa-v4compatibility.ttf


+ 0 - 0
src/private/themes/flame/fonts/fa-v4compatibility.woff2 → src/themes/flame/fonts/fa-v4compatibility.woff2


+ 0 - 0
src/private/themes/flame/fonts/raleway-v26-latin-regular.eot → src/themes/flame/fonts/raleway-v26-latin-regular.eot


+ 0 - 0
src/private/themes/flame/fonts/raleway-v26-latin-regular.svg → src/themes/flame/fonts/raleway-v26-latin-regular.svg


+ 0 - 0
src/private/themes/flame/fonts/raleway-v26-latin-regular.ttf → src/themes/flame/fonts/raleway-v26-latin-regular.ttf


+ 0 - 0
src/private/themes/flame/fonts/raleway-v26-latin-regular.woff → src/themes/flame/fonts/raleway-v26-latin-regular.woff


+ 0 - 0
src/private/themes/flame/fonts/raleway-v26-latin-regular.woff2 → src/themes/flame/fonts/raleway-v26-latin-regular.woff2


+ 0 - 0
src/private/themes/flame/index.html → src/themes/flame/index.html


+ 0 - 0
src/private/themes/flame/js/magma.js → src/themes/flame/js/magma.js


+ 0 - 0
src/private/themes/flame/js/skycons.min.js → src/themes/flame/js/skycons.min.js