BREAKING Change the way bookmark.json is written with Categories

This commit is contained in:
Florian Hoss 2022-12-01 08:56:34 +01:00
parent 54426e661d
commit 7bb7acf84f
6 changed files with 20 additions and 20 deletions

View file

@ -43,7 +43,7 @@ The name and related link can be provided as well.
```json
[
{
"DESCRIPTION": "First",
"CATEGORY": "First",
"BOOKMARKS": [
{
"NAME": "Github",
@ -58,7 +58,7 @@ The name and related link can be provided as well.
]
},
{
"DESCRIPTION": "",
"CATEGORY": "",
"BOOKMARKS": [
{
"NAME": "Github",
@ -68,7 +68,7 @@ The name and related link can be provided as well.
]
},
{
"DESCRIPTION": "Third",
"CATEGORY": "Third",
"BOOKMARKS": [
{
"NAME": "Github",

View file

@ -11,7 +11,7 @@ import (
"strings"
)
var Categories []Category
var Entries []Entry
const StorageDir = "storage/"
const IconsDir = StorageDir + "icons/"
@ -66,7 +66,7 @@ func readBookmarksFile() []byte {
}
func replaceIconString() {
for _, v := range Categories {
for _, v := range Entries {
for i, bookmark := range v.Bookmarks {
if !strings.Contains(bookmark.Icon, "http") {
v.Bookmarks[i].Icon = "/" + IconsDir + bookmark.Icon
@ -77,7 +77,7 @@ func replaceIconString() {
func parseBookmarks() {
byteValue := readBookmarksFile()
err := json.Unmarshal(byteValue, &Categories)
err := json.Unmarshal(byteValue, &Entries)
if err != nil {
logrus.WithField("file", bookmarksFile).Error(message.CannotParse.String())
return
@ -106,7 +106,7 @@ func watchBookmarks() {
return
}
parseBookmarks()
logrus.WithField("bookmarks", len(Categories)).Trace(bookmarksFile + " changed")
logrus.WithField("bookmarks", len(Entries)).Trace(bookmarksFile + " changed")
}
}
}()

View file

@ -1,8 +1,8 @@
package bookmark
type Category struct {
Description string `json:"description"`
Bookmarks []Bookmark `json:"bookmarks"`
type Entry struct {
Category string `json:"category"`
Bookmarks []Bookmark `json:"bookmarks"`
}
type Bookmark struct {

View file

@ -1,6 +1,6 @@
[
{
"DESCRIPTION": "First",
"CATEGORY": "First",
"BOOKMARKS": [
{
"NAME": "Github",
@ -10,7 +10,7 @@
]
},
{
"DESCRIPTION": "",
"CATEGORY": "",
"BOOKMARKS": [
{
"NAME": "Github",
@ -20,7 +20,7 @@
]
},
{
"DESCRIPTION": "Third",
"CATEGORY": "Third",
"BOOKMARKS": [
{
"NAME": "Github",

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,
"Categories": bookmark.Categories,
"Weather": weather.CurrentWeather,
"System": system.Sys,
"Title": server.Title,
"Entries": bookmark.Entries,
"Weather": weather.CurrentWeather,
"System": system.Sys,
})
}

View file

@ -121,10 +121,10 @@
<div class="grid gap-8">
{{ range .Categories }}
{{ range .Entries }}
<div class="grid gap-4">
{{ if .Description }}
<div class="text-lg text-primary font-thin tracking-wider select-none truncate">{{ .Description }}</div>
{{ if .Category }}
<div class="text-lg text-primary font-thin tracking-wider select-none truncate">{{ .Category }}</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 }}