diff --git a/.gitignore b/.gitignore index 80552e2d..5624a33a 100644 --- a/.gitignore +++ b/.gitignore @@ -29,6 +29,7 @@ _testmain.go # external packages folder vendor/ node_modules/ +tmp/ # debugger debug diff --git a/api.go b/api.go index dd755d0a..82c4df35 100644 --- a/api.go +++ b/api.go @@ -3,7 +3,6 @@ package main import ( "sort" "strings" - "time" "github.com/aerogo/aero" "github.com/animenotifier/arn" @@ -11,7 +10,6 @@ import ( func init() { app.Get("/all/anime", func(ctx *aero.Context) string { - start := time.Now() var titles []string results := make(chan *arn.Anime) @@ -22,7 +20,7 @@ func init() { } sort.Strings(titles) - return ctx.Text(s(len(titles)) + " anime fetched in " + s(time.Since(start)) + "\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 { @@ -46,4 +44,15 @@ func init() { return ctx.JSON(user) }) + + app.Get("/api/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") + } + + return ctx.JSON(thread) + }) } diff --git a/helper.go b/helper.go index 642ea83d..4a0b4fc6 100644 --- a/helper.go +++ b/helper.go @@ -3,7 +3,7 @@ package main import "fmt" // Converts anything into a string -func s(v interface{}) string { +func toString(v interface{}) string { return fmt.Sprint(v) } diff --git a/templates/layout.pixy b/layout/layout.pixy similarity index 71% rename from templates/layout.pixy rename to layout/layout.pixy index 6627251b..228db162 100644 --- a/templates/layout.pixy +++ b/layout/layout.pixy @@ -23,10 +23,14 @@ component Content(content string) component Navigation nav#navigation - a.navigation-link.navigation-link-left.ajax(href="/") - .navigation-button - i.fa.fa-dashboard - span.navigation-text Dash + NavigationButton("Dash", "/", "dashboard") + NavigationButton("Forum", "/forum", "comment") + +component NavigationButton(name string, target string, icon string) + a.navigation-link.navigation-link-left.ajax(href=target) + .navigation-button + i(class="fa fa-" + icon) + span.navigation-text= name component LoadingAnimation #loading-animation.sk-cube-grid.fade diff --git a/mixins/Avatar.pixy b/mixins/Avatar.pixy new file mode 100644 index 00000000..8be88841 --- /dev/null +++ b/mixins/Avatar.pixy @@ -0,0 +1,12 @@ +component Avatar(user *arn.User) + a.user.ajax(href="/+" + user.Nick, title=user.Nick) + if user.Avatar != "" + if strings.Contains(user.Avatar, "gravatar.com") + img.user-image(src=user.Avatar + "?s=100&r=x&d=mm", alt=user.Nick) + else + img.user-image(src=user.Avatar, alt=user.Nick) + else + svg.user-image(width="50", height="50") + circle.head(cx="25", cy="19", r="10", fill="rgb(32, 32, 32)") + circle.body(cx="25", cy="50", r="20") + //- text(x="25", y="44", text-anchor="middle") TODO \ No newline at end of file diff --git a/templates/icon.pixy b/mixins/Icon.pixy similarity index 100% rename from templates/icon.pixy rename to mixins/Icon.pixy diff --git a/templates/anime/anime.pixy b/pages/anime/anime.pixy similarity index 96% rename from templates/anime/anime.pixy rename to pages/anime/anime.pixy index 1e9fdc16..1d9c86d8 100644 --- a/templates/anime/anime.pixy +++ b/pages/anime/anime.pixy @@ -49,7 +49,7 @@ component Anime(anime *arn.Anime) h3.anime-header Studios .light-button-group each studio in anime.Studios - a.light-button(href="https://anilist.co/studio/" + s(studio.ID), target="_blank") + a.light-button(href="https://anilist.co/studio/" + toString(studio.ID), target="_blank") i.fa.fa-building.fa-fw span= studio.Name @@ -106,7 +106,7 @@ component Anime(anime *arn.Anime) a.light-button(href=link.URL, target="_blank")= link.Title if anime.CreatedBy == "" - a.light-button(href="https://anilist.co/anime/" + s(anime.ID), target="_blank") AniList + a.light-button(href="https://anilist.co/anime/" + toString(anime.ID), target="_blank") AniList //- if providers.HummingBird //- a.light-button(href="https://hummingbird.me/anime/" + providers.HummingBird.providerId, target="_blank") HummingBird diff --git a/templates/anime/anime.styl b/pages/anime/anime.styl similarity index 100% rename from templates/anime/anime.styl rename to pages/anime/anime.styl diff --git a/templates/anime/anime.ts b/pages/anime/anime.ts similarity index 100% rename from templates/anime/anime.ts rename to pages/anime/anime.ts diff --git a/templates/dashboard.pixy b/pages/dashboard/dashboard.pixy similarity index 100% rename from templates/dashboard.pixy rename to pages/dashboard/dashboard.pixy diff --git a/pages/forum/forum.pixy b/pages/forum/forum.pixy new file mode 100644 index 00000000..bec5ffb4 --- /dev/null +++ b/pages/forum/forum.pixy @@ -0,0 +1,35 @@ +component Forum(threads []*arn.Thread) + h2 Forum + ForumHeader + each thread in threads + ThreadLink(thread) + +component ForumHeader + .forum-tags + a.ajax(href="/forum") All + span | + a.ajax(href="/forum/general") General + span | + a.ajax(href="/forum/news") News + span | + a.ajax(href="/forum/anime") Anime + span | + a.ajax(href="/forum/update") Updates + span | + a.ajax(href="/forum/suggestion") Suggestions + span | + a.ajax(href="/forum/bug") Bugs + +component ThreadLink(thread *arn.Thread) + .thread(data-stick=toString(thread.Sticky)) + .post-author.thread-author + Avatar(thread.Author) + .thread-content-container + .post-content.thread-content + if thread.Sticky + i.fa.fa-thumb-tack.fa-fw.thread-icon + a.thread-title.ajax(href="/threads/" + thread.ID)= thread.Title + //- .thread-icons + //- each icon in thread.Icons + //- i(class='fa fa-' + icon + ' fa-fw thread-icon') + //- .thread-reply-count= 25 \ No newline at end of file diff --git a/pages/forum/forum.styl b/pages/forum/forum.styl new file mode 100644 index 00000000..65d59f0b --- /dev/null +++ b/pages/forum/forum.styl @@ -0,0 +1,37 @@ +.forum-tags + text-align left + margin-bottom 1.5rem + +.thread + display flex + flex-flow row + width 100% + +.thread-icons +.thread-reply-count + flex 1 + text-align right + opacity 0.5 + +.thread-reply-count + &:after + content " replies" + +.thread-content-container + display flex + align-items center + width 100% + +.thread-content + display flex + align-items center + justify-content flex-start + text-align left + min-height 80% + a + color rgb(32, 32, 32) !important + &:hover + color linkHoverColor !important + +.thread-icon + font-size 0.9em \ No newline at end of file diff --git a/templates/genres/genres.pixy b/pages/genres/genres.pixy similarity index 73% rename from templates/genres/genres.pixy rename to pages/genres/genres.pixy index d4615d2e..4fdfa6a9 100644 --- a/templates/genres/genres.pixy +++ b/pages/genres/genres.pixy @@ -11,5 +11,5 @@ 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/" + s(anime.ID)) - img.anime-image.genre-anime-image(src=anime.Image, alt=anime.Title.Romaji, title=anime.Title.Romaji + " (" + s(anime.Watching) + ")") \ No newline at end of file + 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 diff --git a/templates/genres/genres.styl b/pages/genres/genres.styl similarity index 100% rename from templates/genres/genres.styl rename to pages/genres/genres.styl diff --git a/router.go b/router.go index 79e8a92b..25377d5d 100644 --- a/router.go +++ b/router.go @@ -38,4 +38,24 @@ func init() { 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) + + 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) } diff --git a/scripts/init.ts b/scripts/main.ts similarity index 100% rename from scripts/init.ts rename to scripts/main.ts diff --git a/styles/layout.styl b/styles/layout.styl index 531171c3..1d1134e0 100644 --- a/styles/layout.styl +++ b/styles/layout.styl @@ -73,7 +73,6 @@ & > div float left width 100% - text-align center .header-logged-in background-image none !important