Add the option to use categories

This commit is contained in:
Florian Hoss 2022-11-30 17:26:20 +01:00
parent 756916af93
commit cd041ab34a
7 changed files with 79 additions and 37 deletions

View file

@ -2,6 +2,7 @@ package bookmark
import (
"encoding/json"
"fmt"
"github.com/fsnotify/fsnotify"
"github.com/sirupsen/logrus"
folderCreate "github.com/unjx-de/go-folder"
@ -11,7 +12,7 @@ import (
"strings"
)
var Bookmarks []Bookmark
var Categories []Category
const StorageDir = "storage/"
const IconsDir = StorageDir + "icons/"
@ -66,20 +67,23 @@ func readBookmarksFile() []byte {
}
func replaceIconString() {
for i, v := range Bookmarks {
if !strings.Contains(v.Icon, "http") {
Bookmarks[i].Icon = "/" + IconsDir + v.Icon
for _, v := range Categories {
for _, bookmark := range v.Bookmarks {
if !strings.Contains(bookmark.Icon, "http") {
bookmark.Icon = "/" + IconsDir + bookmark.Icon
}
}
}
}
func parseBookmarks() {
byteValue := readBookmarksFile()
err := json.Unmarshal(byteValue, &Bookmarks)
err := json.Unmarshal(byteValue, &Categories)
if err != nil {
logrus.WithField("file", bookmarksFile).Error(message.CannotParse.String())
return
}
fmt.Println(Categories)
replaceIconString()
}
@ -104,7 +108,7 @@ func watchBookmarks() {
return
}
parseBookmarks()
logrus.WithField("bookmarks", len(Bookmarks)).Trace(bookmarksFile + " changed")
logrus.WithField("bookmarks", len(Categories)).Trace(bookmarksFile + " changed")
}
}
}()

View file

@ -1,7 +1,12 @@
package bookmark
type Bookmark struct {
Name string `json:"name" validate:"required"`
Icon string `json:"icon" validate:"required"`
Url string `json:"url" validate:"required"`
type Category struct {
Description string `json:"description"`
Bookmarks []Bookmark `json:"bookmarks"`
}
type Bookmark struct {
Name string `json:"name"`
Icon string `json:"icon"`
Url string `json:"url"`
}

View file

@ -1,7 +1,32 @@
[
{
"NAME": "Github",
"ICON": "https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png",
"URL": "https://github.com"
"DESCRIPTION": "First",
"BOOKMARKS": [
{
"NAME": "Github",
"ICON": "https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png",
"URL": "https://github.com"
}
]
},
{
"DESCRIPTION": "",
"BOOKMARKS": [
{
"NAME": "Github",
"ICON": "https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png",
"URL": "https://github.com"
}
]
},
{
"DESCRIPTION": "Third",
"BOOKMARKS": [
{
"NAME": "Github",
"ICON": "https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png",
"URL": "https://github.com"
}
]
}
]
]

View file

@ -15,10 +15,10 @@ import (
func (server *Server) goDash(c context.Context, ctx *app.RequestContext) {
ctx.HTML(consts.StatusOK, "index.gohtml", utils.H{
"Title": server.Title,
"Bookmarks": bookmark.Bookmarks,
"Weather": weather.CurrentWeather,
"System": system.Sys,
"Title": server.Title,
"Categories": bookmark.Categories,
"Weather": weather.CurrentWeather,
"System": system.Sys,
})
}

View file

@ -18,4 +18,7 @@
.extra-sun-icon {
@apply h-4 w-4 shrink-0 -mb-1 mr-2;
}
.extra-system-info {
@apply text-primary text-xs truncate font-thin tracking-wider;
}
}

View file

@ -23,7 +23,7 @@
</head>
<body>
<div class="mx-auto max-w-7xl px-5 lg:px-8 my-3 md:my-10 lg:mt-18 lg:mb-10 xl:mt-28 xl:mb-18">{{ template "content" . }}</div>
<div class="mx-auto container px-5 lg:px-8 my-3 md:my-10 lg:my-14 xl:my-20">{{ template "content" . }}</div>
</body>
</html>
{{ end }}

View file

@ -18,7 +18,7 @@
<div class="text-4xl md:text-4xl">
<span id="weatherTemp">{{ .Weather.Temp }}</span> {{ .Weather.Units }}
</div>
<div class="flex items-center gap-5 text-xs">
<div class="flex items-center gap-5 text-xs font-thin tracking-wider">
<div class="flex items-center">
<svg class="extra-icon">
<use xlink:href="#quote"></use>
@ -58,7 +58,7 @@
<use xlink:href="#cpu"></use>
</svg>
<div class="w-full truncate">
<div class="text-primary text-xs truncate">{{ .System.Static.CPU.Threads }}</div>
<div class="extra-system-info">{{ .System.Static.CPU.Threads }}</div>
<div class="truncate">{{ .System.Static.CPU.Name }}</div>
<div class="progress-bar-wrapper">
<div id="systemCpuPercentage" class="progress-bar" style="width: {{ .System.Live.CPU }}%"></div>
@ -70,7 +70,7 @@
<use xlink:href="#ram"></use>
</svg>
<div class="w-full truncate">
<div class="text-primary text-xs truncate">{{ .System.Static.Ram.Swap }}</div>
<div class="extra-system-info">{{ .System.Static.Ram.Swap }}</div>
<div class="truncate">
<span id="systemRamValue">{{ .System.Live.Ram.Value }}</span> /
{{ .System.Static.Ram.Total }}
@ -86,7 +86,7 @@
<use xlink:href="#disk"></use>
</svg>
<div class="w-full truncate">
<div class="text-primary text-xs truncate">{{ .System.Static.Disk.Partitions }}</div>
<div class="extra-system-info">{{ .System.Static.Disk.Partitions }}</div>
<div class="truncate">
<span id="systemDiskValue">{{ .System.Live.Disk.Value }}</span> /
{{ .System.Static.Disk.Total }}
@ -102,11 +102,7 @@
<use xlink:href="#server"></use>
</svg>
<div class="w-full truncate">
<div class="flex items-center gap-5 text-xs">
<div class="truncate">
<div class="text-primary">{{ .System.Static.Host.Architecture }}</div>
</div>
</div>
<div class="extra-system-info">{{ .System.Static.Host.Architecture }}</div>
<div class="flex items-center gap-2 truncate">
<div class="truncate">
<span><span id="uptimeDays">{{ .System.Live.Uptime.Days }}</span> days</span>
@ -124,15 +120,24 @@
{{ end }}
<div class="grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 xl:grid-cols-6 gap-5">
{{ range .Bookmarks }}
<a
href="{{ .Url }}"
class="bookmark-link flex items-center no-underline md:hover:underline underline-offset-2 decoration-primary text-sm text-slate-700 dark:text-slate-300 hover:text-slate-900 dark:hover:text-slate-50 transition-all ease-linear duration-150"
>
<div class="img rounded-md w-8 h-8 bg-cover bg-center opacity-90" style="background-image: url({{ .Icon }})"></div>
<div class="uppercase truncate ml-2">{{ .Name }}</div>
</a>
<div class="grid gap-8">
{{ range .Categories }}
<div class="grid gap-4">
{{ if .Description }}
<div class="text-lg text-primary font-thin tracking-wider select-none truncate">{{ .Description }}</div>
{{ end }}
<div class="grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 xl:grid-cols-6 gap-4">
{{ range .Bookmarks }}
<a
href="{{ .Url }}"
class="bookmark-link flex items-center no-underline md:hover:underline underline-offset-2 decoration-primary text-sm text-slate-700 dark:text-slate-300 hover:text-slate-900 dark:hover:text-slate-50 transition-all ease-linear duration-150"
>
<div class="img rounded-md w-8 h-8 bg-cover bg-center opacity-90" style="background-image: url({{ .Icon }})"></div>
<div class="uppercase truncate ml-2">{{ .Name }}</div>
</a>
{{ end }}
</div>
</div>
{{ end }}
</div>
{{ end }}