Documentation
¶
Overview ¶
Package sponsorships owns the M4 "sponsorships" plugin. It returns the sponsorships the viewer is paying for. In M4 the plugin is scaffolded; the underlying `viewer.sponsorshipsAsSponsor` GraphQL call lands as a follow-up once the schema covers it. The MVP wires the type surface so downstream consumers see the slot.
Index ¶
Constants ¶
const Name = "sponsorships"
Name is the canonical plugin slug.
Variables ¶
var Plugin plugins.Plugin = &sponsorshipsPlugin{}
Plugin is the singleton registered with the global plugin registry.
Functions ¶
func Partial ¶
Partial renders the classic SVG fragment for the sponsorships plugin. Mirrors upstream org_repo/source/templates/classic/partials/sponsorships.ejs: it iterates the configured sections (default "amount, sponsorships") and renders each branch. Unlike the prior implementation it never short-circuits on an empty list — the "amount" section ("$0.00 to open source software") and the "0 users" goal text render even at zero sponsorships, matching the upstream reference card (#449).
Output structure:
<section data-section="sponsorships">
<h2 class="field"><svg heart/>Sponsorships</h2>
[amount]:
<div class="row fill-width">
<section class="sponsorships sponsors goal">
<img src="<heart>" alt="" />
<div><span class="bold">${user}</span> has given a total of
<span class="bold">$X.XX</span> to open source software
[since <span class="bold">${date}</span>].</div>
</section>
</div>
[sponsorships]:
<div class="row fill-width">
<section class="sponsors goal">
<div class="goal-text"><span>${user} helped funding the work of N users and organizations.</span></div>
<div class="row"><img class="avatar ..." .../>...</div>
</section>
</div>
</section>
Types ¶
type Result ¶
type Result struct {
Skipped bool `json:"skipped,omitempty"`
SkippedReason string `json:"-"`
Active []Sponsored `json:"active"`
Past []Sponsored `json:"past,omitempty"`
// Sections honors plugin_sponsorships_sections (default
// "amount, sponsorships") and drives which partial branches render.
Sections []string `json:"sections"`
// Amount is the total spend in US dollars (cents / 100) the viewer
// has sponsored. Renders in the "amount" section; zero is valid and
// still renders as "$0.00".
Amount float64 `json:"amount"`
// Image is the URL of the heart image shown in the "amount" section.
// The render pipeline inlines it as a base64 data URI.
Image string `json:"image,omitempty"`
// Started is the date of the viewer's first sponsorship, shown as
// "since <date>" in the amount line. Nil when there are none.
Started *time.Time `json:"started,omitempty"`
}
Result is the JSON payload published under data.Plugins["sponsorships"].
type Sponsored ¶
type Sponsored struct {
Login string `json:"login"`
Tier string `json:"tier"`
Since time.Time `json:"since"`
Until *time.Time `json:"until,omitempty"`
Avatar string `json:"avatar,omitempty"`
Type string `json:"type,omitempty"`
}
Sponsored carries one entry from the upstream sponsorships list.