MCPcopy Index your code
hub / github.com/writefreely/writefreely / handlePremiumContent

Method handlePremiumContent

postrender.go:46–74  ·  view source on GitHub ↗
(c *Collection, isOwner, postPage bool, cfg *config.Config)

Source from the content-addressed store, hash-verified

44)
45
46func (p *Post) handlePremiumContent(c *Collection, isOwner, postPage bool, cfg *config.Config) {
47 if c.Monetization != "" {
48 // User has Web Monetization enabled, so split content if it exists
49 spl := strings.Index(p.Content, shortCodePaid)
50 p.IsPaid = spl > -1
51 if postPage {
52 // We're viewing the individual post
53 if isOwner {
54 p.Content = strings.Replace(p.Content, shortCodePaid, "\n\n"+`<p class="split">Your subscriber content begins here.</p>`+"\n\n", 1)
55 } else {
56 if spl > -1 {
57 p.Content = p.Content[:spl+len(shortCodePaid)]
58 p.Content = strings.Replace(p.Content, shortCodePaid, "\n\n"+`<p class="split">Continue reading with a <strong>Coil</strong> membership.</p>`+"\n\n", 1)
59 }
60 }
61 } else {
62 // We've viewing the post on the collection landing
63 if spl > -1 {
64 baseURL := c.CanonicalURL()
65 if isOwner {
66 baseURL = "/" + c.Alias + "/"
67 }
68
69 p.Content = p.Content[:spl+len(shortCodePaid)]
70 p.HTMLExcerpt = template.HTML(applyMarkdown([]byte(p.Content[:spl]), baseURL, cfg))
71 }
72 }
73 }
74}
75
76func (p *Post) formatContent(cfg *config.Config, c *Collection, isOwner bool, isPostPage bool) {
77 baseURL := c.CanonicalURL()

Callers 2

formatContentMethod · 0.95
FetchPublicPostsMethod · 0.95

Calls 2

applyMarkdownFunction · 0.85
CanonicalURLMethod · 0.45

Tested by

no test coverage detected