From 87a9236e017fb3accee9b91086a13d15c9a2cbd1 Mon Sep 17 00:00:00 2001 From: ngn Date: Wed, 14 Aug 2024 00:32:48 +0300 Subject: [PATCH] update: general formatting and cleanup --- .gitignore | 2 + Makefile | 9 ++ README.md | 25 ++++-- compose.yml | 12 --- lib/content.go | 120 +++++++++++++------------- lib/util.go | 58 ++++++------- log/log.go | 23 +++++ main.go | 57 ++++++------- public/download.css | 2 +- public/news.css | 2 +- routes/configs.go | 204 +++++++++++++++++++++++--------------------- routes/download.go | 25 +++--- routes/index.go | 25 +++--- routes/news.go | 98 ++++++++++----------- routes/wiki.go | 84 +++++++++--------- 15 files changed, 402 insertions(+), 344 deletions(-) create mode 100644 Makefile delete mode 100644 compose.yml create mode 100644 log/log.go diff --git a/.gitignore b/.gitignore index ad97612..9239422 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ +docker-compose.yml +compose.yml content website diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..b088f1a --- /dev/null +++ b/Makefile @@ -0,0 +1,9 @@ +all: website + +website: */*.go *.go + go build -o $@ + +format: + gofmt -s -w . + +.PHONY: format diff --git a/README.md b/README.md index 093bcea..55e6f3f 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,33 @@ -# website | MatterLinux Website +# website | MatterLinux website Soruce code of Matterlinux's offical website, which is located at [matterlinux.xyz](https://matterlinux.xyz) ### Deployment -Web server can be built and deployed with docker: +Web server can be built and deployed with docker compose using the following +configuration file: +```yaml +version: "3" + +services: + website: + image: matterwebsite + restart: unless-stopped + build: + context: ./ + ports: + - "127.0.0.1:9878:9878" + volumes: + - "./content:/app/content" ``` -docker build --tag matterwebsite . +After saving the configuration file, you can build and run the docker container: +```bash docker-compose up -d ``` -### Managing Content +### Managing content Website content can be managed by editing JSON and markdown files under the `content` direcotry. -Matterlinux's website content directory can be found in the +MatterLinux's website content directory can be found in the [content](https://git.matterlinux.xyz/Matter/content) repository. diff --git a/compose.yml b/compose.yml deleted file mode 100644 index 3df574a..0000000 --- a/compose.yml +++ /dev/null @@ -1,12 +0,0 @@ -version: "3" - -services: - website: - image: matterwebsite - restart: unless-stopped - build: - context: ./ - ports: - - "127.0.0.1:9878:9878" - volumes: - - "./content:/app/content" diff --git a/lib/content.go b/lib/content.go index 24363a9..74c9812 100644 --- a/lib/content.go +++ b/lib/content.go @@ -11,86 +11,86 @@ import ( const CONTENT_PATH string = "content" -type Content struct{ - Dir string - Name string +type Content struct { + Dir string + Name string - Title string `json:"title"` - ID string `json:"id"` + Title string `json:"title"` + ID string `json:"id"` - Md string - HTML template.HTML + Md string + HTML template.HTML - Date string `json:"date"` - Author string `json:"author"` + Date string `json:"date"` + Author string `json:"author"` } func ListContent(dir string) ([]Content, error) { - var res []Content + var res []Content - dirpath := path.Join(CONTENT_PATH, dir) - entries, err := os.ReadDir(dirpath) - if err != nil { - return nil, errors.New("Cannot readdir: "+dirpath) - } + dirpath := path.Join(CONTENT_PATH, dir) + entries, err := os.ReadDir(dirpath) + if err != nil { + return nil, errors.New("Cannot readdir: " + dirpath) + } - for _, e := range entries { - if e.IsDir() { - subres, err := ListContent(path.Join(dir, e.Name())) - if err != nil { - return res, err - } - res = append(res, subres...) - } + for _, e := range entries { + if e.IsDir() { + subres, err := ListContent(path.Join(dir, e.Name())) + if err != nil { + return res, err + } + res = append(res, subres...) + } - if(!strings.HasSuffix(e.Name(), ".json")) { - continue - } + if !strings.HasSuffix(e.Name(), ".json") { + continue + } - var con Content - jsonfile := path.Join(dirpath, e.Name()) - jsoncon, err := os.ReadFile(jsonfile) + var con Content + jsonfile := path.Join(dirpath, e.Name()) + jsoncon, err := os.ReadFile(jsonfile) - if err != nil { - return nil, errors.New("Cannot get JSON: "+jsonfile) - } + if err != nil { + return nil, errors.New("Cannot get JSON: " + jsonfile) + } - err = json.Unmarshal(jsoncon, &con) - if err != nil { - return nil, errors.New("Cannot parse JSON: "+jsonfile) - } + err = json.Unmarshal(jsoncon, &con) + if err != nil { + return nil, errors.New("Cannot parse JSON: " + jsonfile) + } - con.Dir = dir - con.Name = strings.Split(e.Name(), ".")[0] - res = append(res, con) - } + con.Dir = dir + con.Name = strings.Split(e.Name(), ".")[0] + res = append(res, con) + } - return res, nil + return res, nil } func GetContent(dir string, name string) (Content, error) { - var res Content - jsonfile := path.Join(CONTENT_PATH, dir, name+".json") - mdfile := path.Join(CONTENT_PATH, dir, name+".md") + var res Content + jsonfile := path.Join(CONTENT_PATH, dir, name+".json") + mdfile := path.Join(CONTENT_PATH, dir, name+".md") - res.Dir = dir - res.Name = name + res.Dir = dir + res.Name = name - jsoncontent, err := os.ReadFile(jsonfile) - if err != nil { - return res, errors.New("Cannot read JSON file: "+jsonfile) - } + jsoncontent, err := os.ReadFile(jsonfile) + if err != nil { + return res, errors.New("Cannot read JSON file: " + jsonfile) + } - rawcontent, err := os.ReadFile(mdfile) - if err != nil { - return res, errors.New("Cannot read markdown file: "+mdfile) - } + rawcontent, err := os.ReadFile(mdfile) + if err != nil { + return res, errors.New("Cannot read markdown file: " + mdfile) + } - if(json.Unmarshal(jsoncontent, &res)!= nil) { - return res, errors.New("Cannot parse JSON: "+jsonfile) - } + if json.Unmarshal(jsoncontent, &res) != nil { + return res, errors.New("Cannot parse JSON: " + jsonfile) + } - res.Md = string(rawcontent) - res.HTML = template.HTML(ParseMarkdown(res.Md)) - return res, nil + res.Md = string(rawcontent) + res.HTML = template.HTML(ParseMarkdown(res.Md)) + return res, nil } diff --git a/lib/util.go b/lib/util.go index 706f624..a1cc80d 100644 --- a/lib/util.go +++ b/lib/util.go @@ -12,44 +12,44 @@ import ( // python3 -c "import string; print(string.ascii_letters+string.digits+\" /,_-?!'\\\"\")" var valid string = `abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 /,_-?!'"` -func IsStringValid(s string) bool{ - for _, c := range s { - if !strings.Contains(valid, string(c)){ - fmt.Printf("%c\n", c) - return false - } - } - return true +func IsStringValid(s string) bool { + for _, c := range s { + if !strings.Contains(valid, string(c)) { + fmt.Printf("%c\n", c) + return false + } + } + return true } -func RenderError(c *fiber.Ctx, code int) error{ - var msg string = "Server Error" - c.Status(code) +func RenderError(c *fiber.Ctx, code int) error { + var msg string = "Server Error" + c.Status(code) - switch code { - case 404: - msg = "Not Found" - } + switch code { + case 404: + msg = "Not Found" + } - return c.Render("error", fiber.Map{ - "msg": msg, - }) + return c.Render("error", fiber.Map{ + "msg": msg, + }) } func TimeFromString(date string) (time.Time, error) { - res, err := time.Parse("02/01/06", date) - if err == nil { - return res, nil - } - return time.Now(), nil + res, err := time.Parse("02/01/06", date) + if err == nil { + return res, nil + } + return time.Now(), nil } func ParseMarkdown(md string) string { - ext := blackfriday.FencedCode - ext |= blackfriday.BackslashLineBreak - ext |= blackfriday.Strikethrough - ext |= blackfriday.Tables - ext |= blackfriday.NoEmptyLineBeforeBlock + ext := blackfriday.FencedCode + ext |= blackfriday.BackslashLineBreak + ext |= blackfriday.Strikethrough + ext |= blackfriday.Tables + ext |= blackfriday.NoEmptyLineBeforeBlock - return string(blackfriday.Run([]byte(md), blackfriday.WithExtensions(ext))) + return string(blackfriday.Run([]byte(md), blackfriday.WithExtensions(ext))) } diff --git a/log/log.go b/log/log.go new file mode 100644 index 0000000..e0eb92f --- /dev/null +++ b/log/log.go @@ -0,0 +1,23 @@ +package log + +import ( + "fmt" + "time" +) + +func Log(p string, f string, args ...interface{}) { + now := time.Now() + nstr := now.Format("[02/01/06 15:04:05]") + + fmt.Printf("%s -%s- ", nstr, p) + fmt.Printf(f, args...) + fmt.Println() +} + +func Info(f string, args ...interface{}) { + Log("INFO", f, args...) +} + +func Error(f string, args ...interface{}) { + Log("ERROR", f, args...) +} diff --git a/main.go b/main.go index 78b9aac..2bded5c 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,6 @@ /* - * website | MatterLinux Official Website + * website | MatterLinux website * MatterLinux 2023-2024 (https://matterlinux.xyz) * This program is free software: you can redistribute it and/or modify @@ -21,44 +21,43 @@ package main import ( - "log" - "git.matterlinux.xyz/Matter/website/lib" + "git.matterlinux.xyz/Matter/website/log" "git.matterlinux.xyz/Matter/website/routes" "github.com/gofiber/fiber/v2" "github.com/gofiber/template/html/v2" ) -func main(){ - log.SetFlags(log.Lshortfile | log.Ltime) +func main() { + var err error - engine := html.New("./templates", ".html") - app := fiber.New(fiber.Config{ - DisableStartupMessage: true, - Views: engine, - }) - app.Static("/", "./public") - app.Static("/assets", "./content/assets") + engine := html.New("./templates", ".html") + app := fiber.New(fiber.Config{ + DisableStartupMessage: true, + Views: engine, + }) + app.Static("/", "./public") + app.Static("/assets", "./content/assets") - app.Get("/", routes.IndexRoute) - app.Get("/download", routes.DownloadRoute) + app.Get("/", routes.GET_Index) + app.Get("/download", routes.GET_Download) - app.Get("/news", routes.NewsRoute) - app.Get("/news/:id", routes.PostRoute) - - app.Get("/wiki", routes.WikiMainRoute) - app.Get("/wiki/:id", routes.WikiRoute) + app.Get("/news", routes.GET_News) + app.Get("/news/:id", routes.GET_New) - app.Get("/hub", routes.ConfigsRoute) - app.Get("/hub/:name", routes.ConfigRoute) + app.Get("/wiki", routes.GET_Wiki) + app.Get("/wiki/:id", routes.GET_WikiPage) - app.Get("*", func(c *fiber.Ctx) error { - return lib.RenderError(c, 404) - }) + app.Get("/hub", routes.GET_Configs) + app.Get("/hub/:name", routes.GET_Config) - log.Println("Starting MatterLinux Website on port 9878") - err := app.Listen(":9878") - if err != nil { - log.Fatalf("Error starting server: %s", err) - } + app.Get("*", func(c *fiber.Ctx) error { + return lib.RenderError(c, 404) + }) + + log.Info("Starting MatterLinux website on port 9878") + + if err = app.Listen(":9878"); err != nil { + log.Error("Error starting server: %s", err.Error()) + } } diff --git a/public/download.css b/public/download.css index 2749057..7349978 100644 --- a/public/download.css +++ b/public/download.css @@ -11,7 +11,7 @@ align-items: center; justify-content: space-between; background: var(--dark-second); - border: solid 1px var(--bright-main); + border: solid 1px var(--bright-second); padding: 10px; } diff --git a/public/news.css b/public/news.css index e1b7b58..d5b1c31 100644 --- a/public/news.css +++ b/public/news.css @@ -1,7 +1,7 @@ main { display: flex; flex-direction: column; - padding-top: 50px; + padding-top: 40px; gap: 10px; } diff --git a/routes/configs.go b/routes/configs.go index 7dd17c7..20a7a1d 100644 --- a/routes/configs.go +++ b/routes/configs.go @@ -4,137 +4,145 @@ import ( "bytes" "encoding/json" "fmt" - "log" "os" "path" "strings" "git.matterlinux.xyz/Matter/website/lib" + "git.matterlinux.xyz/Matter/website/log" "github.com/bigkevmcd/go-configparser" "github.com/gofiber/fiber/v2" ) type Config struct { - Redirect string `json:"redirect"` - Image string `json:"image"` - Url string `json:"url"` + Redirect string `json:"redirect"` + Image string `json:"image"` + Url string `json:"url"` - Name string - Desc string - Author string - Keywords string + Name string + Desc string + Author string + Keywords string } -func LoadConfig(c *Config) (error) { - agent := fiber.Get(c.Url) - code, body, errs := agent.Bytes() - if len(errs) > 0 { - return fmt.Errorf("request to %s failed", c.Url) - } +func (c *Config) Load() error { + agent := fiber.Get(c.Url) + code, body, errs := agent.Bytes() + if len(errs) > 0 { + return fmt.Errorf("request to %s failed", c.Url) + } - if code != 200 { - return fmt.Errorf("bad response from %s", c.Url) - } + if code != 200 { + return fmt.Errorf("bad response from %s", c.Url) + } - parser := configparser.New() - err := parser.ParseReader(bytes.NewReader(body)) - if err != nil { - return fmt.Errorf("failed to parse %s: %s", c.Url, err.Error()) - } + parser := configparser.New() + err := parser.ParseReader(bytes.NewReader(body)) + if err != nil { + return fmt.Errorf("failed to parse %s: %s", c.Url, err.Error()) + } - name, err := parser.Get("details", "name") - if err != nil { - return fmt.Errorf("failed get details/name: %s", c.Url) - } - - keywords, err := parser.Get("details", "keywords") - if err != nil { - return fmt.Errorf("failed get details/keywords: %s", c.Url) - } + name, err := parser.Get("details", "name") + if err != nil { + return fmt.Errorf("failed get details/name: %s", c.Url) + } - author, err := parser.Get("details", "author") - if err != nil { - return fmt.Errorf("failed get details/keywords: %s", c.Url) - } - - desc, err := parser.Get("details", "desc") + keywords, err := parser.Get("details", "keywords") + if err != nil { + return fmt.Errorf("failed get details/keywords: %s", c.Url) + } - c.Name = name - c.Desc = desc - c.Author = author - c.Keywords = strings.ReplaceAll(keywords, ",", ", ") + author, err := parser.Get("details", "author") + if err != nil { + return fmt.Errorf("failed get details/keywords: %s", c.Url) + } - if(!lib.IsStringValid(c.Name) || - !lib.IsStringValid(c.Desc) || - !lib.IsStringValid(c.Author) || - !lib.IsStringValid(c.Keywords)){ - return fmt.Errorf("keywords or name contain illegal chars: %s", c.Url) - } + desc, err := parser.Get("details", "desc") - return nil + c.Name = name + c.Desc = desc + c.Author = author + c.Keywords = strings.ReplaceAll(keywords, ",", ", ") + + if !lib.IsStringValid(c.Name) || + !lib.IsStringValid(c.Desc) || + !lib.IsStringValid(c.Author) || + !lib.IsStringValid(c.Keywords) { + return fmt.Errorf("keywords or name contain illegal chars: %s", c.Url) + } + + return nil } func GetConfigs() ([]Config, error) { - var data map[string][]Config + var data map[string][]Config - configs_path := path.Join(lib.CONTENT_PATH, "configs.json") - raw, err := os.ReadFile(configs_path) - if err != nil { - return nil, err - } + configs_path := path.Join(lib.CONTENT_PATH, "configs.json") + raw, err := os.ReadFile(configs_path) + if err != nil { + return nil, err + } - err = json.Unmarshal(raw, &data) - if err != nil { - return nil, err - } + err = json.Unmarshal(raw, &data) + if err != nil { + return nil, err + } - if _, ok := data["list"]; !ok { - return nil, fmt.Errorf("json data does not contain the list key") - } + if _, ok := data["list"]; !ok { + return nil, fmt.Errorf("json data does not contain the list key") + } - for i := range data["list"] { - err = LoadConfig(&data["list"][i]) - if err != nil { - return nil, err - } - } + for i := range data["list"] { + if err = data["list"][i].Load(); err != nil { + return nil, err + } + } - return data["list"], nil + return data["list"], nil } -func ConfigsRoute(c *fiber.Ctx) error{ - con, err := lib.GetContent("", "configs") - if err != nil { - log.Printf("GetContent failed: %s", err.Error()) - return lib.RenderError(c, 500) - } - - configs, err := GetConfigs() - if err != nil { - log.Printf("GetConfigs failed: %s", err.Error()) - return lib.RenderError(c, 500) - } - - return c.Render("configs", fiber.Map{ - "content": con, - "list": configs, - }) +func GET_Configs(c *fiber.Ctx) error { + var ( + err error + con lib.Content + configs []Config + ) + + if con, err = lib.GetContent("", "configs"); err != nil { + log.Error("GetContent failed: %s", err.Error()) + return lib.RenderError(c, 500) + } + + if configs, err = GetConfigs(); err != nil { + log.Error("GetConfigs failed: %s", err.Error()) + return lib.RenderError(c, 500) + } + + return c.Render("configs", fiber.Map{ + "content": con, + "list": configs, + }) } -func ConfigRoute(c *fiber.Ctx) error{ - name := c.Params("name") +func GET_Config(c *fiber.Ctx) error { + var ( + err error + name string + configs []Config + ) - configs, err := GetConfigs() - if err != nil { - log.Printf("GetConfigs failed: %s", err.Error()) - return lib.RenderError(c, 500) - } + name = c.Params("name") - for _, cur := range configs { - if cur.Name == name || cur.Name+".git" == name { - return c.Status(301).Redirect(cur.Redirect) - } - } + if configs, err = GetConfigs(); err != nil { + log.Error("GetConfigs failed: %s", err.Error()) + return lib.RenderError(c, 500) + } - return lib.RenderError(c, 404) + for _, cur := range configs { + if cur.Name == name || cur.Name+".git" == name { + return c.Status(301).Redirect(cur.Redirect) + } + } + + return lib.RenderError(c, 404) } diff --git a/routes/download.go b/routes/download.go index b64d09d..2615148 100644 --- a/routes/download.go +++ b/routes/download.go @@ -1,20 +1,23 @@ package routes import ( - "log" - "git.matterlinux.xyz/Matter/website/lib" + "git.matterlinux.xyz/Matter/website/log" "github.com/gofiber/fiber/v2" ) -func DownloadRoute(c *fiber.Ctx) error{ - con, err := lib.GetContent("", "download") - if err != nil { - log.Printf("GetContent failed: %s", err.Error()) - return lib.RenderError(c, 500) - } +func GET_Download(c *fiber.Ctx) error { + var ( + con lib.Content + err error + ) - return c.Render("download", fiber.Map{ - "content": con, - }) + if con, err = lib.GetContent("", "download"); err != nil { + log.Error("GetContent failed: %s", err.Error()) + return lib.RenderError(c, 500) + } + + return c.Render("download", fiber.Map{ + "content": con, + }) } diff --git a/routes/index.go b/routes/index.go index 4448057..28f880f 100644 --- a/routes/index.go +++ b/routes/index.go @@ -1,20 +1,23 @@ package routes import ( - "log" - "git.matterlinux.xyz/Matter/website/lib" + "git.matterlinux.xyz/Matter/website/log" "github.com/gofiber/fiber/v2" ) -func IndexRoute(c *fiber.Ctx) error{ - con, err := lib.GetContent("", "index") - if err != nil { - log.Printf("GetContent failed: %s", err.Error()) - return lib.RenderError(c, 500) - } +func GET_Index(c *fiber.Ctx) error { + var ( + err error + con lib.Content + ) - return c.Render("index", fiber.Map{ - "readme": con, - }) + if con, err = lib.GetContent("", "index"); err != nil { + log.Error("GetContent failed: %s", err.Error()) + return lib.RenderError(c, 500) + } + + return c.Render("index", fiber.Map{ + "readme": con, + }) } diff --git a/routes/news.go b/routes/news.go index c9f2567..889cf54 100644 --- a/routes/news.go +++ b/routes/news.go @@ -1,69 +1,69 @@ package routes import ( - "log" "sort" "git.matterlinux.xyz/Matter/website/lib" + "git.matterlinux.xyz/Matter/website/log" "github.com/gofiber/fiber/v2" ) -func NewsRoute(c *fiber.Ctx) error { - contents, err := lib.ListContent("news") - if err != nil { - log.Printf("ListContent failed: %s", err.Error()) - return lib.RenderError(c, 500) - } +func GET_News(c *fiber.Ctx) error { + contents, err := lib.ListContent("news") + if err != nil { + log.Error("ListContent failed: %s", err.Error()) + return lib.RenderError(c, 500) + } - sort.Slice(contents, func(i, j int) bool { - time1, err := lib.TimeFromString(contents[i].Date) - if err != nil { - log.Printf("Bad date while sorting: %s", err.Error()) - return false - } + sort.Slice(contents, func(i, j int) bool { + time1, err := lib.TimeFromString(contents[i].Date) + if err != nil { + log.Error("Bad date while sorting: %s", err.Error()) + return false + } - time2, err := lib.TimeFromString(contents[j].Date) - if err != nil { - log.Printf("Bad date while sorting: %s", err.Error()) - return false - } - - return time1.After(time2) - }) + time2, err := lib.TimeFromString(contents[j].Date) + if err != nil { + log.Error("Bad date while sorting: %s", err.Error()) + return false + } - return c.Render("news", fiber.Map{ - "news": contents, - }) + return time1.After(time2) + }) + + return c.Render("news", fiber.Map{ + "news": contents, + }) } -func PostRoute(c *fiber.Ctx) error { - postid := c.Params("id") - if len(postid) == 0 { - return lib.RenderError(c, 404) - } +func GET_New(c *fiber.Ctx) error { + postid := c.Params("id") + if len(postid) == 0 { + return lib.RenderError(c, 404) + } - contents, err := lib.ListContent("news") - if err != nil { - log.Printf("ListContent failed: %s", err.Error()) - return lib.RenderError(c, 500) - } + contents, err := lib.ListContent("news") + if err != nil { + log.Error("ListContent failed: %s", err.Error()) + return lib.RenderError(c, 500) + } - for _, con := range contents { - if(con.ID != postid) { - continue - } + for _, con := range contents { + if con.ID != postid { + continue + } - con, err = lib.GetContent(con.Dir, con.Name) - if err != nil { - log.Printf("ListContent failed: %s", err.Error()) - return lib.RenderError(c, 500) - } + con, err = lib.GetContent(con.Dir, con.Name) + if err != nil { + log.Error("ListContent failed: %s", err.Error()) + return lib.RenderError(c, 500) + } - return c.Render("post", fiber.Map{ - "title": con.Title, - "post": con, - }) - } + return c.Render("post", fiber.Map{ + "title": con.Title, + "post": con, + }) + } - return lib.RenderError(c, 404) + return lib.RenderError(c, 404) } diff --git a/routes/wiki.go b/routes/wiki.go index 8ebb528..1520536 100644 --- a/routes/wiki.go +++ b/routes/wiki.go @@ -1,54 +1,62 @@ package routes import ( - "log" - "git.matterlinux.xyz/Matter/website/lib" + "git.matterlinux.xyz/Matter/website/log" "github.com/gofiber/fiber/v2" ) -func WikiMainRoute(c *fiber.Ctx) error { - con, err := lib.GetContent("wiki", "main") - if err != nil { - log.Printf("GetContent failed: %s", err.Error()) - return lib.RenderError(c, 500) - } +func GET_Wiki(c *fiber.Ctx) error { + var ( + con lib.Content + err error + ) - return c.Render("post", fiber.Map{ - "title": "Wiki", - "post": con, - }) + if con, err = lib.GetContent("wiki", "main"); err != nil { + log.Error("GetContent failed: %s", err.Error()) + return lib.RenderError(c, 500) + } + + return c.Render("post", fiber.Map{ + "title": "Wiki", + "post": con, + }) } -func WikiRoute(c *fiber.Ctx) error{ - docid := c.Params("id") - if len(docid) == 0 { - return lib.RenderError(c, 404) - } +func GET_WikiPage(c *fiber.Ctx) error { + var ( + contents []lib.Content + err error + ) - contents, err := lib.ListContent("wiki") - if err != nil { - log.Printf("ListContent failed: %s", err.Error()) - return lib.RenderError(c, 500) - } + docid := c.Params("id") + if len(docid) == 0 { + return lib.RenderError(c, 404) + } - for _, con := range contents { - if(con.ID != docid) { - continue - } + if contents, err = lib.ListContent("wiki"); err != nil { + log.Error("ListContent failed: %s", err.Error()) + return lib.RenderError(c, 500) + } - con, err = lib.GetContent(con.Dir, con.Name) - if err != nil { - log.Printf("GetContent failed: %s", err.Error()) - return lib.RenderError(c, 500) - } + for _, con := range contents { + if con.ID != docid { + continue + } - con.Title = "Wiki: "+con.Title - return c.Render("post", fiber.Map{ - "title": con.Title, - "post": con, - }) - } + con, err = lib.GetContent(con.Dir, con.Name) + if err != nil { + log.Error("GetContent failed: %s", err.Error()) + return lib.RenderError(c, 500) + } - return lib.RenderError(c, 404) + con.Title = "Wiki: " + con.Title + + return c.Render("post", fiber.Map{ + "title": con.Title, + "post": con, + }) + } + + return lib.RenderError(c, 404) }