Live video on the AT Protocol

add branding to page title el

+80 -38
+80 -38
pkg/linking/linking.go
··· 106 106 return nil, errors.New("livestream view is not a livestream") 107 107 } 108 108 109 - titleStr := fmt.Sprintf("@%s's livestream on %s", lsv.Author.Handle, u.Host) 109 + titleStr := fmt.Sprintf("@%s's livestream on ", lsv.Author.Handle) 110 110 outURL := u.String() 111 - 112 - pageTitle := fmt.Sprintf("@%s | %s", lsv.Author.Handle, u.Host) 113 111 114 112 thumbURL, _ := url.Parse(u.String()) 115 113 thumbURL.Path = "/xrpc/place.stream.live.getProfileCard" ··· 123 121 // Facebook Meta Tags 124 122 {Type: "property", Key: "og:url", Content: u.String()}, 125 123 {Type: "property", Key: "og:type", Content: "website"}, 126 - {Type: "property", Key: "og:title", Content: titleStr}, 127 124 {Type: "property", Key: "og:description", Content: ls.Title}, 128 125 {Type: "property", Key: "og:image", Content: thumbURL.String()}, 129 126 ··· 131 128 {Type: "name", Key: "twitter:card", Content: "summary_large_image"}, 132 129 {Type: "property", Key: "twitter:domain", Content: u.Host}, 133 130 {Type: "property", Key: "twitter:url", Content: outURL}, 134 - {Type: "name", Key: "twitter:title", Content: titleStr}, 135 131 {Type: "name", Key: "twitter:description", Content: ls.Title}, 136 132 {Type: "name", Key: "twitter:image", Content: thumbURL.String()}, 137 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 + }) 138 171 139 172 return l.GenerateHTML(ctx, &PageConfig{ 140 - Title: pageTitle, 173 + Title: fmt.Sprintf("%s%s", titleStr, brandingTitle), 141 174 Metas: metaTags, 142 175 SentryDSN: sentryDSN, 143 176 }) ··· 160 193 {Type: "property", Key: "og:url", Content: u.String()}, 161 194 {Type: "property", Key: "og:type", Content: "website"}, 162 195 {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."}, 196 + {Type: "property", Key: "og:description", Content: "Open-source livestreaming on the AT Protocol."}, 164 197 {Type: "property", Key: "og:image", Content: thumbURL.String()}, 165 198 166 199 // Twitter Meta Tags ··· 168 201 {Type: "property", Key: "twitter:domain", Content: u.Host}, 169 202 {Type: "property", Key: "twitter:url", Content: u.String()}, 170 203 {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."}, 204 + {Type: "name", Key: "twitter:description", Content: "Open-source livestreaming on the AT Protocol."}, 172 205 {Type: "name", Key: "twitter:image", Content: thumbURL.String()}, 173 206 } 174 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 + 175 246 return l.GenerateHTML(ctx, &PageConfig{ 176 - Title: "Stream.place", 247 + Title: brandingTitle, 177 248 Metas: metaTags, 178 249 SentryDSN: sentryDSN, 179 250 }) ··· 256 327 }) 257 328 } 258 329 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 330 // Render the HTML to a string 289 331 var buf bytes.Buffer 290 332 if err := html.Render(&buf, root); err != nil {