Skip to content

Commit b192709

Browse files
Merge pull request #973 from andrea-kyurchiev/hotfix/fech-youtube-links-only-ones-per-session
fix: only fetch youtube links once
2 parents 460a69d + f92e222 commit b192709

2 files changed

Lines changed: 29 additions & 16 deletions

File tree

layouts/partials/footer.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
{{ if .Params.fetchYoutubeVideos }}
7373
<script>
7474
$('#youmax').youmax({
75-
apiKey:'AIzaSyDyTr4jpR0yAHv6y1VBiU2kvA2OZyfG2HA',
75+
apiKey:'AIzaSyAarbxeg1eOcMvxTD2Px_G3OhmDQD9N2EE',
7676
youTubeChannelURL: "https://www.youtube.com/channel/UCoSPSd6Or4F_vpjo4SmyoEA",
7777
youmaxDefaultTab: "UPLOADS",
7878
youmaxColumns: 3,

static/plugins/youmax/youmax.js

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,10 @@ var youmax_global_options = {};
7474

7575
},
7676

77-
showUploads = function(response) {
77+
showUploads = function() {
7878
$('#youmax-video-list-div').empty();
79-
79+
let response = JSON.parse(sessionStorage.getItem("youtubeResponse"));
80+
console.log(response);
8081
var nextPageToken = response.nextPageToken;
8182
var $youmaxLoadMoreDiv = $('#youmax-load-more-div');
8283
youmaxColumns = youmax_global_options.youmaxColumns;
@@ -104,19 +105,31 @@ var youmax_global_options = {};
104105
},
105106

106107
getUploads = function() {
107-
let channelId = youmax_global_options.youTubeChannelURL.split('/').pop();
108-
var apiUploadURL = "https://www.googleapis.com/youtube/v3/search?key=" + youmax_global_options.apiKey + "&channelId="+ channelId +"&part=snippet,id&order=date&maxResults=" + youmax_global_options.maxResults;
109-
110-
$.ajax({
111-
url: apiUploadURL,
112-
type: "GET",
113-
async: true,
114-
cache: true,
115-
dataType: 'jsonp',
116-
success: function(response) { showUploads(response);},
117-
error: function(html) { alert(html); },
118-
beforeSend: setHeader
119-
});
108+
let response = JSON.parse(sessionStorage.getItem("youtubeResponse"));
109+
if (!(location.hostname === "localhost" || location.hostname === "127.0.0.1")){
110+
if(!response){
111+
console.log('gonna call');
112+
let channelId = youmax_global_options.youTubeChannelURL.split('/').pop();
113+
var apiUploadURL = "https://www.googleapis.com/youtube/v3/search?key=" + youmax_global_options.apiKey + "&channelId="+ channelId +"&part=snippet,id&order=date&maxResults=" + youmax_global_options.maxResults;
114+
115+
$.ajax({
116+
url: apiUploadURL,
117+
type: "GET",
118+
async: true,
119+
cache: true,
120+
dataType: 'jsonp',
121+
success: function(response) {
122+
sessionStorage.setItem("youtubeResponse", JSON.stringify(response));
123+
showUploads(response);
124+
},
125+
error: function(html) { alert(html); },
126+
beforeSend: setHeader
127+
});
128+
} else {
129+
showUploads();
130+
}
131+
}
132+
120133
},
121134

122135
$.fn.youmax = function(options) {

0 commit comments

Comments
 (0)