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.
This commit is contained in:
parent
dfa14c9c92
commit
13eb51913e
|
@ -552,6 +552,7 @@ type CollectionPage struct {
|
||||||
IsOwner bool
|
IsOwner bool
|
||||||
CanPin bool
|
CanPin bool
|
||||||
Username string
|
Username string
|
||||||
|
Monetization string
|
||||||
Collections *[]Collection
|
Collections *[]Collection
|
||||||
PinnedPosts *[]PublicPost
|
PinnedPosts *[]PublicPost
|
||||||
IsAdmin bool
|
IsAdmin bool
|
||||||
|
@ -829,6 +830,7 @@ func handleViewCollection(app *App, w http.ResponseWriter, r *http.Request) erro
|
||||||
// Add more data
|
// Add more data
|
||||||
// TODO: fix this mess of collections inside collections
|
// TODO: fix this mess of collections inside collections
|
||||||
displayPage.PinnedPosts, _ = app.db.GetPinnedPosts(coll.CollectionObj, isOwner)
|
displayPage.PinnedPosts, _ = app.db.GetPinnedPosts(coll.CollectionObj, isOwner)
|
||||||
|
displayPage.Monetization = app.db.GetCollectionAttribute(coll.ID, "monetization_pointer")
|
||||||
|
|
||||||
collTmpl := "collection"
|
collTmpl := "collection"
|
||||||
if app.cfg.App.Chorus {
|
if app.cfg.App.Chorus {
|
||||||
|
@ -947,6 +949,7 @@ func handleViewCollectionTag(app *App, w http.ResponseWriter, r *http.Request) e
|
||||||
// Add more data
|
// Add more data
|
||||||
// TODO: fix this mess of collections inside collections
|
// TODO: fix this mess of collections inside collections
|
||||||
displayPage.PinnedPosts, _ = app.db.GetPinnedPosts(coll.CollectionObj, isOwner)
|
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)
|
err = templates["collection-tags"].ExecuteTemplate(w, "collection-tags", displayPage)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
22
database.go
22
database.go
|
@ -2162,6 +2162,28 @@ func (db *datastore) CollectionHasAttribute(id int64, attr string) bool {
|
||||||
return true
|
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
|
// DeleteAccount will delete the entire account for userID
|
||||||
func (db *datastore) DeleteAccount(userID int64) error {
|
func (db *datastore) DeleteAccount(userID int64) error {
|
||||||
// Get all collections
|
// Get all collections
|
||||||
|
|
2
posts.go
2
posts.go
|
@ -1476,6 +1476,7 @@ Are you sure it was ever here?`,
|
||||||
IsOwner bool
|
IsOwner bool
|
||||||
IsPinned bool
|
IsPinned bool
|
||||||
IsCustomDomain bool
|
IsCustomDomain bool
|
||||||
|
Monetization string
|
||||||
PinnedPosts *[]PublicPost
|
PinnedPosts *[]PublicPost
|
||||||
IsFound bool
|
IsFound bool
|
||||||
IsAdmin bool
|
IsAdmin bool
|
||||||
|
@ -1493,6 +1494,7 @@ Are you sure it was ever here?`,
|
||||||
tp.CanInvite = canUserInvite(app.cfg, tp.IsAdmin)
|
tp.CanInvite = canUserInvite(app.cfg, tp.IsAdmin)
|
||||||
tp.PinnedPosts, _ = app.db.GetPinnedPosts(coll, p.IsOwner)
|
tp.PinnedPosts, _ = app.db.GetPinnedPosts(coll, p.IsOwner)
|
||||||
tp.IsPinned = len(*tp.PinnedPosts) > 0 && PostsContains(tp.PinnedPosts, p)
|
tp.IsPinned = len(*tp.PinnedPosts) > 0 && PostsContains(tp.PinnedPosts, p)
|
||||||
|
tp.Monetization = app.db.GetCollectionAttribute(coll.ID, "monetization_pointer")
|
||||||
|
|
||||||
if !postFound {
|
if !postFound {
|
||||||
w.WriteHeader(http.StatusNotFound)
|
w.WriteHeader(http.StatusNotFound)
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
<meta property="og:updated_time" content="{{.Created8601}}" />
|
<meta property="og:updated_time" content="{{.Created8601}}" />
|
||||||
{{range .Images}}<meta property="og:image" content="{{.}}" />{{else}}<meta property="og:image" content="{{.Collection.AvatarURL}}">{{end}}
|
{{range .Images}}<meta property="og:image" content="{{.}}" />{{else}}<meta property="og:image" content="{{.Collection.AvatarURL}}">{{end}}
|
||||||
<meta property="article:published_time" content="{{.Created8601}}">
|
<meta property="article:published_time" content="{{.Created8601}}">
|
||||||
|
{{template "collection-meta" .}}
|
||||||
{{if .Collection.StyleSheet}}<style type="text/css">{{.Collection.StyleSheetDisplay}}</style>{{end}}
|
{{if .Collection.StyleSheet}}<style type="text/css">{{.Collection.StyleSheetDisplay}}</style>{{end}}
|
||||||
<style type="text/css">
|
<style type="text/css">
|
||||||
body footer {
|
body footer {
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
<meta property="og:url" content="{{.CanonicalURL}}" />
|
<meta property="og:url" content="{{.CanonicalURL}}" />
|
||||||
<meta property="og:description" content="{{.Description}}" />
|
<meta property="og:description" content="{{.Description}}" />
|
||||||
<meta property="og:image" content="{{.AvatarURL}}">
|
<meta property="og:image" content="{{.AvatarURL}}">
|
||||||
|
{{template "collection-meta" .}}
|
||||||
{{if .StyleSheet}}<style type="text/css">{{.StyleSheetDisplay}}</style>{{end}}
|
{{if .StyleSheet}}<style type="text/css">{{.StyleSheetDisplay}}</style>{{end}}
|
||||||
<style type="text/css">
|
<style type="text/css">
|
||||||
body#collection header {
|
body#collection header {
|
||||||
|
|
|
@ -31,6 +31,7 @@
|
||||||
{{range .Images}}<meta property="og:image" content="{{.}}" />{{else}}<meta property="og:image" content="{{.Collection.AvatarURL}}">{{end}}
|
{{range .Images}}<meta property="og:image" content="{{.}}" />{{else}}<meta property="og:image" content="{{.Collection.AvatarURL}}">{{end}}
|
||||||
<meta property="article:published_time" content="{{.Created8601}}">
|
<meta property="article:published_time" content="{{.Created8601}}">
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
{{template "collection-meta" .}}
|
||||||
{{if .Collection.StyleSheet}}<style type="text/css">{{.Collection.StyleSheetDisplay}}</style>{{end}}
|
{{if .Collection.StyleSheet}}<style type="text/css">{{.Collection.StyleSheetDisplay}}</style>{{end}}
|
||||||
|
|
||||||
{{if .Collection.RenderMathJax}}
|
{{if .Collection.RenderMathJax}}
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
<meta property="og:type" content="article" />
|
<meta property="og:type" content="article" />
|
||||||
<meta property="og:url" content="{{.CanonicalURL}}tag:{{.Tag}}" />
|
<meta property="og:url" content="{{.CanonicalURL}}tag:{{.Tag}}" />
|
||||||
<meta property="og:image" content="{{.Collection.AvatarURL}}">
|
<meta property="og:image" content="{{.Collection.AvatarURL}}">
|
||||||
|
{{template "collection-meta" .}}
|
||||||
{{if .Collection.StyleSheet}}<style type="text/css">{{.Collection.StyleSheetDisplay}}</style>{{end}}
|
{{if .Collection.StyleSheet}}<style type="text/css">{{.Collection.StyleSheetDisplay}}</style>{{end}}
|
||||||
|
|
||||||
{{if .Collection.RenderMathJax}}
|
{{if .Collection.RenderMathJax}}
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
<meta property="og:url" content="{{.CanonicalURL}}" />
|
<meta property="og:url" content="{{.CanonicalURL}}" />
|
||||||
<meta property="og:description" content="{{.Description}}" />
|
<meta property="og:description" content="{{.Description}}" />
|
||||||
<meta property="og:image" content="{{.AvatarURL}}">
|
<meta property="og:image" content="{{.AvatarURL}}">
|
||||||
|
{{template "collection-meta" .}}
|
||||||
{{if .StyleSheet}}<style type="text/css">{{.StyleSheetDisplay}}</style>{{end}}
|
{{if .StyleSheet}}<style type="text/css">{{.StyleSheetDisplay}}</style>{{end}}
|
||||||
|
|
||||||
{{if .RenderMathJax}}
|
{{if .RenderMathJax}}
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
<!-- Miscelaneous render related template parts we use multiple times -->
|
<!-- Miscelaneous render related template parts we use multiple times -->
|
||||||
|
{{define "collection-meta"}}
|
||||||
|
{{if .Monetization -}}
|
||||||
|
<meta name="monetization" content="{{.Monetization}}" />
|
||||||
|
{{- end}}
|
||||||
|
{{end}}
|
||||||
|
|
||||||
{{define "highlighting"}}
|
{{define "highlighting"}}
|
||||||
<script>
|
<script>
|
||||||
// TODO: this feels more like a mutation observer
|
// TODO: this feels more like a mutation observer
|
||||||
|
|
Loading…
Reference in New Issue