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{
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, "")
}

33
main.go
View File

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

View File

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

View File

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

View File

@ -1,12 +1,11 @@
<div class="bar">
<div class="logo-div">
<h1 class="logo">MatterLinux</h1>
</div>
<div class="links">
<a href="https://matterlinux.xyz">Home</a>
<a href="https://matterlinux.xyz/news">News</a>
<a href="https://matterlinux.xyz/wiki">Wiki</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>