diff --git a/api.go b/api.go index 82c4df35..ca3a0625 100644 --- a/api.go +++ b/api.go @@ -1,27 +1,24 @@ package main import ( - "sort" - "strings" - "github.com/aerogo/aero" "github.com/animenotifier/arn" ) func init() { - app.Get("/all/anime", func(ctx *aero.Context) string { - var titles []string + // app.Get("/all/anime", func(ctx *aero.Context) string { + // var titles []string - results := make(chan *arn.Anime) - arn.Scan("Anime", results) + // results := make(chan *arn.Anime) + // arn.Scan("Anime", results) - for anime := range results { - titles = append(titles, anime.Title.Romaji) - } - sort.Strings(titles) + // for anime := range results { + // titles = append(titles, anime.Title.Romaji) + // } + // sort.Strings(titles) - return ctx.Text(toString(len(titles)) + "\n\n" + strings.Join(titles, "\n")) - }) + // return ctx.Text(toString(len(titles)) + "\n\n" + strings.Join(titles, "\n")) + // }) app.Get("/api/anime/:id", func(ctx *aero.Context) string { id, _ := ctx.GetInt("id") diff --git a/deploy.sh b/deploy.sh index cc43cce3..0523958f 100755 --- a/deploy.sh +++ b/deploy.sh @@ -1,5 +1,5 @@ #!/bin/bash -pack -go build +#pack +#go build scp notify.moe eduard@arn:~/beta/notify.moe.new -ssh eduard@arn 'cd beta; killall notify.moe; rm notify.moe; mv notify.moe.new notify.moe; ./notify.moe &' \ No newline at end of file +ssh eduard@arn 'cd beta; killall notify.moe; rm notify.moe; mv notify.moe.new notify.moe; ./notify.moe &' diff --git a/layout/layout.pixy b/layout/layout.pixy index 228db162..c28806c3 100644 --- a/layout/layout.pixy +++ b/layout/layout.pixy @@ -23,8 +23,9 @@ component Content(content string) component Navigation nav#navigation - NavigationButton("Dash", "/", "dashboard") + NavigationButton("Dash", "/", "inbox") NavigationButton("Forum", "/forum", "comment") + NavigationButton("Genres", "/genres", "tags") component NavigationButton(name string, target string, icon string) a.navigation-link.navigation-link-left.ajax(href=target) diff --git a/main.go b/main.go index 23897f2d..5837918f 100644 --- a/main.go +++ b/main.go @@ -5,6 +5,12 @@ import ( "github.com/aerogo/aero" "github.com/animenotifier/notify.moe/components" + "github.com/animenotifier/notify.moe/pages/anime" + "github.com/animenotifier/notify.moe/pages/dashboard" + "github.com/animenotifier/notify.moe/pages/forum" + "github.com/animenotifier/notify.moe/pages/genre" + "github.com/animenotifier/notify.moe/pages/genres" + "github.com/animenotifier/notify.moe/pages/threads" ) var app = aero.New() @@ -28,5 +34,13 @@ func main() { return components.Layout(content) } + app.Ajax("/", dashboard.Get) + app.Ajax("/anime/:id", anime.Get) + app.Ajax("/genres", genres.Get) + app.Ajax("/genres/:name", genre.Get) + app.Ajax("/forum", forum.Get) + app.Ajax("/forum/:tag", forum.Get) + app.Ajax("/threads/:id", threads.Get) + app.Run() } diff --git a/pages/anime/anime.go b/pages/anime/anime.go new file mode 100644 index 00000000..c8ff2661 --- /dev/null +++ b/pages/anime/anime.go @@ -0,0 +1,19 @@ +package anime + +import ( + "github.com/aerogo/aero" + "github.com/animenotifier/arn" + "github.com/animenotifier/notify.moe/components" +) + +// Get ... +func Get(ctx *aero.Context) string { + id, _ := ctx.GetInt("id") + anime, err := arn.GetAnime(id) + + if err != nil { + return ctx.Text("Anime not found") + } + + return ctx.HTML(components.Anime(anime)) +} diff --git a/pages/beta/beta.pixy b/pages/beta/beta.pixy new file mode 100644 index 00000000..b7db83d2 --- /dev/null +++ b/pages/beta/beta.pixy @@ -0,0 +1,14 @@ +component Beta + section + header + h2 The future + + p Shht! The next version of notify.moe is currently being built here. + hr + ul + li + a.ajax(href="/anime/21499") Sousei no Onmyouji + li + a.ajax(href="/anime/1000001") RWBY + li + a(href="/api/anime/1000001") RWBY (JSON API) \ No newline at end of file diff --git a/pages/dashboard/dashboard.go b/pages/dashboard/dashboard.go new file mode 100644 index 00000000..ed739211 --- /dev/null +++ b/pages/dashboard/dashboard.go @@ -0,0 +1,11 @@ +package dashboard + +import ( + "github.com/aerogo/aero" + "github.com/animenotifier/notify.moe/components" +) + +// Get ... +func Get(ctx *aero.Context) string { + return ctx.HTML(components.Dashboard()) +} diff --git a/pages/dashboard/dashboard.pixy b/pages/dashboard/dashboard.pixy index af0f7d98..39ae4e24 100644 --- a/pages/dashboard/dashboard.pixy +++ b/pages/dashboard/dashboard.pixy @@ -1,17 +1,4 @@ component Dashboard section header - h2 ARN 4.0 - p Shht! The next version of notify.moe is currently being built here. - hr - ul - li - a.ajax(href="/anime/21499") Sousei no Onmyouji - li - a.ajax(href="/anime/1000001") RWBY - li - a(href="/api/anime/1000001") RWBY (JSON API) - li - a.ajax(href="/genres") Genre Overview - li - a(href="/all/anime") All anime titles on notify.moe (text file) \ No newline at end of file + h2 Dash \ No newline at end of file diff --git a/pages/forum/forum.go b/pages/forum/forum.go new file mode 100644 index 00000000..5a3577ad --- /dev/null +++ b/pages/forum/forum.go @@ -0,0 +1,29 @@ +package forum + +import ( + "sort" + + "github.com/aerogo/aero" + "github.com/animenotifier/arn" + "github.com/animenotifier/notify.moe/components" +) + +const threadsPerPage = 20 + +// Get ... +func Get(ctx *aero.Context) string { + tag := ctx.Get("tag") + threads, _ := arn.GetThreadsByTag(tag) + + sort.Sort(threads) + + if len(threads) > threadsPerPage { + threads = threads[:threadsPerPage] + } + + for _, thread := range threads { + thread.Init() + } + + return ctx.HTML(components.Forum(threads)) +} diff --git a/pages/genre/genre.go b/pages/genre/genre.go new file mode 100644 index 00000000..3eac53a7 --- /dev/null +++ b/pages/genre/genre.go @@ -0,0 +1,21 @@ +package genre + +import ( + "github.com/aerogo/aero" + "github.com/animenotifier/arn" + "github.com/animenotifier/notify.moe/components" +) + +// Get ... +func Get(ctx *aero.Context) string { + genreName := ctx.Get("name") + genreInfo := new(arn.Genre) + + err := arn.GetObject("Genres", genreName, genreInfo) + + if err != nil { + return err.Error() + } + + return ctx.HTML(components.Genre(genreInfo.Genre, genreInfo.AnimeList)) +} diff --git a/pages/genre/genre.pixy b/pages/genre/genre.pixy new file mode 100644 index 00000000..5555a996 --- /dev/null +++ b/pages/genre/genre.pixy @@ -0,0 +1,6 @@ +component Genre(genre string, animeList []*arn.Anime) + h2.genre-header= arn.Capitalize(genre) + .grid + each anime in animeList + a.grid-cell.ajax(href="/anime/" + toString(anime.ID)) + img.anime-image.grid-cell-content.grid-cell-image(src=anime.Image, alt=anime.Title.Romaji, title=anime.Title.Romaji + " (" + toString(anime.Watching) + ")") \ No newline at end of file diff --git a/pages/genre/genre.styl b/pages/genre/genre.styl new file mode 100644 index 00000000..421e1ea3 --- /dev/null +++ b/pages/genre/genre.styl @@ -0,0 +1,28 @@ +.grid + display flex + flex-flow row wrap + float none !important + justify-content center + +.grid-cell + margin 0.5em + flex-grow 0 + flex-shrink 0 + +.grid-cell-content + width 16vw + height 9vw + min-width 90px + min-height 127px + max-width 200px + max-height 282px + +.grid-cell-image + object-fit cover + +.grid-cell-text + display flex + flex-flow column + align-items center + justify-content center + padding 0.75em \ No newline at end of file diff --git a/pages/genres/genres.go b/pages/genres/genres.go new file mode 100644 index 00000000..84a93d45 --- /dev/null +++ b/pages/genres/genres.go @@ -0,0 +1,11 @@ +package genres + +import ( + "github.com/aerogo/aero" + "github.com/animenotifier/notify.moe/components" +) + +// Get ... +func Get(ctx *aero.Context) string { + return ctx.HTML(components.Genres()) +} diff --git a/pages/genres/genres.pixy b/pages/genres/genres.pixy index 4fdfa6a9..c82c642a 100644 --- a/pages/genres/genres.pixy +++ b/pages/genres/genres.pixy @@ -1,15 +1,9 @@ -component GenreOverview +component Genres h2.genre-header Genres - div + .grid each genre in arn.Genres - a.light-button.ajax(href="/genres/" + arn.FixGenre(genre)) - Icon(arn.GetGenreIcon(genre)) - span= genre - -component AnimeInGenre(genre string, animeList []*arn.Anime) - h2.genre-header= arn.Capitalize(genre) - .genre-anime-list - each anime in animeList - a.genre-anime-link.ajax(href="/anime/" + toString(anime.ID)) - img.anime-image.genre-anime-image(src=anime.Image, alt=anime.Title.Romaji, title=anime.Title.Romaji + " (" + toString(anime.Watching) + ")") \ No newline at end of file + a.grid-cell.light-button.ajax(href="/genres/" + arn.FixGenre(genre)) + .genre.grid-cell-content.grid-cell-text + Icon(arn.GetGenreIcon(genre)) + span= genre \ No newline at end of file diff --git a/pages/genres/genres.styl b/pages/genres/genres.styl index 2fb5b2d9..aea02203 100644 --- a/pages/genres/genres.styl +++ b/pages/genres/genres.styl @@ -1,22 +1,9 @@ .genre-header text-align center -.genre-anime-list - display flex - flex-flow row wrap - float none !important - justify-content center - -.genre-anime-image - width 16vw - height 9vw - min-width 90px - min-height 127px - max-width 200px - max-height 282px - object-fit cover - -.genre-anime-link - margin 0.5em - flex-grow 0 - flex-shrink 0 \ No newline at end of file +.genre + font-size 1rem + .fa + font-size 2rem + margin-right 0 + margin-bottom 1rem \ No newline at end of file diff --git a/pages/threads/threads.go b/pages/threads/threads.go new file mode 100644 index 00000000..39c77832 --- /dev/null +++ b/pages/threads/threads.go @@ -0,0 +1,33 @@ +package threads + +import ( + "sort" + + "github.com/aerogo/aero" + "github.com/animenotifier/arn" + "github.com/animenotifier/notify.moe/components" +) + +// Get ... +func Get(ctx *aero.Context) string { + id := ctx.Get("id") + thread, err := arn.GetThread(id) + + if err != nil { + return ctx.Text("Thread not found") + } + + thread.Author, _ = arn.GetUser(thread.AuthorID) + + replies, filterErr := arn.FilterPosts(func(post *arn.Post) bool { + return post.ThreadID == thread.ID + }) + + sort.Sort(replies) + + if filterErr != nil { + return ctx.Text("Error fetching thread replies") + } + + return ctx.HTML(components.Thread(thread, replies)) +} diff --git a/pages/threads/threads.pixy b/pages/threads/threads.pixy index f03ef26b..7b8c3a6c 100644 --- a/pages/threads/threads.pixy +++ b/pages/threads/threads.pixy @@ -1,16 +1,15 @@ -component Thread(thread *arn.Thread) +component Thread(thread *arn.Thread, posts []*arn.Post) .thread h2.thread-title= thread.Title .posts - Post(thread.ToPostable(), nil, "Threads", "Thread", thread.AuthorID) - //- +renderMessage(thread, user, "Threads", thread.author.ID) + Post(thread.ToPostable(), nil, "Threads", "Thread", thread.Author.ID) - //- each post in posts - //- +renderMessage(post, user, "Posts", thread.author.ID) + each post in posts + Post(post.ToPostable(), nil, "Posts", "Post", thread.Author.ID) component Post(post arn.Postable, viewUser *arn.User, postType string, postTypeSingular string, highlightAuthorID string) - .post(class=[]string{"", "special-post"}[post.Author().ID == highlightAuthorID]) + .post(data-highlight=post.Author().ID == highlightAuthorID) .post-author Avatar(post.Author()) diff --git a/router.go b/router.go deleted file mode 100644 index 93d95e6f..00000000 --- a/router.go +++ /dev/null @@ -1,78 +0,0 @@ -package main - -import ( - "sort" - - "github.com/aerogo/aero" - "github.com/animenotifier/arn" - "github.com/animenotifier/notify.moe/components" -) - -func init() { - app.Ajax("/", func(ctx *aero.Context) string { - return ctx.HTML(components.Dashboard()) - }) - - app.Ajax("/anime/:id", func(ctx *aero.Context) string { - id, _ := ctx.GetInt("id") - anime, err := arn.GetAnime(id) - - if err != nil { - return ctx.Text("Anime not found") - } - - return ctx.HTML(components.Anime(anime)) - }) - - app.Ajax("/genres", func(ctx *aero.Context) string { - return ctx.HTML(components.GenreOverview()) - }) - - app.Ajax("/genres/:name", func(ctx *aero.Context) string { - genreName := ctx.Get("name") - genreInfo := new(arn.Genre) - - err := arn.GetObject("Genres", genreName, genreInfo) - - if err != nil { - return err.Error() - } - - return ctx.HTML(components.AnimeInGenre(genreInfo.Genre, genreInfo.AnimeList)) - }) - - const threadsPerPage = 12 - - forumHandler := func(ctx *aero.Context) string { - tag := ctx.Get("tag") - threads, _ := arn.GetThreadsByTag(tag) - - sort.Sort(threads) - - if len(threads) > threadsPerPage { - threads = threads[:threadsPerPage] - } - - for _, thread := range threads { - thread.Author, _ = arn.GetUser(thread.AuthorID) - } - - return ctx.HTML(components.Forum(threads)) - } - - app.Ajax("/forum", forumHandler) - app.Ajax("/forum/:tag", forumHandler) - - app.Ajax("/threads/:id", func(ctx *aero.Context) string { - id := ctx.Get("id") - thread, err := arn.GetThread(id) - - if err != nil { - return ctx.Text("Thread not found") - } - - thread.Author, _ = arn.GetUser(thread.AuthorID) - - return ctx.HTML(components.Thread(thread)) - }) -} diff --git a/styles/forum.styl b/styles/forum.styl index 577984cd..9b665e70 100644 --- a/styles/forum.styl +++ b/styles/forum.styl @@ -102,7 +102,7 @@ line-height 2em font-weight normal -.special-post +.post[data-highlight="true"] .post-content border 2px solid alpha(mainColor, 70%)