Przeglądaj źródła

Support Web Monetization via backend attribute

This supports a new `monetization_pointer` collection attribute.
When present, we include the `monetization` meta tag on all
collection pages.
pull/369/head
Matt Baer 3 lat temu
rodzic
commit
13eb51913e
9 zmienionych plików z 38 dodań i 0 usunięć
  1. +3
    -0
      collections.go
  2. +22
    -0
      database.go
  3. +2
    -0
      posts.go
  4. +1
    -0
      templates/chorus-collection-post.tmpl
  5. +1
    -0
      templates/chorus-collection.tmpl
  6. +1
    -0
      templates/collection-post.tmpl
  7. +1
    -0
      templates/collection-tags.tmpl
  8. +1
    -0
      templates/collection.tmpl
  9. +6
    -0
      templates/include/post-render.tmpl

+ 3
- 0
collections.go Wyświetl plik

@@ -552,6 +552,7 @@ type CollectionPage struct {
IsOwner bool
CanPin bool
Username string
Monetization string
Collections *[]Collection
PinnedPosts *[]PublicPost
IsAdmin bool
@@ -829,6 +830,7 @@ func handleViewCollection(app *App, w http.ResponseWriter, r *http.Request) erro
// Add more data
// TODO: fix this mess of collections inside collections
displayPage.PinnedPosts, _ = app.db.GetPinnedPosts(coll.CollectionObj, isOwner)
displayPage.Monetization = app.db.GetCollectionAttribute(coll.ID, "monetization_pointer")

collTmpl := "collection"
if app.cfg.App.Chorus {
@@ -947,6 +949,7 @@ func handleViewCollectionTag(app *App, w http.ResponseWriter, r *http.Request) e
// Add more data
// TODO: fix this mess of collections inside collections
displayPage.PinnedPosts, _ = app.db.GetPinnedPosts(coll.CollectionObj, isOwner)
displayPage.Monetization = app.db.GetCollectionAttribute(coll.ID, "monetization_pointer")

err = templates["collection-tags"].ExecuteTemplate(w, "collection-tags", displayPage)
if err != nil {


+ 22
- 0
database.go Wyświetl plik

@@ -2162,6 +2162,28 @@ func (db *datastore) CollectionHasAttribute(id int64, attr string) bool {
return true
}

func (db *datastore) GetCollectionAttribute(id int64, attr string) string {
var v string
err := db.QueryRow("SELECT value FROM collectionattributes WHERE collection_id = ? AND attribute = ?", id, attr).Scan(&v)
switch {
case err == sql.ErrNoRows:
return ""
case err != nil:
log.Error("Couldn't SELECT value in getCollectionAttribute for attribute '%s': %v", attr, err)
return ""
}
return v
}

func (db *datastore) SetCollectionAttribute(id int64, attr, v string) error {
_, err := db.Exec("INSERT INTO collectionattributes (collection_id, attribute, value) VALUES (?, ?, ?)", id, attr, v)
if err != nil {
log.Error("Unable to INSERT into collectionattributes: %v", err)
return err
}
return nil
}

// DeleteAccount will delete the entire account for userID
func (db *datastore) DeleteAccount(userID int64) error {
// Get all collections


+ 2
- 0
posts.go Wyświetl plik

@@ -1476,6 +1476,7 @@ Are you sure it was ever here?`,
IsOwner bool
IsPinned bool
IsCustomDomain bool
Monetization string
PinnedPosts *[]PublicPost
IsFound bool
IsAdmin bool
@@ -1493,6 +1494,7 @@ Are you sure it was ever here?`,
tp.CanInvite = canUserInvite(app.cfg, tp.IsAdmin)
tp.PinnedPosts, _ = app.db.GetPinnedPosts(coll, p.IsOwner)
tp.IsPinned = len(*tp.PinnedPosts) > 0 && PostsContains(tp.PinnedPosts, p)
tp.Monetization = app.db.GetCollectionAttribute(coll.ID, "monetization_pointer")

if !postFound {
w.WriteHeader(http.StatusNotFound)


+ 1
- 0
templates/chorus-collection-post.tmpl Wyświetl plik

@@ -29,6 +29,7 @@
<meta property="og:updated_time" content="{{.Created8601}}" />
{{range .Images}}<meta property="og:image" content="{{.}}" />{{else}}<meta property="og:image" content="{{.Collection.AvatarURL}}">{{end}}
<meta property="article:published_time" content="{{.Created8601}}">
{{template "collection-meta" .}}
{{if .Collection.StyleSheet}}<style type="text/css">{{.Collection.StyleSheetDisplay}}</style>{{end}}
<style type="text/css">
body footer {


+ 1
- 0
templates/chorus-collection.tmpl Wyświetl plik

@@ -27,6 +27,7 @@
<meta property="og:url" content="{{.CanonicalURL}}" />
<meta property="og:description" content="{{.Description}}" />
<meta property="og:image" content="{{.AvatarURL}}">
{{template "collection-meta" .}}
{{if .StyleSheet}}<style type="text/css">{{.StyleSheetDisplay}}</style>{{end}}
<style type="text/css">
body#collection header {


+ 1
- 0
templates/collection-post.tmpl Wyświetl plik

@@ -31,6 +31,7 @@
{{range .Images}}<meta property="og:image" content="{{.}}" />{{else}}<meta property="og:image" content="{{.Collection.AvatarURL}}">{{end}}
<meta property="article:published_time" content="{{.Created8601}}">
{{ end }}
{{template "collection-meta" .}}
{{if .Collection.StyleSheet}}<style type="text/css">{{.Collection.StyleSheetDisplay}}</style>{{end}}

{{if .Collection.RenderMathJax}}


+ 1
- 0
templates/collection-tags.tmpl Wyświetl plik

@@ -29,6 +29,7 @@
<meta property="og:type" content="article" />
<meta property="og:url" content="{{.CanonicalURL}}tag:{{.Tag}}" />
<meta property="og:image" content="{{.Collection.AvatarURL}}">
{{template "collection-meta" .}}
{{if .Collection.StyleSheet}}<style type="text/css">{{.Collection.StyleSheetDisplay}}</style>{{end}}

{{if .Collection.RenderMathJax}}


+ 1
- 0
templates/collection.tmpl Wyświetl plik

@@ -27,6 +27,7 @@
<meta property="og:url" content="{{.CanonicalURL}}" />
<meta property="og:description" content="{{.Description}}" />
<meta property="og:image" content="{{.AvatarURL}}">
{{template "collection-meta" .}}
{{if .StyleSheet}}<style type="text/css">{{.StyleSheetDisplay}}</style>{{end}}

{{if .RenderMathJax}}


+ 6
- 0
templates/include/post-render.tmpl Wyświetl plik

@@ -1,4 +1,10 @@
<!-- Miscelaneous render related template parts we use multiple times -->
{{define "collection-meta"}}
{{if .Monetization -}}
<meta name="monetization" content="{{.Monetization}}" />
{{- end}}
{{end}}

{{define "highlighting"}}
<script>
// TODO: this feels more like a mutation observer


Ładowanie…
Anuluj
Zapisz