Added page about instance

This commit is contained in:
localhost_frssoft 2022-10-12 13:34:41 +03:00
parent fe304f60e9
commit 7dd90ac015
7 changed files with 81 additions and 0 deletions

View File

@ -17,6 +17,8 @@ type Instance struct {
Stats *InstanceStats `json:"stats,omitempty"`
Languages []string `json:"languages"`
ContactAccount *Account `json:"account"`
MaxTootChars *int64 `json:"max_toot_chars"`
Pleroma *PleromaInstance `json:"pleroma"`
}
// InstanceStats hold information for mastodon instance stats.
@ -26,6 +28,16 @@ type InstanceStats struct {
DomainCount int64 `json:"domain_count"`
}
// For about instance if this Pleroma
type PleromaInstance struct {
MetaData MetaData `json:"metadata"`
}
type MetaData struct {
Features *[]string `json:"features"`
}
// GetInstance return Instance.
func (c *Client) GetInstance(ctx context.Context) (*Instance, error) {
var instance Instance

View File

@ -119,6 +119,11 @@ type AboutData struct {
*CommonData
}
type AboutInstanceData struct {
*CommonData
Instance *mastodon.Instance
}
type EmojiData struct {
*CommonData
Emojis []*mastodon.Emoji

View File

@ -27,6 +27,7 @@ const (
UserPage = "user.tmpl"
UserSearchPage = "usersearch.tmpl"
AboutPage = "about.tmpl"
AboutInstance = "aboutinstance.tmpl"
EmojiPage = "emoji.tmpl"
LikedByPage = "likedby.tmpl"
RetweetedByPage = "retweetedby.tmpl"

View File

@ -737,6 +737,19 @@ func (s *service) AboutPage(c *client) (err error) {
return s.renderer.Render(c.rctx, c.w, renderer.AboutPage, data)
}
func (s *service) AboutInstance(c *client) (err error) {
cdata := s.cdata(c, "about", 0, 0, "")
instance, err := c.GetInstance(c.ctx)
if err != nil {
return
}
data := &renderer.AboutInstanceData{
CommonData: cdata,
Instance: instance,
}
return s.renderer.Render(c.rctx, c.w, renderer.AboutInstance, data)
}
func (s *service) EmojiPage(c *client) (err error) {
emojis, err := c.GetInstanceEmojis(c.ctx)
if err != nil {

View File

@ -221,6 +221,10 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler {
return s.AboutPage(c)
}, SESSION, HTML)
aboutInstance := handle(func(c *client) error {
return s.AboutInstance(c)
}, SESSION, HTML)
emojisPage := handle(func(c *client) error {
return s.EmojiPage(c)
}, SESSION, HTML)
@ -721,6 +725,7 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler {
r.HandleFunc("/user/{id}/{type}", userPage).Methods(http.MethodGet)
r.HandleFunc("/usersearch/{id}", userSearchPage).Methods(http.MethodGet)
r.HandleFunc("/about", aboutPage).Methods(http.MethodGet)
r.HandleFunc("/aboutinstance", aboutInstance).Methods(http.MethodGet)
r.HandleFunc("/emojis", emojisPage).Methods(http.MethodGet)
r.HandleFunc("/search", searchPage).Methods(http.MethodGet)
r.HandleFunc("/settings", settingsPage).Methods(http.MethodGet)

View File

@ -0,0 +1,44 @@
{{with .Data}}
{{template "header.tmpl" (WithContext .CommonData $.Ctx)}}
<div class="page-title"> About {{.Instance.Title}} </div>
<div>
<p>
{{.Instance.Description}}
</p>
<p>
<details>
<summary>Logo instance</summary>
<img src="{{.Instance.Thumbnail}}" height="512"></img>
</details>
</p>
</div>
<div class="page-title"> Contact E-mail: {{.Instance.EMail}} </div>
{{if .Instance.Stats}}
<div class="page-title"> Statistics: </div>
<div>
<p>
Domains federated: {{.Instance.Stats.DomainCount}}<br>
Registered users: {{.Instance.Stats.UserCount}}<br>
Statuses writen: {{.Instance.Stats.StatusCount}}<br>
</p>
</div>
{{end}}
<div class="page-title"> Features: </div>
<div>
{{if .Instance.Pleroma}}
{{range .Instance.Pleroma.MetaData.Features}}
{{.}}<br>
{{end}}
{{end}}
</div>
<div class="page-title"> Version: {{.Instance.Version}} </div>
{{template "footer.tmpl"}}
{{end}}

View File

@ -30,6 +30,7 @@
<input type="submit" value="signout" class="btn-link nav-link" title="Signout">
</form>
<a class="nav-link" href="/about" accesskey="9" title="About (9)">about</a>
<a class="nav-link" href="/aboutinstance" title="Info about instance">instance</a>
</div>
</div>
</div>