Updating css to match with the website, changing search route to GET from POST

This commit is contained in:
ngn 2024-01-18 20:25:33 +03:00
parent c447b632d9
commit 564ccaa109
5 changed files with 37 additions and 50 deletions

View File

@ -94,9 +94,9 @@ func GetTimePassed(t time.Time) string {
} }
func CleanString(s string) string{ func CleanString(s string) string{
var possible_bad_char_list_that_i_made_up_which_may_contain_bad_xss_chars_look_im_not_gonna_search_for_a_xss_charlist_just_to_prevent_self_xss []string = []string{"'", "\"", "/", "<", ">", "?", "=", "#", "(", ")", "{", "}", "*", "!", "`", "[", "]"} var badchars []string = []string{"~", "'", "\"", "/", "<", ">", "?", "=", "#", "(", ")", "{", "}", "*", "!", "`", "[", "]"}
for _, c := range possible_bad_char_list_that_i_made_up_which_may_contain_bad_xss_chars_look_im_not_gonna_search_for_a_xss_charlist_just_to_prevent_self_xss { for _, c := range badchars {
s = strings.ReplaceAll(s, c, "") s = strings.ReplaceAll(s, c, "")
} }

45
main.go
View File

@ -30,11 +30,6 @@ import (
"github.com/gofiber/template/html/v2" "github.com/gofiber/template/html/v2"
) )
type PostData struct {
Repo string `form:"repo"`
Name string `form:"name"`
}
var lastupdate time.Time var lastupdate time.Time
var updatetick = time.NewTicker(time.Hour) var updatetick = time.NewTicker(time.Hour)
var stopchan = make(chan struct{}) var stopchan = make(chan struct{})
@ -59,39 +54,44 @@ func UpdatePackages() {
} }
func GETIndex(c *fiber.Ctx) error { func GETIndex(c *fiber.Ctx) error {
return c.Render("index", fiber.Map{ repo := c.Query("r")
"last": lib.GetTimePassed(lastupdate), name := c.Query("n")
"repos": lib.Repos, exact := c.Query("e")
"pkgs": lib.Packages,
}) if repo == "" && name == "" {
} return c.Render("index", fiber.Map{
"last": lib.GetTimePassed(lastupdate),
func POSTIndex(c *fiber.Ctx) error { "repos": lib.Repos,
var pdata PostData "pkgs": lib.Packages,
err := c.BodyParser(&pdata) })
if err != nil || pdata.Name == ""{
return c.Redirect("/")
} }
name = lib.CleanString(name)
var res []lib.Package var res []lib.Package
pdata.Name = lib.CleanString(pdata.Name)
for _, p := range lib.Packages { for _, p := range lib.Packages {
if(pdata.Repo != "all" && p.Repo != pdata.Repo){ if(repo != "all" && p.Repo != repo){
continue continue
} }
if(strings.Contains(p.Name, pdata.Name)){ if(exact == ""){
res = append(res, p) if(strings.Contains(p.Name, name)){
res = append(res, p)
}
}else {
if (p.Name == name) {
res = append(res, p)
}
} }
} }
return c.Render("index", fiber.Map{ return c.Render("index", fiber.Map{
"search": pdata.Name, "search": name,
"last": lib.GetTimePassed(lastupdate), "last": lib.GetTimePassed(lastupdate),
"repos": lib.Repos, "repos": lib.Repos,
"pkgs": res, "pkgs": res,
}) })
} }
func main(){ func main(){
@ -103,7 +103,6 @@ func main(){
app.Static("/", "./public") app.Static("/", "./public")
app.Get("/", GETIndex) app.Get("/", GETIndex)
app.Post("/", POSTIndex)
app.Get("*", func(c *fiber.Ctx) error { app.Get("*", func(c *fiber.Ctx) error {
return lib.RenderError(c, 404) return lib.RenderError(c, 404)

View File

@ -2,8 +2,8 @@
:root { :root {
--dark-main: black; --dark-main: black;
--dark-second: #070707; --dark-second: #090909;
--dark-third: #151515; --dark-third: #181818;
--bright-main: white; --bright-main: white;
--bright-second: #DFDFDF; --bright-second: #DFDFDF;
--bright-third: #777777; --bright-third: #777777;
@ -38,30 +38,19 @@ main {
border-bottom: solid 1px white; border-bottom: solid 1px white;
} }
.logo-div {
display: flex;
flex-direction: row;
color: white;
gap: 15px;
}
.logo-text{
font-family: JetBrainsMono;
font-size: 25px;
}
.logo { .logo {
font-family: JetBrainsItalic; font-family: JetBrainsItalic;
color: white;
font-size: 25px; font-size: 25px;
} }
.links { .links {
display: flex; display: block;
flex-direction: row; text-align: right;
gap: 10px;
} }
.links a{ .links a{
margin-left: 7px;
color: var(--bright-main); color: var(--bright-main);
font-family: Ubuntu; font-family: Ubuntu;
font-size: 20px; font-size: 20px;

View File

@ -10,13 +10,13 @@
{{template "parts/bar" .}} {{template "parts/bar" .}}
<main> <main>
<div class="search"> <div class="search">
<form action="/" method="POST"> <form action="/" method="GET">
{{if .search}} {{if .search}}
<input placeholder="Hit enter to search" type="text" name="name" value="{{.search}}"> <input placeholder="Hit enter to search" type="text" name="n" value="{{.search}}">
{{else}} {{else}}
<input placeholder="Hit enter to search" type="text" name="name" autofocus> <input placeholder="Hit enter to search" type="text" name="n" autofocus>
{{end}} {{end}}
<select name="repo"> <select name="r">
<option value="all">Select repo</option> <option value="all">Select repo</option>
{{range .repos}} {{range .repos}}
<option value="{{.Name}}">{{.Name}}</option> <option value="{{.Name}}">{{.Name}}</option>

View File

@ -1,12 +1,11 @@
<div class="bar"> <div class="bar">
<div class="logo-div"> <h1 class="logo">MatterLinux</h1>
<h1 class="logo">MatterLinux</h1>
</div>
<div class="links"> <div class="links">
<a href="https://matterlinux.xyz">Home</a> <a href="https://matterlinux.xyz">Home</a>
<a href="https://matterlinux.xyz/news">News</a> <a href="https://matterlinux.xyz/news">News</a>
<a href="https://matterlinux.xyz/wiki">Wiki</a> <a href="https://matterlinux.xyz/wiki">Wiki</a>
<a href="https://git.matterlinux.xyz/Matter">Source</a> <a href="https://git.matterlinux.xyz/Matter">Source</a>
<a href="https://tracker.matterlinux.xyz">Packages</a> <a href="/">Packages</a>
<a href="https://matterlinux.xyz/download">Download</a>
</div> </div>
</div> </div>