update: general formatting and cleanup
This commit is contained in:
parent
25f30b51f0
commit
87a9236e01
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,2 +1,4 @@
|
|||||||
|
docker-compose.yml
|
||||||
|
compose.yml
|
||||||
content
|
content
|
||||||
website
|
website
|
||||||
|
9
Makefile
Normal file
9
Makefile
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
all: website
|
||||||
|
|
||||||
|
website: */*.go *.go
|
||||||
|
go build -o $@
|
||||||
|
|
||||||
|
format:
|
||||||
|
gofmt -s -w .
|
||||||
|
|
||||||
|
.PHONY: format
|
25
README.md
25
README.md
@ -1,18 +1,33 @@
|
|||||||
# website | MatterLinux Website
|
# website | MatterLinux website
|
||||||
Soruce code of Matterlinux's offical website, which is
|
Soruce code of Matterlinux's offical website, which is
|
||||||
located at [matterlinux.xyz](https://matterlinux.xyz)
|
located at [matterlinux.xyz](https://matterlinux.xyz)
|
||||||
|
|
||||||
### Deployment
|
### 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
|
docker-compose up -d
|
||||||
```
|
```
|
||||||
|
|
||||||
### Managing Content
|
### Managing content
|
||||||
Website content can be managed by editing JSON and markdown files
|
Website content can be managed by editing JSON and markdown files
|
||||||
under the `content` direcotry.
|
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)
|
[content](https://git.matterlinux.xyz/Matter/content)
|
||||||
repository.
|
repository.
|
||||||
|
12
compose.yml
12
compose.yml
@ -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"
|
|
120
lib/content.go
120
lib/content.go
@ -11,86 +11,86 @@ import (
|
|||||||
|
|
||||||
const CONTENT_PATH string = "content"
|
const CONTENT_PATH string = "content"
|
||||||
|
|
||||||
type Content struct{
|
type Content struct {
|
||||||
Dir string
|
Dir string
|
||||||
Name string
|
Name string
|
||||||
|
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
|
|
||||||
Md string
|
Md string
|
||||||
HTML template.HTML
|
HTML template.HTML
|
||||||
|
|
||||||
Date string `json:"date"`
|
Date string `json:"date"`
|
||||||
Author string `json:"author"`
|
Author string `json:"author"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func ListContent(dir string) ([]Content, error) {
|
func ListContent(dir string) ([]Content, error) {
|
||||||
var res []Content
|
var res []Content
|
||||||
|
|
||||||
dirpath := path.Join(CONTENT_PATH, dir)
|
dirpath := path.Join(CONTENT_PATH, dir)
|
||||||
entries, err := os.ReadDir(dirpath)
|
entries, err := os.ReadDir(dirpath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.New("Cannot readdir: "+dirpath)
|
return nil, errors.New("Cannot readdir: " + dirpath)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, e := range entries {
|
for _, e := range entries {
|
||||||
if e.IsDir() {
|
if e.IsDir() {
|
||||||
subres, err := ListContent(path.Join(dir, e.Name()))
|
subres, err := ListContent(path.Join(dir, e.Name()))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
res = append(res, subres...)
|
res = append(res, subres...)
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!strings.HasSuffix(e.Name(), ".json")) {
|
if !strings.HasSuffix(e.Name(), ".json") {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
var con Content
|
var con Content
|
||||||
jsonfile := path.Join(dirpath, e.Name())
|
jsonfile := path.Join(dirpath, e.Name())
|
||||||
jsoncon, err := os.ReadFile(jsonfile)
|
jsoncon, err := os.ReadFile(jsonfile)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.New("Cannot get JSON: "+jsonfile)
|
return nil, errors.New("Cannot get JSON: " + jsonfile)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = json.Unmarshal(jsoncon, &con)
|
err = json.Unmarshal(jsoncon, &con)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.New("Cannot parse JSON: "+jsonfile)
|
return nil, errors.New("Cannot parse JSON: " + jsonfile)
|
||||||
}
|
}
|
||||||
|
|
||||||
con.Dir = dir
|
con.Dir = dir
|
||||||
con.Name = strings.Split(e.Name(), ".")[0]
|
con.Name = strings.Split(e.Name(), ".")[0]
|
||||||
res = append(res, con)
|
res = append(res, con)
|
||||||
}
|
}
|
||||||
|
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetContent(dir string, name string) (Content, error) {
|
func GetContent(dir string, name string) (Content, error) {
|
||||||
var res Content
|
var res Content
|
||||||
jsonfile := path.Join(CONTENT_PATH, dir, name+".json")
|
jsonfile := path.Join(CONTENT_PATH, dir, name+".json")
|
||||||
mdfile := path.Join(CONTENT_PATH, dir, name+".md")
|
mdfile := path.Join(CONTENT_PATH, dir, name+".md")
|
||||||
|
|
||||||
res.Dir = dir
|
res.Dir = dir
|
||||||
res.Name = name
|
res.Name = name
|
||||||
|
|
||||||
jsoncontent, err := os.ReadFile(jsonfile)
|
jsoncontent, err := os.ReadFile(jsonfile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, errors.New("Cannot read JSON file: "+jsonfile)
|
return res, errors.New("Cannot read JSON file: " + jsonfile)
|
||||||
}
|
}
|
||||||
|
|
||||||
rawcontent, err := os.ReadFile(mdfile)
|
rawcontent, err := os.ReadFile(mdfile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, errors.New("Cannot read markdown file: "+mdfile)
|
return res, errors.New("Cannot read markdown file: " + mdfile)
|
||||||
}
|
}
|
||||||
|
|
||||||
if(json.Unmarshal(jsoncontent, &res)!= nil) {
|
if json.Unmarshal(jsoncontent, &res) != nil {
|
||||||
return res, errors.New("Cannot parse JSON: "+jsonfile)
|
return res, errors.New("Cannot parse JSON: " + jsonfile)
|
||||||
}
|
}
|
||||||
|
|
||||||
res.Md = string(rawcontent)
|
res.Md = string(rawcontent)
|
||||||
res.HTML = template.HTML(ParseMarkdown(res.Md))
|
res.HTML = template.HTML(ParseMarkdown(res.Md))
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
58
lib/util.go
58
lib/util.go
@ -12,44 +12,44 @@ import (
|
|||||||
// python3 -c "import string; print(string.ascii_letters+string.digits+\" /,_-?!'\\\"\")"
|
// python3 -c "import string; print(string.ascii_letters+string.digits+\" /,_-?!'\\\"\")"
|
||||||
var valid string = `abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 /,_-?!'"`
|
var valid string = `abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 /,_-?!'"`
|
||||||
|
|
||||||
func IsStringValid(s string) bool{
|
func IsStringValid(s string) bool {
|
||||||
for _, c := range s {
|
for _, c := range s {
|
||||||
if !strings.Contains(valid, string(c)){
|
if !strings.Contains(valid, string(c)) {
|
||||||
fmt.Printf("%c\n", c)
|
fmt.Printf("%c\n", c)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func RenderError(c *fiber.Ctx, code int) error{
|
func RenderError(c *fiber.Ctx, code int) error {
|
||||||
var msg string = "Server Error"
|
var msg string = "Server Error"
|
||||||
c.Status(code)
|
c.Status(code)
|
||||||
|
|
||||||
switch code {
|
switch code {
|
||||||
case 404:
|
case 404:
|
||||||
msg = "Not Found"
|
msg = "Not Found"
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.Render("error", fiber.Map{
|
return c.Render("error", fiber.Map{
|
||||||
"msg": msg,
|
"msg": msg,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TimeFromString(date string) (time.Time, error) {
|
func TimeFromString(date string) (time.Time, error) {
|
||||||
res, err := time.Parse("02/01/06", date)
|
res, err := time.Parse("02/01/06", date)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
return time.Now(), nil
|
return time.Now(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func ParseMarkdown(md string) string {
|
func ParseMarkdown(md string) string {
|
||||||
ext := blackfriday.FencedCode
|
ext := blackfriday.FencedCode
|
||||||
ext |= blackfriday.BackslashLineBreak
|
ext |= blackfriday.BackslashLineBreak
|
||||||
ext |= blackfriday.Strikethrough
|
ext |= blackfriday.Strikethrough
|
||||||
ext |= blackfriday.Tables
|
ext |= blackfriday.Tables
|
||||||
ext |= blackfriday.NoEmptyLineBeforeBlock
|
ext |= blackfriday.NoEmptyLineBeforeBlock
|
||||||
|
|
||||||
return string(blackfriday.Run([]byte(md), blackfriday.WithExtensions(ext)))
|
return string(blackfriday.Run([]byte(md), blackfriday.WithExtensions(ext)))
|
||||||
}
|
}
|
||||||
|
23
log/log.go
Normal file
23
log/log.go
Normal file
@ -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...)
|
||||||
|
}
|
55
main.go
55
main.go
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
|
|
||||||
* website | MatterLinux Official Website
|
* website | MatterLinux website
|
||||||
* MatterLinux 2023-2024 (https://matterlinux.xyz)
|
* MatterLinux 2023-2024 (https://matterlinux.xyz)
|
||||||
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
@ -21,44 +21,43 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
|
||||||
|
|
||||||
"git.matterlinux.xyz/Matter/website/lib"
|
"git.matterlinux.xyz/Matter/website/lib"
|
||||||
|
"git.matterlinux.xyz/Matter/website/log"
|
||||||
"git.matterlinux.xyz/Matter/website/routes"
|
"git.matterlinux.xyz/Matter/website/routes"
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
"github.com/gofiber/template/html/v2"
|
"github.com/gofiber/template/html/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main(){
|
func main() {
|
||||||
log.SetFlags(log.Lshortfile | log.Ltime)
|
var err error
|
||||||
|
|
||||||
engine := html.New("./templates", ".html")
|
engine := html.New("./templates", ".html")
|
||||||
app := fiber.New(fiber.Config{
|
app := fiber.New(fiber.Config{
|
||||||
DisableStartupMessage: true,
|
DisableStartupMessage: true,
|
||||||
Views: engine,
|
Views: engine,
|
||||||
})
|
})
|
||||||
app.Static("/", "./public")
|
app.Static("/", "./public")
|
||||||
app.Static("/assets", "./content/assets")
|
app.Static("/assets", "./content/assets")
|
||||||
|
|
||||||
app.Get("/", routes.IndexRoute)
|
app.Get("/", routes.GET_Index)
|
||||||
app.Get("/download", routes.DownloadRoute)
|
app.Get("/download", routes.GET_Download)
|
||||||
|
|
||||||
app.Get("/news", routes.NewsRoute)
|
app.Get("/news", routes.GET_News)
|
||||||
app.Get("/news/:id", routes.PostRoute)
|
app.Get("/news/:id", routes.GET_New)
|
||||||
|
|
||||||
app.Get("/wiki", routes.WikiMainRoute)
|
app.Get("/wiki", routes.GET_Wiki)
|
||||||
app.Get("/wiki/:id", routes.WikiRoute)
|
app.Get("/wiki/:id", routes.GET_WikiPage)
|
||||||
|
|
||||||
app.Get("/hub", routes.ConfigsRoute)
|
app.Get("/hub", routes.GET_Configs)
|
||||||
app.Get("/hub/:name", routes.ConfigRoute)
|
app.Get("/hub/:name", routes.GET_Config)
|
||||||
|
|
||||||
app.Get("*", func(c *fiber.Ctx) error {
|
app.Get("*", func(c *fiber.Ctx) error {
|
||||||
return lib.RenderError(c, 404)
|
return lib.RenderError(c, 404)
|
||||||
})
|
})
|
||||||
|
|
||||||
log.Println("Starting MatterLinux Website on port 9878")
|
log.Info("Starting MatterLinux website on port 9878")
|
||||||
err := app.Listen(":9878")
|
|
||||||
if err != nil {
|
if err = app.Listen(":9878"); err != nil {
|
||||||
log.Fatalf("Error starting server: %s", err)
|
log.Error("Error starting server: %s", err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
background: var(--dark-second);
|
background: var(--dark-second);
|
||||||
border: solid 1px var(--bright-main);
|
border: solid 1px var(--bright-second);
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
main {
|
main {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
padding-top: 50px;
|
padding-top: 40px;
|
||||||
gap: 10px;
|
gap: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,137 +4,145 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"git.matterlinux.xyz/Matter/website/lib"
|
"git.matterlinux.xyz/Matter/website/lib"
|
||||||
|
"git.matterlinux.xyz/Matter/website/log"
|
||||||
"github.com/bigkevmcd/go-configparser"
|
"github.com/bigkevmcd/go-configparser"
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Redirect string `json:"redirect"`
|
Redirect string `json:"redirect"`
|
||||||
Image string `json:"image"`
|
Image string `json:"image"`
|
||||||
Url string `json:"url"`
|
Url string `json:"url"`
|
||||||
|
|
||||||
Name string
|
Name string
|
||||||
Desc string
|
Desc string
|
||||||
Author string
|
Author string
|
||||||
Keywords string
|
Keywords string
|
||||||
}
|
}
|
||||||
|
|
||||||
func LoadConfig(c *Config) (error) {
|
func (c *Config) Load() error {
|
||||||
agent := fiber.Get(c.Url)
|
agent := fiber.Get(c.Url)
|
||||||
code, body, errs := agent.Bytes()
|
code, body, errs := agent.Bytes()
|
||||||
if len(errs) > 0 {
|
if len(errs) > 0 {
|
||||||
return fmt.Errorf("request to %s failed", c.Url)
|
return fmt.Errorf("request to %s failed", c.Url)
|
||||||
}
|
}
|
||||||
|
|
||||||
if code != 200 {
|
if code != 200 {
|
||||||
return fmt.Errorf("bad response from %s", c.Url)
|
return fmt.Errorf("bad response from %s", c.Url)
|
||||||
}
|
}
|
||||||
|
|
||||||
parser := configparser.New()
|
parser := configparser.New()
|
||||||
err := parser.ParseReader(bytes.NewReader(body))
|
err := parser.ParseReader(bytes.NewReader(body))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to parse %s: %s", c.Url, err.Error())
|
return fmt.Errorf("failed to parse %s: %s", c.Url, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
name, err := parser.Get("details", "name")
|
name, err := parser.Get("details", "name")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed get details/name: %s", c.Url)
|
return fmt.Errorf("failed get details/name: %s", c.Url)
|
||||||
}
|
}
|
||||||
|
|
||||||
keywords, err := parser.Get("details", "keywords")
|
keywords, err := parser.Get("details", "keywords")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed get details/keywords: %s", c.Url)
|
return fmt.Errorf("failed get details/keywords: %s", c.Url)
|
||||||
}
|
}
|
||||||
|
|
||||||
author, err := parser.Get("details", "author")
|
author, err := parser.Get("details", "author")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed get details/keywords: %s", c.Url)
|
return fmt.Errorf("failed get details/keywords: %s", c.Url)
|
||||||
}
|
}
|
||||||
|
|
||||||
desc, err := parser.Get("details", "desc")
|
desc, err := parser.Get("details", "desc")
|
||||||
|
|
||||||
c.Name = name
|
c.Name = name
|
||||||
c.Desc = desc
|
c.Desc = desc
|
||||||
c.Author = author
|
c.Author = author
|
||||||
c.Keywords = strings.ReplaceAll(keywords, ",", ", ")
|
c.Keywords = strings.ReplaceAll(keywords, ",", ", ")
|
||||||
|
|
||||||
if(!lib.IsStringValid(c.Name) ||
|
if !lib.IsStringValid(c.Name) ||
|
||||||
!lib.IsStringValid(c.Desc) ||
|
!lib.IsStringValid(c.Desc) ||
|
||||||
!lib.IsStringValid(c.Author) ||
|
!lib.IsStringValid(c.Author) ||
|
||||||
!lib.IsStringValid(c.Keywords)){
|
!lib.IsStringValid(c.Keywords) {
|
||||||
return fmt.Errorf("keywords or name contain illegal chars: %s", c.Url)
|
return fmt.Errorf("keywords or name contain illegal chars: %s", c.Url)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetConfigs() ([]Config, error) {
|
func GetConfigs() ([]Config, error) {
|
||||||
var data map[string][]Config
|
var data map[string][]Config
|
||||||
|
|
||||||
configs_path := path.Join(lib.CONTENT_PATH, "configs.json")
|
configs_path := path.Join(lib.CONTENT_PATH, "configs.json")
|
||||||
raw, err := os.ReadFile(configs_path)
|
raw, err := os.ReadFile(configs_path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = json.Unmarshal(raw, &data)
|
err = json.Unmarshal(raw, &data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, ok := data["list"]; !ok {
|
if _, ok := data["list"]; !ok {
|
||||||
return nil, fmt.Errorf("json data does not contain the list key")
|
return nil, fmt.Errorf("json data does not contain the list key")
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := range data["list"] {
|
for i := range data["list"] {
|
||||||
err = LoadConfig(&data["list"][i])
|
if err = data["list"][i].Load(); err != nil {
|
||||||
if err != nil {
|
return nil, err
|
||||||
return nil, err
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return data["list"], nil
|
return data["list"], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func ConfigsRoute(c *fiber.Ctx) error{
|
func GET_Configs(c *fiber.Ctx) error {
|
||||||
con, err := lib.GetContent("", "configs")
|
var (
|
||||||
if err != nil {
|
err error
|
||||||
log.Printf("GetContent failed: %s", err.Error())
|
con lib.Content
|
||||||
return lib.RenderError(c, 500)
|
configs []Config
|
||||||
}
|
)
|
||||||
|
|
||||||
configs, err := GetConfigs()
|
if con, err = lib.GetContent("", "configs"); err != nil {
|
||||||
if err != nil {
|
log.Error("GetContent failed: %s", err.Error())
|
||||||
log.Printf("GetConfigs failed: %s", err.Error())
|
return lib.RenderError(c, 500)
|
||||||
return lib.RenderError(c, 500)
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return c.Render("configs", fiber.Map{
|
if configs, err = GetConfigs(); err != nil {
|
||||||
"content": con,
|
log.Error("GetConfigs failed: %s", err.Error())
|
||||||
"list": configs,
|
return lib.RenderError(c, 500)
|
||||||
})
|
}
|
||||||
|
|
||||||
|
return c.Render("configs", fiber.Map{
|
||||||
|
"content": con,
|
||||||
|
"list": configs,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func ConfigRoute(c *fiber.Ctx) error{
|
func GET_Config(c *fiber.Ctx) error {
|
||||||
name := c.Params("name")
|
var (
|
||||||
|
err error
|
||||||
|
name string
|
||||||
|
configs []Config
|
||||||
|
)
|
||||||
|
|
||||||
configs, err := GetConfigs()
|
name = c.Params("name")
|
||||||
if err != nil {
|
|
||||||
log.Printf("GetConfigs failed: %s", err.Error())
|
|
||||||
return lib.RenderError(c, 500)
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, cur := range configs {
|
if configs, err = GetConfigs(); err != nil {
|
||||||
if cur.Name == name || cur.Name+".git" == name {
|
log.Error("GetConfigs failed: %s", err.Error())
|
||||||
return c.Status(301).Redirect(cur.Redirect)
|
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)
|
||||||
}
|
}
|
||||||
|
@ -1,20 +1,23 @@
|
|||||||
package routes
|
package routes
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
|
||||||
|
|
||||||
"git.matterlinux.xyz/Matter/website/lib"
|
"git.matterlinux.xyz/Matter/website/lib"
|
||||||
|
"git.matterlinux.xyz/Matter/website/log"
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func DownloadRoute(c *fiber.Ctx) error{
|
func GET_Download(c *fiber.Ctx) error {
|
||||||
con, err := lib.GetContent("", "download")
|
var (
|
||||||
if err != nil {
|
con lib.Content
|
||||||
log.Printf("GetContent failed: %s", err.Error())
|
err error
|
||||||
return lib.RenderError(c, 500)
|
)
|
||||||
}
|
|
||||||
|
|
||||||
return c.Render("download", fiber.Map{
|
if con, err = lib.GetContent("", "download"); err != nil {
|
||||||
"content": con,
|
log.Error("GetContent failed: %s", err.Error())
|
||||||
})
|
return lib.RenderError(c, 500)
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.Render("download", fiber.Map{
|
||||||
|
"content": con,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
@ -1,20 +1,23 @@
|
|||||||
package routes
|
package routes
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
|
||||||
|
|
||||||
"git.matterlinux.xyz/Matter/website/lib"
|
"git.matterlinux.xyz/Matter/website/lib"
|
||||||
|
"git.matterlinux.xyz/Matter/website/log"
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func IndexRoute(c *fiber.Ctx) error{
|
func GET_Index(c *fiber.Ctx) error {
|
||||||
con, err := lib.GetContent("", "index")
|
var (
|
||||||
if err != nil {
|
err error
|
||||||
log.Printf("GetContent failed: %s", err.Error())
|
con lib.Content
|
||||||
return lib.RenderError(c, 500)
|
)
|
||||||
}
|
|
||||||
|
|
||||||
return c.Render("index", fiber.Map{
|
if con, err = lib.GetContent("", "index"); err != nil {
|
||||||
"readme": con,
|
log.Error("GetContent failed: %s", err.Error())
|
||||||
})
|
return lib.RenderError(c, 500)
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.Render("index", fiber.Map{
|
||||||
|
"readme": con,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
@ -1,69 +1,69 @@
|
|||||||
package routes
|
package routes
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
"git.matterlinux.xyz/Matter/website/lib"
|
"git.matterlinux.xyz/Matter/website/lib"
|
||||||
|
"git.matterlinux.xyz/Matter/website/log"
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewsRoute(c *fiber.Ctx) error {
|
func GET_News(c *fiber.Ctx) error {
|
||||||
contents, err := lib.ListContent("news")
|
contents, err := lib.ListContent("news")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("ListContent failed: %s", err.Error())
|
log.Error("ListContent failed: %s", err.Error())
|
||||||
return lib.RenderError(c, 500)
|
return lib.RenderError(c, 500)
|
||||||
}
|
}
|
||||||
|
|
||||||
sort.Slice(contents, func(i, j int) bool {
|
sort.Slice(contents, func(i, j int) bool {
|
||||||
time1, err := lib.TimeFromString(contents[i].Date)
|
time1, err := lib.TimeFromString(contents[i].Date)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Bad date while sorting: %s", err.Error())
|
log.Error("Bad date while sorting: %s", err.Error())
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
time2, err := lib.TimeFromString(contents[j].Date)
|
time2, err := lib.TimeFromString(contents[j].Date)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Bad date while sorting: %s", err.Error())
|
log.Error("Bad date while sorting: %s", err.Error())
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
return time1.After(time2)
|
return time1.After(time2)
|
||||||
})
|
})
|
||||||
|
|
||||||
return c.Render("news", fiber.Map{
|
return c.Render("news", fiber.Map{
|
||||||
"news": contents,
|
"news": contents,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func PostRoute(c *fiber.Ctx) error {
|
func GET_New(c *fiber.Ctx) error {
|
||||||
postid := c.Params("id")
|
postid := c.Params("id")
|
||||||
if len(postid) == 0 {
|
if len(postid) == 0 {
|
||||||
return lib.RenderError(c, 404)
|
return lib.RenderError(c, 404)
|
||||||
}
|
}
|
||||||
|
|
||||||
contents, err := lib.ListContent("news")
|
contents, err := lib.ListContent("news")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("ListContent failed: %s", err.Error())
|
log.Error("ListContent failed: %s", err.Error())
|
||||||
return lib.RenderError(c, 500)
|
return lib.RenderError(c, 500)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, con := range contents {
|
for _, con := range contents {
|
||||||
if(con.ID != postid) {
|
if con.ID != postid {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
con, err = lib.GetContent(con.Dir, con.Name)
|
con, err = lib.GetContent(con.Dir, con.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("ListContent failed: %s", err.Error())
|
log.Error("ListContent failed: %s", err.Error())
|
||||||
return lib.RenderError(c, 500)
|
return lib.RenderError(c, 500)
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.Render("post", fiber.Map{
|
return c.Render("post", fiber.Map{
|
||||||
"title": con.Title,
|
"title": con.Title,
|
||||||
"post": con,
|
"post": con,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return lib.RenderError(c, 404)
|
return lib.RenderError(c, 404)
|
||||||
}
|
}
|
||||||
|
@ -1,54 +1,62 @@
|
|||||||
package routes
|
package routes
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
|
||||||
|
|
||||||
"git.matterlinux.xyz/Matter/website/lib"
|
"git.matterlinux.xyz/Matter/website/lib"
|
||||||
|
"git.matterlinux.xyz/Matter/website/log"
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func WikiMainRoute(c *fiber.Ctx) error {
|
func GET_Wiki(c *fiber.Ctx) error {
|
||||||
con, err := lib.GetContent("wiki", "main")
|
var (
|
||||||
if err != nil {
|
con lib.Content
|
||||||
log.Printf("GetContent failed: %s", err.Error())
|
err error
|
||||||
return lib.RenderError(c, 500)
|
)
|
||||||
}
|
|
||||||
|
|
||||||
return c.Render("post", fiber.Map{
|
if con, err = lib.GetContent("wiki", "main"); err != nil {
|
||||||
"title": "Wiki",
|
log.Error("GetContent failed: %s", err.Error())
|
||||||
"post": con,
|
return lib.RenderError(c, 500)
|
||||||
})
|
}
|
||||||
|
|
||||||
|
return c.Render("post", fiber.Map{
|
||||||
|
"title": "Wiki",
|
||||||
|
"post": con,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func WikiRoute(c *fiber.Ctx) error{
|
func GET_WikiPage(c *fiber.Ctx) error {
|
||||||
docid := c.Params("id")
|
var (
|
||||||
if len(docid) == 0 {
|
contents []lib.Content
|
||||||
return lib.RenderError(c, 404)
|
err error
|
||||||
}
|
)
|
||||||
|
|
||||||
contents, err := lib.ListContent("wiki")
|
docid := c.Params("id")
|
||||||
if err != nil {
|
if len(docid) == 0 {
|
||||||
log.Printf("ListContent failed: %s", err.Error())
|
return lib.RenderError(c, 404)
|
||||||
return lib.RenderError(c, 500)
|
}
|
||||||
}
|
|
||||||
|
|
||||||
for _, con := range contents {
|
if contents, err = lib.ListContent("wiki"); err != nil {
|
||||||
if(con.ID != docid) {
|
log.Error("ListContent failed: %s", err.Error())
|
||||||
continue
|
return lib.RenderError(c, 500)
|
||||||
}
|
}
|
||||||
|
|
||||||
con, err = lib.GetContent(con.Dir, con.Name)
|
for _, con := range contents {
|
||||||
if err != nil {
|
if con.ID != docid {
|
||||||
log.Printf("GetContent failed: %s", err.Error())
|
continue
|
||||||
return lib.RenderError(c, 500)
|
}
|
||||||
}
|
|
||||||
|
|
||||||
con.Title = "Wiki: "+con.Title
|
con, err = lib.GetContent(con.Dir, con.Name)
|
||||||
return c.Render("post", fiber.Map{
|
if err != nil {
|
||||||
"title": con.Title,
|
log.Error("GetContent failed: %s", err.Error())
|
||||||
"post": con,
|
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)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user