diff --git a/_includes/js/notifications.js b/_includes/js/notifications.js new file mode 100644 index 0000000..630b064 --- /dev/null +++ b/_includes/js/notifications.js @@ -0,0 +1,46 @@ +(function () { + + if (typeof window.$ === "undefined") { + return; + } + + function getPrefixURL(type) { + switch(type) { + case "blog": + return "https://go.tiny.cloud/blog/"; + break; + default: + return "https://go.tiny.cloud/blog/"; + } + } + + function setResultToNewsBar(latest) { + $(".tiny-news-text").text(latest.text); + var newsLink = $(".tiny-news-link"); + newsLink.attr("href", latest.url); + newsLink.text(latest.urlText); + var prefix = $(".tiny-news-prefix"); + prefix.text("TINY " + latest.type.toUpperCase()); + prefix.attr("href", getPrefixURL(latest.type)); + } + + function fetchLatestNews() { + var url = "https://cdn.jsdelivr.net/npm/contentful@latest/dist/contentful.browser.min.js"; + $.getScript( url, function() { + var client = contentful.createClient({ + space: "sn6g75ou164i", + accessToken: "BptrxEYsjeOYo1RSx_-qF_UVkn5HDs_MeHpG1g0wJx4" + }); + client.getEntries({ + order: "-sys.createdAt", + limit: 1, + content_type: "news" + }).then(function(entries) { + setResultToNewsBar(entries.items[0].fields); + }).catch(function(err) { + console.log(err); + }); + }); + } + $(document).ready(fetchLatestNews); +})(); diff --git a/_includes/template/bodycontents.html b/_includes/template/bodycontents.html index 982c33d..751650b 100644 --- a/_includes/template/bodycontents.html +++ b/_includes/template/bodycontents.html @@ -141,6 +141,7 @@ diff --git a/_includes/template/notification.html b/_includes/template/notification.html index 0ea8ef2..23dd581 100644 --- a/_includes/template/notification.html +++ b/_includes/template/notification.html @@ -1,14 +1,15 @@