Skip to content
This repository has been archived by the owner on Jun 3, 2019. It is now read-only.

Added a formatted version of an anime summary #14

Open
wants to merge 4 commits into
base: go
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Anime.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package arn
import (
"errors"
"fmt"
"github.com/aerogo/markdown"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -98,6 +99,8 @@ type Anime struct {

// SynopsisSource string `json:"synopsisSource" editable:"true"`
// Hashtag string `json:"hashtag"`

html string
}

// NewAnime creates a new anime.
Expand Down Expand Up @@ -788,6 +791,16 @@ func FilterAnime(filter func(*Anime) bool) []*Anime {
return filtered
}

// HTML returns the HTML representation of the anime summary.
func (anime *Anime) HTML() string {
if anime.html != "" {
return anime.html
}

anime.html = markdown.Render(anime.Summary)
return anime.html
}

// // SetID performs a database-wide ID change.
// // Calling this will automatically save the anime.
// func (anime *Anime) SetID(newID string) {
Expand Down
2 changes: 2 additions & 0 deletions AnimeAPI.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package arn
import (
"errors"
"fmt"
"github.com/aerogo/markdown"
"os"
"path"
"reflect"
Expand Down Expand Up @@ -98,6 +99,7 @@ func (anime *Anime) Authorize(ctx *aero.Context, action string) error {
func (anime *Anime) AfterEdit(ctx *aero.Context) error {
anime.Edited = DateTimeUTC()
anime.EditedBy = GetUserFromContext(ctx).ID
anime.html = markdown.Render(anime.Summary)
return nil
}

Expand Down