Add og meta tags to starter pack detail (#4585)
* add og meta tags to starter pack detail * tidy * bskyweb: add starter pack title to og meta * bskyweb build * go version to 1.22 * tidy
This commit is contained in:
parent
6cda641250
commit
682f31ec9d
8 changed files with 137 additions and 68 deletions
|
@ -40,6 +40,12 @@ func run(args []string) {
|
|||
// retain old PDS env var for easy transition
|
||||
EnvVars: []string{"ATP_APPVIEW_HOST", "ATP_PDS_HOST"},
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "ogcard-host",
|
||||
Usage: "scheme, hostname, and port of ogcard service",
|
||||
Required: false,
|
||||
EnvVars: []string{"OGCARD_HOST"},
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "http-address",
|
||||
Usage: "Specify the local IP/port to bind to",
|
||||
|
|
|
@ -31,12 +31,22 @@ type Server struct {
|
|||
echo *echo.Echo
|
||||
httpd *http.Server
|
||||
xrpcc *xrpc.Client
|
||||
cfg *Config
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
debug bool
|
||||
httpAddress string
|
||||
appviewHost string
|
||||
ogcardHost string
|
||||
linkHost string
|
||||
}
|
||||
|
||||
func serve(cctx *cli.Context) error {
|
||||
debug := cctx.Bool("debug")
|
||||
httpAddress := cctx.String("http-address")
|
||||
appviewHost := cctx.String("appview-host")
|
||||
ogcardHost := cctx.String("ogcard-host")
|
||||
linkHost := cctx.String("link-host")
|
||||
|
||||
// Echo
|
||||
|
@ -73,6 +83,13 @@ func serve(cctx *cli.Context) error {
|
|||
server := &Server{
|
||||
echo: e,
|
||||
xrpcc: xrpcc,
|
||||
cfg: &Config{
|
||||
debug: debug,
|
||||
httpAddress: httpAddress,
|
||||
appviewHost: appviewHost,
|
||||
ogcardHost: ogcardHost,
|
||||
linkHost: linkHost,
|
||||
},
|
||||
}
|
||||
|
||||
// Create the HTTP server.
|
||||
|
@ -223,9 +240,9 @@ func serve(cctx *cli.Context) error {
|
|||
e.GET("/profile/:handleOrDID/post/:rkey/liked-by", server.WebGeneric)
|
||||
e.GET("/profile/:handleOrDID/post/:rkey/reposted-by", server.WebGeneric)
|
||||
|
||||
// starter packs
|
||||
e.GET("/starter-pack/:handleOrDID/:rkey", server.WebGeneric)
|
||||
e.GET("/start/:handleOrDID/:rkey", server.WebGeneric)
|
||||
// starter packs
|
||||
e.GET("/starter-pack/:handleOrDID/:rkey", server.WebStarterPack)
|
||||
e.GET("/start/:handleOrDID/:rkey", server.WebStarterPack)
|
||||
|
||||
if linkHost != "" {
|
||||
linkUrl, err := url.Parse(linkHost)
|
||||
|
@ -415,6 +432,45 @@ func (srv *Server) WebPost(c echo.Context) error {
|
|||
return c.Render(http.StatusOK, "post.html", data)
|
||||
}
|
||||
|
||||
func (srv *Server) WebStarterPack(c echo.Context) error {
|
||||
req := c.Request()
|
||||
ctx := req.Context()
|
||||
data := pongo2.Context{}
|
||||
data["requestURI"] = fmt.Sprintf("https://%s%s", req.Host, req.URL.Path)
|
||||
// sanity check arguments. don't 4xx, just let app handle if not expected format
|
||||
rkeyParam := c.Param("rkey")
|
||||
rkey, err := syntax.ParseRecordKey(rkeyParam)
|
||||
if err != nil {
|
||||
log.Errorf("bad rkey: %v", err)
|
||||
return c.Render(http.StatusOK, "starterpack.html", data)
|
||||
}
|
||||
handleOrDIDParam := c.Param("handleOrDID")
|
||||
handleOrDID, err := syntax.ParseAtIdentifier(handleOrDIDParam)
|
||||
if err != nil {
|
||||
log.Errorf("bad identifier: %v", err)
|
||||
return c.Render(http.StatusOK, "starterpack.html", data)
|
||||
}
|
||||
identifier := handleOrDID.Normalize().String()
|
||||
starterPackURI := fmt.Sprintf("at://%s/app.bsky.graph.starterpack/%s", identifier, rkey)
|
||||
spv, err := appbsky.GraphGetStarterPack(ctx, srv.xrpcc, starterPackURI)
|
||||
if err != nil {
|
||||
log.Errorf("failed to fetch starter pack view for: %s\t%v", starterPackURI, err)
|
||||
return c.Render(http.StatusOK, "starterpack.html", data)
|
||||
}
|
||||
if spv.StarterPack == nil || spv.StarterPack.Record == nil {
|
||||
return c.Render(http.StatusOK, "starterpack.html", data)
|
||||
}
|
||||
rec, ok := spv.StarterPack.Record.Val.(*appbsky.GraphStarterpack)
|
||||
if !ok {
|
||||
return c.Render(http.StatusOK, "starterpack.html", data)
|
||||
}
|
||||
data["title"] = rec.Name
|
||||
if srv.cfg.ogcardHost != "" {
|
||||
data["imgThumbUrl"] = fmt.Sprintf("%s/start/%s/%s", srv.cfg.ogcardHost, identifier, rkey)
|
||||
}
|
||||
return c.Render(http.StatusOK, "starterpack.html", data)
|
||||
}
|
||||
|
||||
func (srv *Server) WebProfile(c echo.Context) error {
|
||||
ctx := c.Request().Context()
|
||||
data := pongo2.Context{}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue