tiny 88x31 lexicon for atproto

add better docs

+76
+34
handler/handler.go
··· 37 37 var logoutT = template.Must(template.ParseFiles("./tmpl/base.html", "./tmpl/logout.html")) 38 38 var uploadT = template.Must(template.ParseFiles("./tmpl/base.html", "./tmpl/upload.html")) 39 39 var referenceT = template.Must(template.ParseFiles("./tmpl/base.html", "./tmpl/reference.html")) 40 + var lbreferenceT = template.Must(template.ParseFiles("./tmpl/partial/iframe.html", "./tmpl/partial/apidoc.html", "./tmpl/base.html", "./tmpl/lbreference.html")) 40 41 var embedT = template.Must(template.ParseFiles("./tmpl/partial/embedbuttonpart.html", "./tmpl/embedbase.html", "./tmpl/embedcollection.html")) 41 42 42 43 func MakeHandler(db *db.Store, oauth *myoauth.Service) *Handler { ··· 45 46 h := &Handler{db: db, router: mux, oauth: oauth, sessionStore: sessionStore} 46 47 mux.HandleFunc("GET /", h.oauthMiddleware(h.gethome)) 47 48 mux.HandleFunc("GET /reference", h.oauthMiddleware(h.getreference)) 49 + mux.HandleFunc("GET /embed/liked-by/reference", h.oauthMiddleware(h.getlbreference)) 48 50 mux.HandleFunc("GET /login", h.oauthMiddleware(getlogin)) 49 51 mux.HandleFunc("POST /login", h.login) 50 52 mux.HandleFunc("GET /logout", h.oauthMiddleware(getlogout)) ··· 149 151 rd.Title = "reference" 150 152 151 153 err := referenceT.ExecuteTemplate(w, "base.html", rd) 154 + if err != nil { 155 + http.Error(w, err.Error(), http.StatusInternalServerError) 156 + } 157 + } 158 + 159 + func (h *Handler) getlbreference(cs *oauth.ClientSession, w http.ResponseWriter, r *http.Request) { 160 + type Apidoc struct { 161 + Fragment string 162 + Accepts string 163 + Notes string 164 + HREF string 165 + } 166 + type ReferenceData struct { 167 + DID *string 168 + Title string 169 + Docs []Apidoc 170 + } 171 + var rd ReferenceData 172 + if cs != nil { 173 + did := cs.Data.AccountDID.String() 174 + rd.DID = &did 175 + } 176 + rd.Title = "reference" 177 + rd.Docs = []Apidoc{ 178 + {"did=", 179 + "atproto did as string", 180 + "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", 181 + "https://88x31.store/embed/liked-by?did=did:plc:25z6ogppprfvijcnqo2fsfce", 182 + }, 183 + } 184 + 185 + err := lbreferenceT.ExecuteTemplate(w, "base.html", rd) 152 186 if err != nil { 153 187 http.Error(w, err.Error(), http.StatusInternalServerError) 154 188 }
+8
tmpl/lbreference.html
··· 1 + {{define "content"}} 2 + <h2> 3 + /embed/liked-by reference 4 + </h2> 5 + {{range .Docs}} 6 + {{apidoc .}} 7 + {{end}} 8 + {{end}}
+19
tmpl/partial/apidoc.html
··· 1 + {{define "apidoc"}} 2 + <h3> 3 + {{.Fragment}} 4 + </h3> 5 + <h4> 6 + accepts 7 + </h4> 8 + <p> 9 + {{.Accepts}} 10 + </p> 11 + <h4> 12 + notes 13 + </h4> 14 + <p> 15 + {{.Notes}} 16 + </p> 17 + {{iframe .}} 18 + <hr> 19 + {{end}}
+15
tmpl/partial/iframe.html
··· 1 + {{define "iframe"}} 2 + <h4> 3 + example HTML 4 + </h4> 5 + <div> 6 + <code> 7 + &lt;iframe src="<a href="{{.HREF}}">{{.HREF}}</a>"&gt;&lt;/iframe&gt; 8 + </code> 9 + </div> 10 + <h4> 11 + example output 12 + </h4> 13 + <iframe src="{{.HREF}}"> 14 + </iframe> 15 + {{end}}