Skip to content

Commit

Permalink
Allison memorial page, first cut
Browse files Browse the repository at this point in the history
  • Loading branch information
ianrose14 committed Oct 12, 2024
1 parent 3ab24f3 commit d22b373
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 25 deletions.
47 changes: 43 additions & 4 deletions cmd/webapp/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"fmt"
"html/template"
"io"
"io/ioutil"
"log"
"net/http"
"net/url"
Expand All @@ -17,11 +16,13 @@ import (
)

const (
AlbumsConfigUrl = "https://www.dropbox.com/s/kr8ewc68husts57/albums.json?dl=1"
AlbumsConfigUrl = "https://www.dropbox.com/s/kr8ewc68husts57/albums.json?dl=1"
AllisonConfigUrl = "https://www.dropbox.com/scl/fi/6yalddhnyuo2sld7y845e/web-config.json?rlkey=q1c1lztc1tsz8vhy8xwvqdtl9&st=khjv2q6e&dl=1"
)

var (
albumsTemplate = template.Must(template.ParseFS(templatesFS, "templates/albums.html"))
albumsTemplate = template.Must(template.ParseFS(templatesFS, "templates/albums.html"))
allisonTemplate = template.Must(template.ParseFS(templatesFS, "templates/allison.html"))
)

type album struct {
Expand All @@ -31,6 +32,16 @@ type album struct {
CoverUrl string
}

type webItem struct {
Desc string `json:"desc"`
Url string `json:"url"`
}

type webSection struct {
Name string `json:"name"`
Items []*webItem `json:"items"`
}

// albumsHandler serves a page that lists all available photo albums.
func (svr *server) albumsHandler(w http.ResponseWriter, _ *http.Request) {
rsp, err := http.Get(AlbumsConfigUrl)
Expand Down Expand Up @@ -64,6 +75,34 @@ func (svr *server) albumsHandler(w http.ResponseWriter, _ *http.Request) {
}
}

func (svr *server) allisonHandler(w http.ResponseWriter, _ *http.Request) {
rsp, err := http.Get(AllisonConfigUrl)
if err != nil {
internal.HttpError(w, http.StatusInternalServerError, "failed to fetch web config file from dropbox: %s", err)
return
}
defer internal.DrainAndClose(rsp.Body)

if err := internal.CheckResponse(rsp); err != nil {
internal.HttpError(w, http.StatusInternalServerError, "failed to fetch web config file from dropbox: %s", err)
return
}

var results struct {
Sections []*webSection `json:"sections"`
}

if err := json.NewDecoder(rsp.Body).Decode(&results); err != nil {
internal.HttpError(w, http.StatusInternalServerError, "failed to json-decode response: %s", err)
return
}

if err := allisonTemplate.Execute(w, results.Sections); err != nil {
internal.HttpError(w, http.StatusInternalServerError, "failed to render template: %s", err)
return
}
}

func (svr *server) dumpHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/plain")

Expand Down Expand Up @@ -93,7 +132,7 @@ func (svr *server) dumpHandler(w http.ResponseWriter, r *http.Request) {
writeIt("%s", buf.String())
fmt.Fprintln(w, "") // write blank line to response body

b, err := ioutil.ReadAll(r.Body)
b, err := io.ReadAll(r.Body)
if err != nil {
writeIt("error: failed to read body: %s", err)
} else {
Expand Down
1 change: 1 addition & 0 deletions cmd/webapp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ func main() {

mux.HandleFunc("/albums/", svr.albumsHandler)
mux.HandleFunc("/albums/thumbnail/", svr.thumbnailHandler)
mux.HandleFunc("/allison", svr.allisonHandler)
mux.HandleFunc("/dump/", svr.dumpHandler)

stravaDb := strava.NewSqliteDb(db)
Expand Down
33 changes: 22 additions & 11 deletions cmd/webapp/templates/albums.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,28 @@
<head>
<link type="text/css" href="/css/albums.css" rel="stylesheet" media="screen">

<script type="text/javascript">
var _fs_debug = false;
var _fs_host='staging.fullstory.com',_fs_org='ianthomasrose.com';
(function(m,n,e,t,l,o,g,y){
g=m[e]=function(a,b){g.q?g.q.push([a,b]):g._api(a,b);};g.q=[];
o=n.createElement(t);o.async=1;o.src='https://'+_fs_host+'/s/fs.js';
y=n.getElementsByTagName(t)[0];y.parentNode.insertBefore(o,y);
g.identify=function(i,v){g(l,{uid:i});if(v)g(l,v)};g.setUserVars=function(v){FS(l,v)};
g.setSessionVars=function(v){FS('session',v)};g.setPageVars=function(v){FS('page',v)};
})(window,document,'FS','script','user');
</script>
<script>
window['_fs_host'] = 'fullstory.com';
window['_fs_script'] = 'edge.fullstory.com/s/fs.js';
window['_fs_org'] = 'o-19T7VB-na1';
window['_fs_namespace'] = 'FS';
!function(m,n,e,t,l,o,g,y){var s,f,a=function(h){
return!(h in m)||(m.console&&m.console.log&&m.console.log('FullStory namespace conflict. Please set window["_fs_namespace"].'),!1)}(e)
;function p(b){var h,d=[];function j(){h&&(d.forEach((function(b){var d;try{d=b[h[0]]&&b[h[0]](h[1])}catch(h){return void(b[3]&&b[3](h))}
d&&d.then?d.then(b[2],b[3]):b[2]&&b[2](d)})),d.length=0)}function r(b){return function(d){h||(h=[b,d],j())}}return b(r(0),r(1)),{
then:function(b,h){return p((function(r,i){d.push([b,h,r,i]),j()}))}}}a&&(g=m[e]=function(){var b=function(b,d,j,r){function i(i,c){
h(b,d,j,i,c,r)}r=r||2;var c,u=/Async$/;return u.test(b)?(b=b.replace(u,""),"function"==typeof Promise?new Promise(i):p(i)):h(b,d,j,c,c,r)}
;function h(h,d,j,r,i,c){return b._api?b._api(h,d,j,r,i,c):(b.q&&b.q.push([h,d,j,r,i,c]),null)}return b.q=[],b}(),y=function(b){function h(h){
"function"==typeof h[4]&&h[4](new Error(b))}var d=g.q;if(d){for(var j=0;j<d.length;j++)h(d[j]);d.length=0,d.push=h}},function(){
(o=n.createElement(t)).async=!0,o.crossOrigin="anonymous",o.src="https://"+l,o.onerror=function(){y("Error loading "+l)}
;var b=n.getElementsByTagName(t)[0];b&&b.parentNode?b.parentNode.insertBefore(o,b):n.head.appendChild(o)}(),function(){function b(){}
function h(b,h,d){g(b,h,d,1)}function d(b,d,j){h("setProperties",{type:b,properties:d},j)}function j(b,h){d("user",b,h)}function r(b,h,d){j({
uid:b},d),h&&j(h,d)}g.identify=r,g.setUserVars=j,g.identifyAccount=b,g.clearUserCookie=b,g.setVars=d,g.event=function(b,d,j){h("trackEvent",{
name:b,properties:d},j)},g.anonymize=function(){r(!1)},g.shutdown=function(){h("shutdown")},g.restart=function(){h("restart")},
g.log=function(b,d){h("log",{level:b,msg:d})},g.consent=function(b){h("setIdentity",{consent:!arguments.length||b})}}(),s="fetch",
f="XMLHttpRequest",g._w={},g._w[f]=m[f],g._w[s]=m[s],m[s]&&(m[s]=function(){return g._w[s].apply(this,arguments)}),g._v="2.0.0")
}(window,document,window._fs_namespace,"script",window._fs_script);
</script>
</head>
<body>
<div class="main-wrapper">
Expand Down
43 changes: 43 additions & 0 deletions cmd/webapp/templates/allison.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<!DOCTYPE html>
<head>
<link type="text/css" href="/css/albums.css" rel="stylesheet" media="screen">

<script>
window['_fs_host'] = 'fullstory.com';
window['_fs_script'] = 'edge.fullstory.com/s/fs.js';
window['_fs_org'] = 'o-19T7VB-na1';
window['_fs_namespace'] = 'FS';
!function(m,n,e,t,l,o,g,y){var s,f,a=function(h){
return!(h in m)||(m.console&&m.console.log&&m.console.log('FullStory namespace conflict. Please set window["_fs_namespace"].'),!1)}(e)
;function p(b){var h,d=[];function j(){h&&(d.forEach((function(b){var d;try{d=b[h[0]]&&b[h[0]](h[1])}catch(h){return void(b[3]&&b[3](h))}
d&&d.then?d.then(b[2],b[3]):b[2]&&b[2](d)})),d.length=0)}function r(b){return function(d){h||(h=[b,d],j())}}return b(r(0),r(1)),{
then:function(b,h){return p((function(r,i){d.push([b,h,r,i]),j()}))}}}a&&(g=m[e]=function(){var b=function(b,d,j,r){function i(i,c){
h(b,d,j,i,c,r)}r=r||2;var c,u=/Async$/;return u.test(b)?(b=b.replace(u,""),"function"==typeof Promise?new Promise(i):p(i)):h(b,d,j,c,c,r)}
;function h(h,d,j,r,i,c){return b._api?b._api(h,d,j,r,i,c):(b.q&&b.q.push([h,d,j,r,i,c]),null)}return b.q=[],b}(),y=function(b){function h(h){
"function"==typeof h[4]&&h[4](new Error(b))}var d=g.q;if(d){for(var j=0;j<d.length;j++)h(d[j]);d.length=0,d.push=h}},function(){
(o=n.createElement(t)).async=!0,o.crossOrigin="anonymous",o.src="https://"+l,o.onerror=function(){y("Error loading "+l)}
;var b=n.getElementsByTagName(t)[0];b&&b.parentNode?b.parentNode.insertBefore(o,b):n.head.appendChild(o)}(),function(){function b(){}
function h(b,h,d){g(b,h,d,1)}function d(b,d,j){h("setProperties",{type:b,properties:d},j)}function j(b,h){d("user",b,h)}function r(b,h,d){j({
uid:b},d),h&&j(h,d)}g.identify=r,g.setUserVars=j,g.identifyAccount=b,g.clearUserCookie=b,g.setVars=d,g.event=function(b,d,j){h("trackEvent",{
name:b,properties:d},j)},g.anonymize=function(){r(!1)},g.shutdown=function(){h("shutdown")},g.restart=function(){h("restart")},
g.log=function(b,d){h("log",{level:b,msg:d})},g.consent=function(b){h("setIdentity",{consent:!arguments.length||b})}}(),s="fetch",
f="XMLHttpRequest",g._w={},g._w[f]=m[f],g._w[s]=m[s],m[s]&&(m[s]=function(){return g._w[s].apply(this,arguments)}),g._v="2.0.0")
}(window,document,window._fs_namespace,"script",window._fs_script);
</script>
</head>
<body>
<div class="main-wrapper">
<div class="title">Memories &amp; Celebration of Allison Rose</div>
<div>
{{ range . }}
<h3>{{.Name}}</h3>
<ul>
{{ range .Items }}
<li><a href="{{.Url}}" target="_blank">{{ .Desc }}</a></li>
{{ end }}
</ul>
{{ end }}
</div>
</div>
</body>
</html>
31 changes: 21 additions & 10 deletions cmd/webapp/templates/strava.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,27 @@
<link type="text/css" href="/css/strava.css" rel="stylesheet" media="screen">
<meta name="viewport" content="width=400, initial-scale=1">

<script type="text/javascript">
let _fs_debug = false;
let _fs_host='staging.fullstory.com',_fs_org='ianthomasrose.com';
(function(m,n,e,t,l,o,g,y){
g=m[e]=function(a,b){g.q?g.q.push([a,b]):g._api(a,b);};g.q=[];
o=n.createElement(t);o.async=1;o.src='https://'+_fs_host+'/s/fs.js';
y=n.getElementsByTagName(t)[0];y.parentNode.insertBefore(o,y);
g.identify=function(i,v){g(l,{uid:i});if(v)g(l,v)};g.setUserVars=function(v){FS(l,v)};
g.setSessionVars=function(v){FS('session',v)};g.setPageVars=function(v){FS('page',v)};
})(window,document,'FS','script','user');
<script>
window['_fs_host'] = 'fullstory.com';
window['_fs_script'] = 'edge.fullstory.com/s/fs.js';
window['_fs_org'] = 'o-19T7VB-na1';
window['_fs_namespace'] = 'FS';
!function(m,n,e,t,l,o,g,y){var s,f,a=function(h){
return!(h in m)||(m.console&&m.console.log&&m.console.log('FullStory namespace conflict. Please set window["_fs_namespace"].'),!1)}(e)
;function p(b){var h,d=[];function j(){h&&(d.forEach((function(b){var d;try{d=b[h[0]]&&b[h[0]](h[1])}catch(h){return void(b[3]&&b[3](h))}
d&&d.then?d.then(b[2],b[3]):b[2]&&b[2](d)})),d.length=0)}function r(b){return function(d){h||(h=[b,d],j())}}return b(r(0),r(1)),{
then:function(b,h){return p((function(r,i){d.push([b,h,r,i]),j()}))}}}a&&(g=m[e]=function(){var b=function(b,d,j,r){function i(i,c){
h(b,d,j,i,c,r)}r=r||2;var c,u=/Async$/;return u.test(b)?(b=b.replace(u,""),"function"==typeof Promise?new Promise(i):p(i)):h(b,d,j,c,c,r)}
;function h(h,d,j,r,i,c){return b._api?b._api(h,d,j,r,i,c):(b.q&&b.q.push([h,d,j,r,i,c]),null)}return b.q=[],b}(),y=function(b){function h(h){
"function"==typeof h[4]&&h[4](new Error(b))}var d=g.q;if(d){for(var j=0;j<d.length;j++)h(d[j]);d.length=0,d.push=h}},function(){
(o=n.createElement(t)).async=!0,o.crossOrigin="anonymous",o.src="https://"+l,o.onerror=function(){y("Error loading "+l)}
;var b=n.getElementsByTagName(t)[0];b&&b.parentNode?b.parentNode.insertBefore(o,b):n.head.appendChild(o)}(),function(){function b(){}
function h(b,h,d){g(b,h,d,1)}function d(b,d,j){h("setProperties",{type:b,properties:d},j)}function j(b,h){d("user",b,h)}function r(b,h,d){j({
uid:b},d),h&&j(h,d)}g.identify=r,g.setUserVars=j,g.identifyAccount=b,g.clearUserCookie=b,g.setVars=d,g.event=function(b,d,j){h("trackEvent",{
name:b,properties:d},j)},g.anonymize=function(){r(!1)},g.shutdown=function(){h("shutdown")},g.restart=function(){h("restart")},
g.log=function(b,d){h("log",{level:b,msg:d})},g.consent=function(b){h("setIdentity",{consent:!arguments.length||b})}}(),s="fetch",
f="XMLHttpRequest",g._w={},g._w[f]=m[f],g._w[s]=m[s],m[s]&&(m[s]=function(){return g._w[s].apply(this,arguments)}),g._v="2.0.0")
}(window,document,window._fs_namespace,"script",window._fs_script);
</script>
</head>
<body>
Expand Down

0 comments on commit d22b373

Please sign in to comment.