Phase 1, part 1: fetch, write and publish posts from the web app
Brings back posting, which Phase 0 removed with the terminal interface. - Content page: per inventory entry, fetch its X account, X hashtag search, YouTube channel and RSS/Atom feeds (new), then select, dismiss or restore the fetched items, which are kept in the database. - Writing: one AI call returns a draft per channel (X and LinkedIn), prompted from the company profile, the entry's relationship, talking points and mention policy, and each channel's rules. Fetched text is quoted as untrusted. An over-long X draft gets one request to shorten. - Drafts page: edit with a live length counter that counts like X, then publish each draft on its own. A draft is claimed before posting so it can't go out twice; failures are kept on the draft for a retry; X tokens are refreshed and saved. - Migration 2 adds content_items and drafts, and turns queued posts into drafts for the platforms they hadn't reached. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"supermarket/internal/api/linkedin"
|
||||
"supermarket/internal/api/rss"
|
||||
"supermarket/internal/api/twitter"
|
||||
"supermarket/internal/api/youtube"
|
||||
"supermarket/internal/content"
|
||||
"supermarket/internal/fetcher"
|
||||
"supermarket/internal/oauth"
|
||||
"supermarket/internal/secrets"
|
||||
)
|
||||
|
||||
// fetchMaxResults is how many posts or videos one source returns per fetch.
|
||||
const fetchMaxResults = 20
|
||||
|
||||
// fetcher builds a fetcher from the saved credentials.
|
||||
func (s *Server) fetcher() *fetcher.Fetcher {
|
||||
f := &fetcher.Fetcher{RSS: rss.New("Supermarket/" + s.Version + " (feed reader)")}
|
||||
if tok := s.Secrets.Get(secrets.XBearerToken); tok != "" {
|
||||
f.Twitter = twitter.New(tok, "", fetchMaxResults)
|
||||
}
|
||||
if key := s.Secrets.Get(secrets.YouTubeAPIKey); key != "" {
|
||||
f.YouTube = youtube.New(key, fetchMaxResults)
|
||||
}
|
||||
return f
|
||||
}
|
||||
|
||||
// publishers are the channels signed in for posting.
|
||||
func (s *Server) publishers() content.Publishers {
|
||||
pubs := content.Publishers{}
|
||||
if tok := s.Secrets.Get(secrets.XAccessToken); tok != "" {
|
||||
c := twitter.New("", tok, 0)
|
||||
// X access tokens last two hours; refresh tokens are single-use, so
|
||||
// each new one is saved before the old is gone.
|
||||
if s.Secrets.Has(secrets.XRefreshToken) && s.Secrets.Has(secrets.XClientID) {
|
||||
c.SetTokenRefresher(func(ctx context.Context) (string, string, error) {
|
||||
res, err := oauth.RefreshX(ctx, s.Secrets.Get(secrets.XClientID),
|
||||
s.Secrets.Get(secrets.XClientSecret), s.Secrets.Get(secrets.XRefreshToken))
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
updates := map[string]string{secrets.XAccessToken: res.AccessToken}
|
||||
if res.RefreshToken != "" {
|
||||
updates[secrets.XRefreshToken] = res.RefreshToken
|
||||
}
|
||||
if err := s.Secrets.Set(updates); err != nil {
|
||||
// Keep going with the new token; the next start will need
|
||||
// a new sign-in.
|
||||
s.Log.Error("x: couldn't save the refreshed token; sign in to X again later", "err", err)
|
||||
}
|
||||
return res.AccessToken, res.RefreshToken, nil
|
||||
})
|
||||
}
|
||||
pubs[content.ChannelX] = xPublisher{c}
|
||||
}
|
||||
if tok, urn := s.Secrets.Get(secrets.LinkedInAccessToken), s.Secrets.Get(secrets.LinkedInAuthorURN); tok != "" && urn != "" {
|
||||
pubs[content.ChannelLinkedIn] = linkedInPublisher{linkedin.New(tok, urn)}
|
||||
}
|
||||
return pubs
|
||||
}
|
||||
|
||||
type xPublisher struct{ c *twitter.Client }
|
||||
|
||||
// Publish appends the source link to the post, as the old app did; X shows
|
||||
// it as a card.
|
||||
func (p xPublisher) Publish(ctx context.Context, text, sourceURL string) (string, error) {
|
||||
if sourceURL != "" {
|
||||
text += "\n\n" + sourceURL
|
||||
}
|
||||
return p.c.PostTweet(ctx, text)
|
||||
}
|
||||
|
||||
type linkedInPublisher struct{ c *linkedin.Client }
|
||||
|
||||
// Publish attaches the source link as an article preview.
|
||||
func (p linkedInPublisher) Publish(ctx context.Context, text, sourceURL string) (string, error) {
|
||||
return p.c.PostUpdate(ctx, text, sourceURL)
|
||||
}
|
||||
@@ -0,0 +1,395 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"supermarket/internal/ai"
|
||||
"supermarket/internal/content"
|
||||
"supermarket/internal/fetcher"
|
||||
"supermarket/internal/inventory"
|
||||
"supermarket/internal/profile"
|
||||
)
|
||||
|
||||
// maxPerItem caps "one post per item", which makes one AI call per item.
|
||||
const maxPerItem = 10
|
||||
|
||||
// --- Sources: entries and their fetched items ---
|
||||
|
||||
type contentRow struct {
|
||||
Entry inventory.Entry
|
||||
Sources []string
|
||||
Waiting int
|
||||
LastChecked time.Time
|
||||
}
|
||||
|
||||
func (s *Server) contentIndex(w http.ResponseWriter, r *http.Request) {
|
||||
entries, err := inventory.List(s.DB, "")
|
||||
if err != nil {
|
||||
s.serverError(w, err)
|
||||
return
|
||||
}
|
||||
counts, err := content.Counts(s.DB)
|
||||
if err != nil {
|
||||
s.serverError(w, err)
|
||||
return
|
||||
}
|
||||
rows := make([]contentRow, 0, len(entries))
|
||||
for _, e := range entries {
|
||||
last, _ := content.LastChecked(s.DB, e.Name)
|
||||
rows = append(rows, contentRow{Entry: e, Sources: fetcher.Sources(&e),
|
||||
Waiting: counts[strings.ToLower(e.Name)], LastChecked: last})
|
||||
}
|
||||
drafts, _ := content.CountDrafts(s.DB)
|
||||
s.render(w, r, "content", page{Title: "Content", Nav: "content", Data: map[string]any{
|
||||
"Rows": rows, "Drafts": drafts,
|
||||
}})
|
||||
}
|
||||
|
||||
type channelChoice struct {
|
||||
content.Channel
|
||||
Connected bool
|
||||
}
|
||||
|
||||
type entryPage struct {
|
||||
Entry *inventory.Entry
|
||||
Sources []string
|
||||
Items []content.Item
|
||||
ShowDismissed bool
|
||||
LastChecked time.Time
|
||||
Since time.Time
|
||||
Channels []channelChoice
|
||||
ProfileSet bool
|
||||
Drafts int
|
||||
// After a fetch
|
||||
Fetched bool
|
||||
NewItems int
|
||||
Errors []string
|
||||
Skipped []string
|
||||
}
|
||||
|
||||
func (s *Server) loadEntry(w http.ResponseWriter, r *http.Request) *inventory.Entry {
|
||||
id, err := strconv.ParseInt(r.PathValue("id"), 10, 64)
|
||||
if err != nil {
|
||||
http.NotFound(w, r)
|
||||
return nil
|
||||
}
|
||||
e, err := inventory.Get(s.DB, id)
|
||||
if err != nil {
|
||||
s.serverError(w, err)
|
||||
return nil
|
||||
}
|
||||
if e == nil {
|
||||
http.NotFound(w, r)
|
||||
}
|
||||
return e
|
||||
}
|
||||
|
||||
func (s *Server) entryData(e *inventory.Entry, showDismissed bool) (*entryPage, error) {
|
||||
items, err := content.ListItems(s.DB, e.Name, showDismissed, 200)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
last, err := content.LastChecked(s.DB, e.Name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
since, _ := content.Since(s.DB, e.Name, time.Now())
|
||||
p, err := profile.Load(s.DB)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pubs := s.publishers()
|
||||
var chans []channelChoice
|
||||
for _, c := range content.Channels {
|
||||
chans = append(chans, channelChoice{c, pubs[c.ID] != nil})
|
||||
}
|
||||
drafts, _ := content.CountDrafts(s.DB)
|
||||
return &entryPage{Entry: e, Sources: fetcher.Sources(e), Items: items, ShowDismissed: showDismissed,
|
||||
LastChecked: last, Since: since, Channels: chans, ProfileSet: p.IsSet(), Drafts: drafts}, nil
|
||||
}
|
||||
|
||||
func (s *Server) contentEntry(w http.ResponseWriter, r *http.Request) {
|
||||
e := s.loadEntry(w, r)
|
||||
if e == nil {
|
||||
return
|
||||
}
|
||||
d, err := s.entryData(e, r.URL.Query().Get("dismissed") == "1")
|
||||
if err != nil {
|
||||
s.serverError(w, err)
|
||||
return
|
||||
}
|
||||
s.render(w, r, "content-entry", page{Title: e.Name, Nav: "content", Data: d})
|
||||
}
|
||||
|
||||
func (s *Server) contentFetch(w http.ResponseWriter, r *http.Request) {
|
||||
e := s.loadEntry(w, r)
|
||||
if e == nil {
|
||||
return
|
||||
}
|
||||
now := time.Now()
|
||||
since, err := content.Since(s.DB, e.Name, now)
|
||||
if err != nil {
|
||||
s.serverError(w, err)
|
||||
return
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(r.Context(), 90*time.Second)
|
||||
defer cancel()
|
||||
res := s.fetcher().Fetch(ctx, e, since)
|
||||
n, err := content.SaveItems(s.DB, res.Items)
|
||||
if err != nil {
|
||||
s.serverError(w, err)
|
||||
return
|
||||
}
|
||||
// Only move the start of the next fetch on if every source answered, so
|
||||
// a failed source is read from the same point next time.
|
||||
if len(res.Errors) == 0 {
|
||||
if err := content.SetLastChecked(s.DB, e.Name, now); err != nil {
|
||||
s.serverError(w, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
d, err := s.entryData(e, false)
|
||||
if err != nil {
|
||||
s.serverError(w, err)
|
||||
return
|
||||
}
|
||||
d.Fetched, d.NewItems, d.Errors, d.Skipped = true, n, res.Errors, res.Skipped
|
||||
s.render(w, r, "content-entry", page{Title: e.Name, Nav: "content", Data: d})
|
||||
}
|
||||
|
||||
// contentItems handles the item list's buttons: dismiss, restore, write.
|
||||
func (s *Server) contentItems(w http.ResponseWriter, r *http.Request) {
|
||||
e := s.loadEntry(w, r)
|
||||
if e == nil {
|
||||
return
|
||||
}
|
||||
if err := r.ParseForm(); err != nil {
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
ids := r.PostForm["item"]
|
||||
back := fmt.Sprintf("/content/%d", e.ID)
|
||||
showErr := func(msg string) {
|
||||
d, err := s.entryData(e, r.PostForm.Get("dismissed") == "1")
|
||||
if err != nil {
|
||||
s.serverError(w, err)
|
||||
return
|
||||
}
|
||||
s.render(w, r, "content-entry", page{Title: e.Name, Nav: "content", Error: msg, Data: d})
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
showErr("Select at least one item first.")
|
||||
return
|
||||
}
|
||||
|
||||
switch r.PostForm.Get("action") {
|
||||
case "dismiss":
|
||||
if err := content.Dismiss(s.DB, ids); err != nil {
|
||||
s.serverError(w, err)
|
||||
return
|
||||
}
|
||||
redirect(w, r, back, "dismissed")
|
||||
case "restore":
|
||||
if err := content.Restore(s.DB, ids); err != nil {
|
||||
s.serverError(w, err)
|
||||
return
|
||||
}
|
||||
redirect(w, r, back+"?dismissed=1", "restored")
|
||||
case "write":
|
||||
if err := s.writeDrafts(r, e, ids); err != nil {
|
||||
showErr(err.Error())
|
||||
return
|
||||
}
|
||||
redirect(w, r, "/drafts", "drafted")
|
||||
default:
|
||||
http.Error(w, "unknown action", http.StatusBadRequest)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Server) writeDrafts(r *http.Request, e *inventory.Entry, ids []string) error {
|
||||
channels := r.PostForm["channel"]
|
||||
if len(channels) == 0 {
|
||||
return errors.New("choose at least one channel to write for")
|
||||
}
|
||||
perItem := r.PostForm.Get("mode") == "each"
|
||||
if perItem && len(ids) > maxPerItem {
|
||||
return fmt.Errorf("one post per item works on up to %d items at a time; you selected %d", maxPerItem, len(ids))
|
||||
}
|
||||
p, err := profile.Load(s.DB)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cfg, err := ai.LoadConfig(s.DB)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
client, err := ai.New(cfg, s.Secrets)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
items, err := content.GetItems(s.DB, ids)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
groups := [][]content.Item{items}
|
||||
if perItem {
|
||||
groups = groups[:0]
|
||||
for _, it := range items {
|
||||
groups = append(groups, []content.Item{it})
|
||||
}
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(r.Context(), 5*time.Minute)
|
||||
defer cancel()
|
||||
// Keep channels in display order whatever order the form sent.
|
||||
var ordered []string
|
||||
for _, c := range content.Channels {
|
||||
for _, ch := range channels {
|
||||
if ch == c.ID {
|
||||
ordered = append(ordered, c.ID)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
written := 0
|
||||
for _, g := range groups {
|
||||
drafts, err := content.Generate(ctx, client, content.Request{Profile: p, Entry: e, Items: g, Channels: ordered})
|
||||
if err != nil {
|
||||
if written > 0 {
|
||||
return fmt.Errorf("wrote %d set(s) of drafts, then: %w", written, err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
if _, err := content.CreateDrafts(s.DB, drafts); err != nil {
|
||||
return err
|
||||
}
|
||||
written++
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// --- Drafts ---
|
||||
|
||||
type draftBatch struct {
|
||||
Batch string
|
||||
InventoryName string
|
||||
Kind string
|
||||
CreatedAt time.Time
|
||||
SourceURL string
|
||||
Drafts []content.Draft
|
||||
}
|
||||
|
||||
func (s *Server) draftsPage(w http.ResponseWriter, r *http.Request) {
|
||||
s.renderDrafts(w, r, "")
|
||||
}
|
||||
|
||||
func (s *Server) renderDrafts(w http.ResponseWriter, r *http.Request, errMsg string) {
|
||||
pending, err := content.ListDrafts(s.DB, 200, content.StatusDraft, content.StatusFailed)
|
||||
if err != nil {
|
||||
s.serverError(w, err)
|
||||
return
|
||||
}
|
||||
var batches []*draftBatch
|
||||
byID := map[string]*draftBatch{}
|
||||
for _, d := range pending {
|
||||
b := byID[d.Batch]
|
||||
if b == nil {
|
||||
b = &draftBatch{Batch: d.Batch, InventoryName: d.InventoryName, Kind: d.Kind, CreatedAt: d.CreatedAt, SourceURL: d.SourceURL}
|
||||
byID[d.Batch] = b
|
||||
batches = append(batches, b)
|
||||
}
|
||||
b.Drafts = append(b.Drafts, d)
|
||||
}
|
||||
for _, b := range batches {
|
||||
// X first, then LinkedIn, whatever order they were stored in.
|
||||
ordered := make([]content.Draft, 0, len(b.Drafts))
|
||||
for _, c := range content.Channels {
|
||||
for _, d := range b.Drafts {
|
||||
if d.Channel == c.ID {
|
||||
ordered = append(ordered, d)
|
||||
}
|
||||
}
|
||||
}
|
||||
b.Drafts = ordered
|
||||
}
|
||||
published, err := content.ListDrafts(s.DB, 20, content.StatusPublished)
|
||||
if err != nil {
|
||||
s.serverError(w, err)
|
||||
return
|
||||
}
|
||||
pubs := s.publishers()
|
||||
connected := map[string]bool{}
|
||||
for id := range pubs {
|
||||
connected[id] = true
|
||||
}
|
||||
s.render(w, r, "drafts", page{Title: "Drafts", Nav: "content", Error: errMsg, Data: map[string]any{
|
||||
"Batches": batches, "Published": published, "Connected": connected,
|
||||
}})
|
||||
}
|
||||
|
||||
func (s *Server) draftID(w http.ResponseWriter, r *http.Request) (int64, bool) {
|
||||
id, err := strconv.ParseInt(r.PathValue("id"), 10, 64)
|
||||
if err != nil {
|
||||
http.NotFound(w, r)
|
||||
return 0, false
|
||||
}
|
||||
return id, true
|
||||
}
|
||||
|
||||
// draftAction saves, publishes or discards one draft.
|
||||
func (s *Server) draftAction(w http.ResponseWriter, r *http.Request) {
|
||||
id, ok := s.draftID(w, r)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
if err := r.ParseForm(); err != nil {
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
fail := func(err error) {
|
||||
if errors.Is(err, content.ErrNoDraft) {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
s.renderDrafts(w, r, err.Error())
|
||||
}
|
||||
action := r.PathValue("action")
|
||||
if action == "save" || action == "publish" {
|
||||
if text, sent := r.PostForm["content"]; sent {
|
||||
if err := content.UpdateDraft(s.DB, id, text[0]); err != nil {
|
||||
fail(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
switch action {
|
||||
case "save":
|
||||
redirect(w, r, "/drafts", "saved")
|
||||
case "publish":
|
||||
ctx, cancel := context.WithTimeout(r.Context(), 60*time.Second)
|
||||
defer cancel()
|
||||
d, err := content.Publish(ctx, s.DB, s.publishers(), id)
|
||||
if err != nil {
|
||||
name := "the channel"
|
||||
if d != nil {
|
||||
name = d.ChannelName()
|
||||
}
|
||||
fail(fmt.Errorf("Couldn't publish to %s: %w", name, err))
|
||||
return
|
||||
}
|
||||
redirect(w, r, "/drafts", "published")
|
||||
case "discard":
|
||||
if err := content.DiscardDraft(s.DB, id); err != nil {
|
||||
fail(err)
|
||||
return
|
||||
}
|
||||
redirect(w, r, "/drafts", "discarded")
|
||||
default:
|
||||
http.NotFound(w, r)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"supermarket/internal/content"
|
||||
"supermarket/internal/inventory"
|
||||
"supermarket/internal/models"
|
||||
"supermarket/internal/profile"
|
||||
)
|
||||
|
||||
func TestContentPages(t *testing.T) {
|
||||
s, h := newTestServer(t, nil)
|
||||
if err := profile.Save(s.DB, &profile.Profile{Name: "Acme", Description: "Widgets."}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
e := &inventory.Entry{Name: "Jitsi", Relationship: inventory.Partner, RSS: []string{"https://jitsi.example/feed"}}
|
||||
if err := inventory.Save(s.DB, e); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
id := strconv.FormatInt(e.ID, 10)
|
||||
now := time.Now()
|
||||
if _, err := content.SaveItems(s.DB, []models.ContentItem{
|
||||
{ID: "a", Source: models.SourceRSS, Title: "Jitsi 3 is out", Body: "Faster calls.", URL: "https://jitsi.example/3", PublishedAt: now, AppName: "Jitsi"},
|
||||
{ID: "b", Source: models.SourceTwitterAccount, AuthorHandle: "jitsinews", Body: "Hello", PublishedAt: now.Add(-time.Hour), AppName: "Jitsi"},
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
rec := do(h, http.MethodGet, "/content", nil, nil)
|
||||
if body := rec.Body.String(); rec.Code != 200 || !strings.Contains(body, "1 RSS feed") || !strings.Contains(body, ">2<") {
|
||||
t.Errorf("content index: %d\n%s", rec.Code, body)
|
||||
}
|
||||
rec = do(h, http.MethodGet, "/content/"+id, nil, nil)
|
||||
if body := rec.Body.String(); !strings.Contains(body, "Jitsi 3 is out") || !strings.Contains(body, "@jitsinews") ||
|
||||
!strings.Contains(body, "not connected") {
|
||||
t.Errorf("entry page:\n%s", body)
|
||||
}
|
||||
|
||||
// Nothing selected, or no channel: an error on the page, no drafts.
|
||||
rec = postForm(h, "/content/"+id+"/items", url.Values{"action": {"write"}})
|
||||
if rec.Code != 200 || !strings.Contains(rec.Body.String(), "Select at least one item") {
|
||||
t.Errorf("write with nothing selected: %d", rec.Code)
|
||||
}
|
||||
rec = postForm(h, "/content/"+id+"/items", url.Values{"action": {"write"}, "item": {"a"}})
|
||||
if !strings.Contains(rec.Body.String(), "choose at least one channel") {
|
||||
t.Errorf("write without channels:\n%s", rec.Body.String())
|
||||
}
|
||||
// No AI key: the provider's error is shown.
|
||||
rec = postForm(h, "/content/"+id+"/items", url.Values{"action": {"write"}, "item": {"a"}, "channel": {"x"}})
|
||||
if !strings.Contains(rec.Body.String(), "Anthropic API key") {
|
||||
t.Errorf("write without an AI key:\n%s", rec.Body.String())
|
||||
}
|
||||
|
||||
// Dismiss and restore.
|
||||
rec = postForm(h, "/content/"+id+"/items", url.Values{"action": {"dismiss"}, "item": {"b"}})
|
||||
if rec.Code != http.StatusSeeOther {
|
||||
t.Fatalf("dismiss: %d", rec.Code)
|
||||
}
|
||||
if items, _ := content.ListItems(s.DB, "Jitsi", true, 10); len(items) != 1 || items[0].ID != "b" {
|
||||
t.Errorf("dismissed: %+v", items)
|
||||
}
|
||||
postForm(h, "/content/"+id+"/items", url.Values{"action": {"restore"}, "item": {"b"}, "dismissed": {"1"}})
|
||||
if items, _ := content.ListItems(s.DB, "Jitsi", true, 10); len(items) != 0 {
|
||||
t.Errorf("still dismissed: %+v", items)
|
||||
}
|
||||
|
||||
if rec := do(h, http.MethodGet, "/content/999", nil, nil); rec.Code != http.StatusNotFound {
|
||||
t.Errorf("missing entry: %d", rec.Code)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDraftsPage(t *testing.T) {
|
||||
s, h := newTestServer(t, nil)
|
||||
if _, err := content.CreateDrafts(s.DB, []content.Draft{
|
||||
{InventoryName: "Jitsi", Kind: "partner", Channel: content.ChannelLinkedIn, Content: "LinkedIn text", SourceURL: "https://jitsi.example/3"},
|
||||
{InventoryName: "Jitsi", Kind: "partner", Channel: content.ChannelX, Content: "X text", SourceURL: "https://jitsi.example/3"},
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
drafts, _ := content.ListDrafts(s.DB, 10, content.StatusDraft)
|
||||
ids := map[string]string{}
|
||||
for _, d := range drafts {
|
||||
ids[d.Channel] = strconv.FormatInt(d.ID, 10)
|
||||
}
|
||||
|
||||
rec := do(h, http.MethodGet, "/drafts", nil, nil)
|
||||
body := rec.Body.String()
|
||||
if rec.Code != 200 || strings.Index(body, "X text") > strings.Index(body, "LinkedIn text") ||
|
||||
!strings.Contains(body, "31 / 280 including the link") || !strings.Contains(body, `data-reserve="25"`) {
|
||||
t.Errorf("drafts page (X should come first):\n%s", body)
|
||||
}
|
||||
|
||||
// Save an edit.
|
||||
if rec := postForm(h, "/drafts/"+ids["x"]+"/save", url.Values{"content": {"Edited X"}}); rec.Code != http.StatusSeeOther {
|
||||
t.Fatalf("save: %d %s", rec.Code, rec.Body.String())
|
||||
}
|
||||
if d, _ := content.GetDraft(s.DB, mustID(ids["x"])); d.Content != "Edited X" {
|
||||
t.Errorf("content = %q", d.Content)
|
||||
}
|
||||
// X isn't connected: the error is shown and the edit is still saved.
|
||||
rec = postForm(h, "/drafts/"+ids["x"]+"/publish", url.Values{"content": {"Edited again"}})
|
||||
if rec.Code != 200 || !strings.Contains(rec.Body.String(), "X isn't connected") {
|
||||
t.Errorf("publish without X: %d\n%s", rec.Code, rec.Body.String())
|
||||
}
|
||||
if d, _ := content.GetDraft(s.DB, mustID(ids["x"])); d.Content != "Edited again" || d.Status != content.StatusDraft {
|
||||
t.Errorf("draft after refused publish: %+v", d)
|
||||
}
|
||||
// Discard.
|
||||
if rec := postForm(h, "/drafts/"+ids["linkedin"]+"/discard", nil); rec.Code != http.StatusSeeOther {
|
||||
t.Fatalf("discard: %d", rec.Code)
|
||||
}
|
||||
if rec := postForm(h, "/drafts/"+ids["linkedin"]+"/discard", nil); !strings.Contains(rec.Body.String(), "can't be changed") {
|
||||
t.Errorf("discarding twice: %s", rec.Body.String())
|
||||
}
|
||||
if rec := postForm(h, "/drafts/999/save", url.Values{"content": {"x"}}); !strings.Contains(rec.Body.String(), "can't be changed") {
|
||||
t.Errorf("unknown draft: %d %s", rec.Code, rec.Body.String())
|
||||
}
|
||||
}
|
||||
|
||||
func mustID(s string) int64 {
|
||||
n, _ := strconv.ParseInt(s, 10, 64)
|
||||
return n
|
||||
}
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
|
||||
"supermarket/internal/ai"
|
||||
"supermarket/internal/bridge"
|
||||
"supermarket/internal/content"
|
||||
"supermarket/internal/core"
|
||||
"supermarket/internal/inventory"
|
||||
"supermarket/internal/profile"
|
||||
@@ -51,6 +52,7 @@ type step struct {
|
||||
|
||||
type module struct {
|
||||
Name, Phase, Body string
|
||||
Link string // set once the module is usable
|
||||
}
|
||||
|
||||
func (s *Server) dashboard(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -97,15 +99,14 @@ func (s *Server) dashboard(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
modules := []module{
|
||||
{"Content", "Phase 1", "Draft posts from partner and competitor news and your own products; review and publish to X, LinkedIn and Reddit."},
|
||||
{"Prospects", "Phase 2", "Find companies and people who fit your targets, and add the ones you approve to EspoCRM through Hermes."},
|
||||
{"SEO", "Phase 3", "Audit your websites and open fixes as pull requests on your Hugo repositories."},
|
||||
{"Metrics", "Phase 4", "Pipeline influence, CAC, CLV and NRR from Stripe, EspoCRM and Plausible."},
|
||||
{"Sites", "Phase 5", "Build pages and sites from a component library and publish them through Gitea."},
|
||||
{"Content", "Phase 1", "Draft posts from partner and competitor news and your own products; review and publish to X, LinkedIn and Reddit.", "/content"},
|
||||
{"Prospects", "Phase 2", "Find companies and people who fit your targets, and add the ones you approve to EspoCRM through Hermes.", ""},
|
||||
{"SEO", "Phase 3", "Audit your websites and open fixes as pull requests on your Hugo repositories.", ""},
|
||||
{"Metrics", "Phase 4", "Pipeline influence, CAC, CLV and NRR from Stripe, EspoCRM and Plausible.", ""},
|
||||
{"Sites", "Phase 5", "Build pages and sites from a component library and publish them through Gitea.", ""},
|
||||
}
|
||||
|
||||
var queued int
|
||||
_ = s.DB.QueryRow(`SELECT count(*) FROM posts`).Scan(&queued)
|
||||
queued, _ := content.CountDrafts(s.DB)
|
||||
|
||||
s.render(w, r, "dashboard", page{Title: "Overview", Nav: "home", Data: map[string]any{
|
||||
"Steps": steps,
|
||||
|
||||
+18
-4
@@ -14,6 +14,7 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"supermarket/internal/api/twitter"
|
||||
"supermarket/internal/core"
|
||||
"supermarket/internal/db"
|
||||
"supermarket/internal/legacy"
|
||||
@@ -90,6 +91,13 @@ func (s *Server) Handler() (http.Handler, error) {
|
||||
mux.HandleFunc("POST /auth/{provider}/start", s.oauthStart)
|
||||
mux.HandleFunc("GET /auth/{provider}/callback", s.oauthCallback)
|
||||
|
||||
mux.HandleFunc("GET /content", s.contentIndex)
|
||||
mux.HandleFunc("GET /content/{id}", s.contentEntry)
|
||||
mux.HandleFunc("POST /content/{id}/fetch", s.contentFetch)
|
||||
mux.HandleFunc("POST /content/{id}/items", s.contentItems)
|
||||
mux.HandleFunc("GET /drafts", s.draftsPage)
|
||||
mux.HandleFunc("POST /drafts/{id}/{action}", s.draftAction)
|
||||
|
||||
mux.HandleFunc("GET /core", s.corePage)
|
||||
mux.HandleFunc("GET /core/checks", s.coreChecks)
|
||||
|
||||
@@ -153,10 +161,11 @@ func sameOrigin(r *http.Request) bool {
|
||||
|
||||
func (s *Server) loadTemplates() error {
|
||||
funcs := template.FuncMap{
|
||||
"lines": func(v []string) string { return strings.Join(v, "\n") },
|
||||
"join": strings.Join,
|
||||
"ago": ago,
|
||||
"add": func(a, b int) int { return a + b },
|
||||
"lines": func(v []string) string { return strings.Join(v, "\n") },
|
||||
"join": strings.Join,
|
||||
"ago": ago,
|
||||
"add": func(a, b int) int { return a + b },
|
||||
"xreserve": twitter.URLReserve,
|
||||
"truncate": func(n int, s string) string {
|
||||
r := []rune(s)
|
||||
if len(r) <= n {
|
||||
@@ -233,6 +242,11 @@ var flashes = map[string]string{
|
||||
"li-connected": "LinkedIn is connected.",
|
||||
"imported": "Imported.",
|
||||
"oauth-expired": "That sign-in took too long or was already used. Try again.",
|
||||
"dismissed": "Dismissed.",
|
||||
"restored": "Restored.",
|
||||
"drafted": "Drafts written. Review them below.",
|
||||
"published": "Published.",
|
||||
"discarded": "Discarded.",
|
||||
}
|
||||
|
||||
func redirect(w http.ResponseWriter, r *http.Request, path, msg string) {
|
||||
|
||||
@@ -88,7 +88,8 @@ func TestEveryPageRenders(t *testing.T) {
|
||||
|
||||
for _, path := range []string{"/", "/?msg=saved", "/profile", "/inventory", "/inventory?relationship=partner",
|
||||
"/inventory/new", "/inventory/1", "/inventory/import", "/inventory/export",
|
||||
"/settings/ai", "/settings/credentials", "/core", "/static/app.css", "/static/htmx.min.js", "/healthz"} {
|
||||
"/settings/ai", "/settings/credentials", "/core", "/static/app.css", "/static/htmx.min.js", "/healthz",
|
||||
"/content", "/content/1", "/content/1?dismissed=1", "/drafts", "/drafts?msg=drafted"} {
|
||||
rec := do(h, http.MethodGet, path, nil, nil)
|
||||
if rec.Code != http.StatusOK {
|
||||
t.Errorf("core=%v GET %s: %d %s", c != nil, path, rec.Code, rec.Body.String())
|
||||
|
||||
@@ -120,3 +120,22 @@ button.pill:hover { background: #e0f2f7; }
|
||||
.htmx-indicator { display: none; color: var(--muted); }
|
||||
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { display: inline; }
|
||||
[hidden] { display: none !important; }
|
||||
|
||||
/* Content */
|
||||
.muted { color: var(--muted); }
|
||||
.buttons form { margin: 0; }
|
||||
.items { list-style: none; padding: 0; margin: 0 0 1rem; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); }
|
||||
.item { padding: 0.75rem 1rem; border-bottom: 1px solid var(--line); }
|
||||
.item:last-child { border-bottom: 0; }
|
||||
.item label.check { margin: 0; align-items: flex-start; }
|
||||
.item label.check > span { display: flex; flex-direction: column; gap: 0.2rem; }
|
||||
.item .body { white-space: pre-line; overflow-wrap: anywhere; }
|
||||
.item.used { background: var(--band); }
|
||||
.meta { color: var(--muted); font-size: 0.85rem; font-weight: normal; }
|
||||
.drafts { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 1.25rem; }
|
||||
.draft h3 { margin: 0 0 0.5rem; }
|
||||
.draft .actions { margin: 0.5rem 0; }
|
||||
.draft.failed textarea { border-color: #f3b5ae; }
|
||||
.count { margin: 0.3rem 0 0; font-size: 0.85rem; color: var(--muted); text-align: right; }
|
||||
.count.over { color: var(--bad); font-weight: 600; }
|
||||
button.small { padding: 0.3rem 0.8rem; font-size: 0.85rem; }
|
||||
|
||||
@@ -41,10 +41,65 @@
|
||||
}
|
||||
});
|
||||
|
||||
// Ask before submitting a form with data-confirm.
|
||||
// Ask before submitting a form with data-confirm. A form with data-busy
|
||||
// shows that text on the button that submitted it, and can't be sent twice,
|
||||
// while a slow request (fetching, writing, publishing) runs. With
|
||||
// data-busy-on, only that button's value counts as slow.
|
||||
document.addEventListener("submit", function (e) {
|
||||
var msg = e.target.getAttribute("data-confirm");
|
||||
if (msg && !window.confirm(msg)) e.preventDefault();
|
||||
var form = e.target;
|
||||
var msg = form.getAttribute("data-confirm");
|
||||
if (msg && !window.confirm(msg)) {
|
||||
e.preventDefault();
|
||||
return;
|
||||
}
|
||||
var busy = form.getAttribute("data-busy");
|
||||
if (!busy) return;
|
||||
var btn = e.submitter;
|
||||
var only = form.getAttribute("data-busy-on");
|
||||
if (only && (!btn || btn.value !== only)) return;
|
||||
if (form.dataset.sending) {
|
||||
e.preventDefault();
|
||||
return;
|
||||
}
|
||||
form.dataset.sending = "1";
|
||||
if (btn) {
|
||||
// A disabled button isn't submitted, so carry its value in a hidden field.
|
||||
if (btn.name) {
|
||||
var keep = document.createElement("input");
|
||||
keep.type = "hidden";
|
||||
keep.name = btn.name;
|
||||
keep.value = btn.value;
|
||||
form.appendChild(keep);
|
||||
}
|
||||
btn.textContent = busy;
|
||||
setTimeout(function () { btn.disabled = true; }, 0);
|
||||
}
|
||||
});
|
||||
|
||||
// Live length of a post: <textarea data-count="x|linkedin" data-limit
|
||||
// data-reserve> followed by its <p class="count">. X counts most characters
|
||||
// outside Latin, punctuation and symbols as 2, like the server does.
|
||||
function weighted(s) {
|
||||
var n = 0;
|
||||
for (var ch of s) {
|
||||
var c = ch.codePointAt(0);
|
||||
if (c <= 0x10ff || (c >= 0x2000 && c <= 0x200d) || (c >= 0x2010 && c <= 0x201f) || (c >= 0x2032 && c <= 0x2037)) n += 1;
|
||||
else n += 2;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
function count(area) {
|
||||
var out = document.getElementById(area.getAttribute("aria-describedby"));
|
||||
if (!out) return;
|
||||
var limit = parseInt(area.getAttribute("data-limit"), 10);
|
||||
var reserve = parseInt(area.getAttribute("data-reserve") || "0", 10);
|
||||
var text = area.value.trim();
|
||||
var n = area.getAttribute("data-count") === "x" ? weighted(text) + reserve : Array.from(text).length;
|
||||
out.textContent = n + " / " + limit + (reserve ? " including the link" : "");
|
||||
out.classList.toggle("over", n > limit);
|
||||
}
|
||||
document.addEventListener("input", function (e) {
|
||||
if (e.target.matches("textarea[data-count]")) count(e.target);
|
||||
});
|
||||
|
||||
document.addEventListener("DOMContentLoaded", syncProvider);
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
{{define "content"}}{{with .Data}}
|
||||
<nav class="tabs">
|
||||
<a href="/content" aria-current="page">Sources</a>
|
||||
<a href="/drafts">Drafts{{if .Drafts}} ({{.Drafts}}){{end}}</a>
|
||||
</nav>
|
||||
<div class="heading">
|
||||
<h1>{{.Entry.Name}} <span class="badge {{.Entry.Relationship}}">{{.Entry.Relationship}}</span></h1>
|
||||
<div class="buttons">
|
||||
<form method="post" action="/content/{{.Entry.ID}}/fetch" data-busy="Fetching…">
|
||||
<button type="submit" {{if not .Sources}}disabled{{end}}>Fetch new</button>
|
||||
</form>
|
||||
<a class="button secondary" href="/inventory/{{.Entry.ID}}">Edit entry</a>
|
||||
</div>
|
||||
</div>
|
||||
<p class="lede">
|
||||
{{if .Sources}}Reads {{join .Sources ", "}}.{{else}}This entry has no sources yet: add an X handle, hashtags, a YouTube channel or RSS feeds to it.{{end}}
|
||||
Last fetched {{ago .LastChecked}}; the next fetch looks for posts since {{.Since.Local.Format "2 Jan 15:04"}}.
|
||||
</p>
|
||||
|
||||
{{if .Fetched}}
|
||||
<section class="card">
|
||||
<p><strong>{{if .NewItems}}{{.NewItems}} new item{{if ne .NewItems 1}}s{{end}}.{{else}}Nothing new.{{end}}</strong></p>
|
||||
{{if .Errors}}<p class="warn-text">Some sources failed; they'll be read from the same point next time:</p>
|
||||
<ul>{{range .Errors}}<li>{{.}}</li>{{end}}</ul>{{end}}
|
||||
{{if .Skipped}}<p class="muted">Skipped, for lack of credentials (<a href="/settings/credentials">add them</a>): {{join .Skipped "; "}}.</p>{{end}}
|
||||
</section>
|
||||
{{end}}
|
||||
|
||||
<nav class="tabs">
|
||||
<a href="/content/{{.Entry.ID}}" {{if not .ShowDismissed}}aria-current="page"{{end}}>Items</a>
|
||||
<a href="/content/{{.Entry.ID}}?dismissed=1" {{if .ShowDismissed}}aria-current="page"{{end}}>Dismissed</a>
|
||||
</nav>
|
||||
|
||||
{{if .Items}}
|
||||
<form method="post" action="/content/{{.Entry.ID}}/items" data-busy-on="write" data-busy="Writing drafts…">
|
||||
{{if .ShowDismissed}}<input type="hidden" name="dismissed" value="1">{{end}}
|
||||
<ul class="items">
|
||||
{{range .Items}}
|
||||
<li class="item{{if .Used}} used{{end}}">
|
||||
<label class="check">
|
||||
<input type="checkbox" name="item" value="{{.ID}}">
|
||||
<span>
|
||||
<span class="meta">{{.Source}} · {{if .AuthorHandle}}@{{.AuthorHandle}}{{else}}{{.Author}}{{end}} · {{.PublishedAt.Local.Format "2 Jan 15:04"}}{{if .Used}} · <em>drafted</em>{{end}}</span>
|
||||
{{if .Title}}<strong>{{.Title}}</strong>{{end}}
|
||||
<span class="body">{{truncate 400 .Body}}</span>
|
||||
{{if .URL}}<a href="{{.URL}}" target="_blank" rel="noopener noreferrer">Open</a>{{end}}
|
||||
</span>
|
||||
</label>
|
||||
</li>
|
||||
{{end}}
|
||||
</ul>
|
||||
|
||||
{{if .ShowDismissed}}
|
||||
<div class="actions"><button type="submit" name="action" value="restore" class="secondary">Restore selected</button></div>
|
||||
{{else}}
|
||||
<section class="card">
|
||||
<h2>Write drafts from the selected items</h2>
|
||||
{{if not .ProfileSet}}<p class="warn-text">Fill in the <a href="/profile">company profile</a> first: drafts are written in its voice.</p>{{end}}
|
||||
<fieldset class="choice">
|
||||
<legend>Channels</legend>
|
||||
{{range .Channels}}
|
||||
<label class="check"><input type="checkbox" name="channel" value="{{.ID}}" {{if .Connected}}checked{{end}}> {{.Name}}{{if not .Connected}} <span class="muted">(not connected: you can draft, but not publish yet)</span>{{end}}</label>
|
||||
{{end}}
|
||||
</fieldset>
|
||||
<fieldset class="choice">
|
||||
<legend>Posts</legend>
|
||||
<label class="check"><input type="radio" name="mode" value="one" checked> One post from all selected items</label>
|
||||
<label class="check"><input type="radio" name="mode" value="each"> One post per item (up to 10)</label>
|
||||
</fieldset>
|
||||
<div class="actions">
|
||||
<button type="submit" name="action" value="write" {{if not .ProfileSet}}disabled{{end}}>Write drafts</button>
|
||||
<button type="submit" name="action" value="dismiss" class="secondary">Dismiss selected</button>
|
||||
</div>
|
||||
</section>
|
||||
{{end}}
|
||||
</form>
|
||||
{{else}}
|
||||
<section class="card empty">
|
||||
<p>{{if .ShowDismissed}}Nothing dismissed.{{else}}No items yet. Fetch to see what {{.Entry.Name}} has been up to.{{end}}</p>
|
||||
</section>
|
||||
{{end}}
|
||||
{{end}}{{end}}
|
||||
@@ -0,0 +1,29 @@
|
||||
{{define "content"}}{{with .Data}}
|
||||
<nav class="tabs">
|
||||
<a href="/content" aria-current="page">Sources</a>
|
||||
<a href="/drafts">Drafts{{if .Drafts}} ({{.Drafts}}){{end}}</a>
|
||||
</nav>
|
||||
<h1>Content</h1>
|
||||
<p class="lede">Pick an inventory entry to fetch its latest news, choose what to write about, and get a draft for each channel to review on the <a href="/drafts">Drafts</a> page.</p>
|
||||
|
||||
{{if .Rows}}
|
||||
<table class="list">
|
||||
<thead><tr><th>Entry</th><th>Relationship</th><th>Sources</th><th>Waiting</th><th>Last fetched</th></tr></thead>
|
||||
<tbody>
|
||||
{{range .Rows}}
|
||||
<tr>
|
||||
<td><a href="/content/{{.Entry.ID}}">{{.Entry.Name}}</a></td>
|
||||
<td><span class="badge {{.Entry.Relationship}}">{{.Entry.Relationship}}</span></td>
|
||||
<td>{{if .Sources}}{{join .Sources ", "}}{{else}}<span class="muted">none: <a href="/inventory/{{.Entry.ID}}">add some</a></span>{{end}}</td>
|
||||
<td>{{if .Waiting}}{{.Waiting}}{{end}}</td>
|
||||
<td>{{ago .LastChecked}}</td>
|
||||
</tr>
|
||||
{{end}}
|
||||
</tbody>
|
||||
</table>
|
||||
{{else}}
|
||||
<section class="card empty">
|
||||
<p>Add the partners and competitors you post about to the <a href="/inventory">Inventory</a> first.</p>
|
||||
</section>
|
||||
{{end}}
|
||||
{{end}}{{end}}
|
||||
@@ -23,7 +23,7 @@
|
||||
<details class="card">
|
||||
<summary>Imported from the old terminal app {{ago .ImportStatus.At}}</summary>
|
||||
<ul>{{range .ImportStatus.Summary}}<li>{{.}}</li>{{end}}</ul>
|
||||
{{if .QueuedPosts}}<p>{{.QueuedPosts}} queued posts are kept for the Content module (Phase 1).</p>{{end}}
|
||||
{{if .QueuedPosts}}<p>Its queued posts are now drafts: <a href="/drafts">{{.QueuedPosts}} waiting for review</a>.</p>{{end}}
|
||||
</details>
|
||||
{{end}}
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
<div class="grid">
|
||||
{{range .Modules}}
|
||||
<section class="card module">
|
||||
<h3>{{.Name}} <span class="badge">{{.Phase}}</span></h3>
|
||||
<h3>{{if .Link}}<a href="{{.Link}}">{{.Name}}</a>{{else}}{{.Name}}{{end}} <span class="badge">{{.Phase}}</span></h3>
|
||||
<p>{{.Body}}</p>
|
||||
</section>
|
||||
{{end}}
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
{{define "content"}}{{with .Data}}{{$conn := .Connected}}
|
||||
<nav class="tabs">
|
||||
<a href="/content">Sources</a>
|
||||
<a href="/drafts" aria-current="page">Drafts</a>
|
||||
</nav>
|
||||
<h1>Drafts</h1>
|
||||
<p class="lede">Each draft is for one channel, and is published on its own: if one channel fails, the other isn't posted twice. The source link is added when publishing.</p>
|
||||
|
||||
{{if .Batches}}
|
||||
{{range .Batches}}
|
||||
<section class="card batch">
|
||||
<p class="meta">
|
||||
{{if .InventoryName}}<strong>{{.InventoryName}}</strong> <span class="badge {{.Kind}}">{{.Kind}}</span> ·{{end}}
|
||||
written {{ago .CreatedAt}}
|
||||
{{if .SourceURL}} · <a href="{{.SourceURL}}" target="_blank" rel="noopener noreferrer">source</a>{{end}}
|
||||
</p>
|
||||
<div class="drafts">
|
||||
{{range .Drafts}}
|
||||
<div class="draft{{if eq .Status "failed"}} failed{{end}}">
|
||||
<h3>{{.ChannelName}}</h3>
|
||||
{{if .Error}}<p class="error">Last attempt failed: {{.Error}}</p>{{end}}
|
||||
<form method="post" action="/drafts/{{.ID}}/save" data-busy-on="publish" data-busy="Publishing…">
|
||||
<textarea name="content" rows="{{if eq .Channel "x"}}5{{else}}12{{end}}"
|
||||
data-count="{{.Channel}}" data-limit="{{.Limit}}" data-reserve="{{if eq .Channel "x"}}{{xreserve .SourceURL}}{{else}}0{{end}}"
|
||||
aria-describedby="count-{{.ID}}">{{.Content}}</textarea>
|
||||
<p class="count{{if .TooLong}} over{{end}}" id="count-{{.ID}}">{{.Length}} / {{.Limit}}{{if and (eq .Channel "x") .SourceURL}} including the link{{end}}</p>
|
||||
<div class="actions">
|
||||
<button type="submit" name="action" value="publish" formaction="/drafts/{{.ID}}/publish"
|
||||
{{if not (index $conn .Channel)}}disabled title="Sign in to {{.ChannelName}} under Settings → Credentials"{{end}}>Publish to {{.ChannelName}}</button>
|
||||
<button type="submit" class="secondary">Save</button>
|
||||
</div>
|
||||
</form>
|
||||
<form method="post" action="/drafts/{{.ID}}/discard" data-confirm="Discard this {{.ChannelName}} draft?">
|
||||
<button type="submit" class="danger small">Discard</button>
|
||||
</form>
|
||||
</div>
|
||||
{{end}}
|
||||
</div>
|
||||
</section>
|
||||
{{end}}
|
||||
{{else}}
|
||||
<section class="card empty">
|
||||
<p>No drafts waiting. Write some from the <a href="/content">Sources</a> page.</p>
|
||||
</section>
|
||||
{{end}}
|
||||
|
||||
{{if .Published}}
|
||||
<h2>Recently published</h2>
|
||||
<table class="list">
|
||||
<thead><tr><th>When</th><th>Channel</th><th>Entry</th><th>Post</th></tr></thead>
|
||||
<tbody>
|
||||
{{range .Published}}
|
||||
<tr>
|
||||
<td>{{ago .PublishedAt}}</td>
|
||||
<td>{{.ChannelName}}</td>
|
||||
<td>{{.InventoryName}}</td>
|
||||
<td>{{if .PostURL}}<a href="{{.PostURL}}" target="_blank" rel="noopener noreferrer">{{truncate 80 .Content}}</a>{{else}}{{truncate 80 .Content}}{{end}}</td>
|
||||
</tr>
|
||||
{{end}}
|
||||
</tbody>
|
||||
</table>
|
||||
{{end}}
|
||||
{{end}}{{end}}
|
||||
@@ -15,6 +15,7 @@
|
||||
<nav>
|
||||
<a href="/" {{if eq .Nav "home"}}aria-current="page"{{end}}>Overview</a>
|
||||
<a href="/profile" {{if eq .Nav "profile"}}aria-current="page"{{end}}>Profile</a>
|
||||
<a href="/content" {{if eq .Nav "content"}}aria-current="page"{{end}}>Content</a>
|
||||
<a href="/inventory" {{if eq .Nav "inventory"}}aria-current="page"{{end}}>Inventory</a>
|
||||
<a href="/settings/ai" {{if eq .Nav "settings"}}aria-current="page"{{end}}>Settings</a>
|
||||
<a href="/core" {{if eq .Nav "core"}}aria-current="page"{{end}}>Core & Hermes</a>
|
||||
|
||||
Reference in New Issue
Block a user