tiny 88x31 lexicon for atproto

add docs

+77 -78
+76 -77
handler/handler.go
··· 1 1 package handler 2 2 3 3 import ( 4 - "fmt" 5 4 "github.com/bluesky-social/indigo/atproto/auth/oauth" 6 5 "github.com/bluesky-social/indigo/atproto/identity" 7 6 "github.com/bluesky-social/indigo/atproto/syntax" ··· 189 188 "prefer to use atproto did! i don't locally store handle:did mappings, so if you use a handle, i have to resolve it on the fly, which adds latency", 190 189 "https://88x31.store/embed/liked-by?handle=moth11.net", 191 190 }, 191 + { 192 + "attribute=", 193 + "non-empty string", 194 + "any non-empty string for attribute will add a line at the bottom of the generated html linking to 88x31.store. no worries if you prefer the plain look!", 195 + "https://88x31.store/embed/liked-by?did=did:plc:25z6ogppprfvijcnqo2fsfce&attribute=yes", 196 + }, 192 197 } 193 198 194 199 err := lbreferenceT.ExecuteTemplate(w, "base.html", rd) ··· 197 202 } 198 203 } 199 204 200 - func (h *Handler) getbutton(cs *oauth.ClientSession, w http.ResponseWriter, r *http.Request) { 201 - if cs != nil { 202 - h.getbuttonauth(cs, w, r) 203 - return 204 - } 205 - uri := r.URL.Query().Get("uri") 206 - btn, err := h.db.GetButton(uri, r.Context()) 207 - if err != nil || btn == nil { 208 - http.Error(w, "not found", http.StatusNotFound) 209 - return 210 - } 211 - type ButtonData struct { 212 - DID *string 213 - Title string 214 - Button types.Button 215 - } 216 - var btnd ButtonData 217 - if btn.Alt != nil { 218 - btnd.Title = *btn.Alt 219 - } else { 220 - btnd.Title = uri 221 - } 222 - btnd.Button = *btn 223 - err = buttonT.ExecuteTemplate(w, "base.html", btnd) 224 - if err != nil { 225 - http.Error(w, "error templating", http.StatusInternalServerError) 226 - } 227 - } 228 - 229 - func (h *Handler) getbuttonauth(cs *oauth.ClientSession, w http.ResponseWriter, r *http.Request) { 230 - if cs == nil { 231 - panic("cs must be non nil when i call getbuttonauth") 232 - } 233 - did := cs.Data.AccountDID.String() 234 - uri := r.URL.Query().Get("uri") 235 - btn, err := h.db.GetButtonAuth(uri, r.Context(), did) 236 - if err != nil || btn == nil { 237 - if err != nil { 238 - log.Println(err) 239 - } 240 - http.Error(w, "not found", http.StatusNotFound) 241 - return 242 - } 243 - type ButtonData struct { 244 - DID *string 245 - Title string 246 - Button types.ButtonViewAuth 247 - } 248 - var btnd ButtonData 249 - btnd.DID = &did 250 - if btn.Alt != nil { 251 - btnd.Title = *btn.Alt 252 - } else { 253 - btnd.Title = uri 254 - } 255 - btnd.Button = *btn 256 - err = buttonT.ExecuteTemplate(w, "base.html", btnd) 257 - if err != nil { 258 - log.Println(err) 259 - http.Error(w, "error templating", http.StatusInternalServerError) 260 - } 261 - } 262 - 263 205 func (h *Handler) getuserlikes(w http.ResponseWriter, r *http.Request) { 264 206 q := r.URL.Query() 265 207 did := q.Get("did") ··· 270 212 id, err := identity.DefaultDirectory().LookupHandle(r.Context(), h) 271 213 if err == nil { 272 214 did = id.DID.String() 273 - log.Println(did) 274 - } else { 275 - log.Println(err.Error()) 276 215 } 277 - } else { 278 - log.Println(err.Error()) 279 216 } 280 217 } 281 - bg := q.Get("bg") 282 - if len(bg) == 6 { 283 - bg = fmt.Sprintf("#%s", bg) 284 - } else { 285 - bg = "white" 286 - } 287 218 cursor := q.Get("cursor") 288 219 var crsr *string 289 220 if cursor != "" { ··· 318 249 if err != nil { 319 250 marginbottom = 2 320 251 } 252 + m := q.Get("margin") 253 + margin, err := strconv.ParseFloat(m, 64) 254 + if err != nil { 255 + margin = 0 256 + } 321 257 imageRendering := q.Get("image-rendering") 322 258 switch imageRendering { 323 259 case "auto", "smooth", "crisp-edges", "high-quality": ··· 332 268 return 333 269 } 334 270 type EmbedData struct { 335 - Background string 271 + Margin float64 336 272 Buttons []types.ButtonView 337 273 Cursor *time.Time 338 274 Attribute bool ··· 345 281 MarginBottom float64 346 282 } 347 283 var ed EmbedData 348 - ed.Background = bg 284 + ed.Margin = margin 349 285 ed.Buttons = btns 350 286 ed.Cursor = ncrsr 351 287 ed.Attribute = attribute != "" ··· 357 293 ed.MarginRight = marginright 358 294 ed.MarginBottom = marginbottom 359 295 err = embedT.ExecuteTemplate(w, "embedbase.html", ed) 296 + if err != nil { 297 + log.Println(err) 298 + http.Error(w, "error templating", http.StatusInternalServerError) 299 + } 300 + } 301 + 302 + func (h *Handler) getbutton(cs *oauth.ClientSession, w http.ResponseWriter, r *http.Request) { 303 + if cs != nil { 304 + h.getbuttonauth(cs, w, r) 305 + return 306 + } 307 + uri := r.URL.Query().Get("uri") 308 + btn, err := h.db.GetButton(uri, r.Context()) 309 + if err != nil || btn == nil { 310 + http.Error(w, "not found", http.StatusNotFound) 311 + return 312 + } 313 + type ButtonData struct { 314 + DID *string 315 + Title string 316 + Button types.Button 317 + } 318 + var btnd ButtonData 319 + if btn.Alt != nil { 320 + btnd.Title = *btn.Alt 321 + } else { 322 + btnd.Title = uri 323 + } 324 + btnd.Button = *btn 325 + err = buttonT.ExecuteTemplate(w, "base.html", btnd) 326 + if err != nil { 327 + http.Error(w, "error templating", http.StatusInternalServerError) 328 + } 329 + } 330 + 331 + func (h *Handler) getbuttonauth(cs *oauth.ClientSession, w http.ResponseWriter, r *http.Request) { 332 + if cs == nil { 333 + panic("cs must be non nil when i call getbuttonauth") 334 + } 335 + did := cs.Data.AccountDID.String() 336 + uri := r.URL.Query().Get("uri") 337 + btn, err := h.db.GetButtonAuth(uri, r.Context(), did) 338 + if err != nil || btn == nil { 339 + if err != nil { 340 + log.Println(err) 341 + } 342 + http.Error(w, "not found", http.StatusNotFound) 343 + return 344 + } 345 + type ButtonData struct { 346 + DID *string 347 + Title string 348 + Button types.ButtonViewAuth 349 + } 350 + var btnd ButtonData 351 + btnd.DID = &did 352 + if btn.Alt != nil { 353 + btnd.Title = *btn.Alt 354 + } else { 355 + btnd.Title = uri 356 + } 357 + btnd.Button = *btn 358 + err = buttonT.ExecuteTemplate(w, "base.html", btnd) 360 359 if err != nil { 361 360 log.Println(err) 362 361 http.Error(w, "error templating", http.StatusInternalServerError)
+1 -1
tmpl/embedbase.html
··· 6 6 <title>88x31s</title> 7 7 <style> 8 8 body { 9 - margin: 0; 9 + margin: {{.Margin}}px; 10 10 } 11 11 img { 12 12 image-rendering: {{.ImageRendering}};