Live video on the AT Protocol

add branding to page title el

+80 -38
+80 -38
pkg/linking/linking.go
··· 106 return nil, errors.New("livestream view is not a livestream") 107 } 108 109 - titleStr := fmt.Sprintf("@%s's livestream on %s", lsv.Author.Handle, u.Host) 110 outURL := u.String() 111 - 112 - pageTitle := fmt.Sprintf("@%s | %s", lsv.Author.Handle, u.Host) 113 114 thumbURL, _ := url.Parse(u.String()) 115 thumbURL.Path = "/xrpc/place.stream.live.getProfileCard" ··· 123 // Facebook Meta Tags 124 {Type: "property", Key: "og:url", Content: u.String()}, 125 {Type: "property", Key: "og:type", Content: "website"}, 126 - {Type: "property", Key: "og:title", Content: titleStr}, 127 {Type: "property", Key: "og:description", Content: ls.Title}, 128 {Type: "property", Key: "og:image", Content: thumbURL.String()}, 129 ··· 131 {Type: "name", Key: "twitter:card", Content: "summary_large_image"}, 132 {Type: "property", Key: "twitter:domain", Content: u.Host}, 133 {Type: "property", Key: "twitter:url", Content: outURL}, 134 - {Type: "name", Key: "twitter:title", Content: titleStr}, 135 {Type: "name", Key: "twitter:description", Content: ls.Title}, 136 {Type: "name", Key: "twitter:image", Content: thumbURL.String()}, 137 } 138 139 return l.GenerateHTML(ctx, &PageConfig{ 140 - Title: pageTitle, 141 Metas: metaTags, 142 SentryDSN: sentryDSN, 143 }) ··· 160 {Type: "property", Key: "og:url", Content: u.String()}, 161 {Type: "property", Key: "og:type", Content: "website"}, 162 {Type: "property", Key: "og:title", Content: "Stream.place"}, 163 - {Type: "property", Key: "og:description", Content: "Stream.place is open-source livestreaming on the AT Protocol."}, 164 {Type: "property", Key: "og:image", Content: thumbURL.String()}, 165 166 // Twitter Meta Tags ··· 168 {Type: "property", Key: "twitter:domain", Content: u.Host}, 169 {Type: "property", Key: "twitter:url", Content: u.String()}, 170 {Type: "name", Key: "twitter:title", Content: "Stream.place"}, 171 - {Type: "name", Key: "twitter:description", Content: "Stream.place is open-source livestreaming on the AT Protocol."}, 172 {Type: "name", Key: "twitter:image", Content: thumbURL.String()}, 173 } 174 175 return l.GenerateHTML(ctx, &PageConfig{ 176 - Title: "Stream.place", 177 Metas: metaTags, 178 SentryDSN: sentryDSN, 179 }) ··· 256 }) 257 } 258 259 - if l.sdb != nil && l.cli != nil { 260 - 261 - branding, err := l.getBrandingAssets("did:web:" + l.cli.BroadcasterHost) 262 - 263 - if err == nil { 264 - 265 - for i := range branding { 266 - val := branding[i] 267 - // 268 - marshalledJson, err := json.Marshal(val) 269 - if err != nil { 270 - fmt.Printf("error marshalling branding asset %s: %v\n", val.Key, err) 271 - continue 272 - } 273 - head.AppendChild(&html.Node{ 274 - Type: html.ElementNode, 275 - Data: "meta", 276 - Attr: []html.Attribute{ 277 - {Key: "name", Val: "internal-brand:" + val.Key}, 278 - {Key: "content", Val: string(marshalledJson)}, 279 - }, 280 - }) 281 - 282 - } 283 - } else { 284 - // log but we should not block rendering 285 - fmt.Printf("error fetching branding assets: %v\n", err) 286 - } 287 - } 288 // Render the HTML to a string 289 var buf bytes.Buffer 290 if err := html.Render(&buf, root); err != nil {
··· 106 return nil, errors.New("livestream view is not a livestream") 107 } 108 109 + titleStr := fmt.Sprintf("@%s's livestream on ", lsv.Author.Handle) 110 outURL := u.String() 111 112 thumbURL, _ := url.Parse(u.String()) 113 thumbURL.Path = "/xrpc/place.stream.live.getProfileCard" ··· 121 // Facebook Meta Tags 122 {Type: "property", Key: "og:url", Content: u.String()}, 123 {Type: "property", Key: "og:type", Content: "website"}, 124 {Type: "property", Key: "og:description", Content: ls.Title}, 125 {Type: "property", Key: "og:image", Content: thumbURL.String()}, 126 ··· 128 {Type: "name", Key: "twitter:card", Content: "summary_large_image"}, 129 {Type: "property", Key: "twitter:domain", Content: u.Host}, 130 {Type: "property", Key: "twitter:url", Content: outURL}, 131 {Type: "name", Key: "twitter:description", Content: ls.Title}, 132 {Type: "name", Key: "twitter:image", Content: thumbURL.String()}, 133 } 134 + brandingTitle := "streamplace node" 135 + if l.sdb != nil && l.cli != nil { 136 + branding, err := l.getBrandingAssets("did:web:" + l.cli.BroadcasterHost) 137 + if err == nil { 138 + for i := range branding { 139 + val := branding[i] 140 + if val.Key == "siteTitle" && val.Data != nil { 141 + brandingTitle = *val.Data 142 + } 143 + marshalledJson, err := json.Marshal(val) 144 + if err != nil { 145 + fmt.Printf("error marshalling branding asset %s: %v\n", val.Key, err) 146 + continue 147 + } 148 + metaTags = append(metaTags, MetaTag{ 149 + Type: "name", 150 + Key: "internal-brand:" + val.Key, 151 + Content: string(marshalledJson), 152 + }) 153 + } 154 + } else { 155 + // log but we should not block rendering 156 + fmt.Printf("error fetching branding assets: %v\n", err) 157 + } 158 + } 159 + 160 + // do twitter/og title after 161 + metaTags = append(metaTags, MetaTag{ 162 + Type: "property", 163 + Key: "og:title", 164 + Content: fmt.Sprintf("%s%s", titleStr, brandingTitle), 165 + }) 166 + metaTags = append(metaTags, MetaTag{ 167 + Type: "name", 168 + Key: "twitter:title", 169 + Content: fmt.Sprintf("%s%s", titleStr, brandingTitle), 170 + }) 171 172 return l.GenerateHTML(ctx, &PageConfig{ 173 + Title: fmt.Sprintf("%s%s", titleStr, brandingTitle), 174 Metas: metaTags, 175 SentryDSN: sentryDSN, 176 }) ··· 193 {Type: "property", Key: "og:url", Content: u.String()}, 194 {Type: "property", Key: "og:type", Content: "website"}, 195 {Type: "property", Key: "og:title", Content: "Stream.place"}, 196 + {Type: "property", Key: "og:description", Content: "Open-source livestreaming on the AT Protocol."}, 197 {Type: "property", Key: "og:image", Content: thumbURL.String()}, 198 199 // Twitter Meta Tags ··· 201 {Type: "property", Key: "twitter:domain", Content: u.Host}, 202 {Type: "property", Key: "twitter:url", Content: u.String()}, 203 {Type: "name", Key: "twitter:title", Content: "Stream.place"}, 204 + {Type: "name", Key: "twitter:description", Content: "Open-source livestreaming on the AT Protocol."}, 205 {Type: "name", Key: "twitter:image", Content: thumbURL.String()}, 206 } 207 208 + brandingTitle := "streamplace node" 209 + if l.sdb != nil && l.cli != nil { 210 + branding, err := l.getBrandingAssets("did:web:" + l.cli.BroadcasterHost) 211 + if err == nil { 212 + for i := range branding { 213 + val := branding[i] 214 + if val.Key == "siteTitle" && val.Data != nil { 215 + brandingTitle = *val.Data 216 + } 217 + marshalledJson, err := json.Marshal(val) 218 + if err != nil { 219 + fmt.Printf("error marshalling branding asset %s: %v\n", val.Key, err) 220 + continue 221 + } 222 + metaTags = append(metaTags, MetaTag{ 223 + Type: "name", 224 + Key: "internal-brand:" + val.Key, 225 + Content: string(marshalledJson), 226 + }) 227 + } 228 + } else { 229 + // log but we should not block rendering 230 + fmt.Printf("error fetching branding assets: %v\n", err) 231 + } 232 + } 233 + 234 + // do twitter/og title after 235 + metaTags = append(metaTags, MetaTag{ 236 + Type: "property", 237 + Key: "og:title", 238 + Content: brandingTitle, 239 + }) 240 + metaTags = append(metaTags, MetaTag{ 241 + Type: "name", 242 + Key: "twitter:title", 243 + Content: brandingTitle, 244 + }) 245 + 246 return l.GenerateHTML(ctx, &PageConfig{ 247 + Title: brandingTitle, 248 Metas: metaTags, 249 SentryDSN: sentryDSN, 250 }) ··· 327 }) 328 } 329 330 // Render the HTML to a string 331 var buf bytes.Buffer 332 if err := html.Render(&buf, root); err != nil {