diff --git a/_config.yml b/_config.yml index 29d9bb2..f1a7c26 100644 --- a/_config.yml +++ b/_config.yml @@ -125,6 +125,7 @@ pwa: # Usually its value is the `baseurl` of another website that # shares the same domain name as the current website. deny_paths: + - "/api" # - "/example" # URLs match `/example/*` will not be cached by the PWA paginate: 10 @@ -216,4 +217,5 @@ future: true # Custom configuration custom-config: blog-services: - service_url: 'http://localhost:5000' \ No newline at end of file + service_url: 'https://localhost:7013/blog/api/v1/blog/posts' + service_key: 'c6eAXYcNT873TT7BfMgQyS4ii7hxa53TLEUN7pAGaaU=' \ No newline at end of file diff --git a/_includes/comments-counter.html b/_includes/comments-counter.html index d56f5f7..a54d833 100644 --- a/_includes/comments-counter.html +++ b/_includes/comments-counter.html @@ -4,6 +4,30 @@ } - - \ No newline at end of file + + + + \ No newline at end of file diff --git a/_includes/comments/remark42.html b/_includes/comments/remark42.html index 78f1786..74cb4b5 100644 --- a/_includes/comments/remark42.html +++ b/_includes/comments/remark42.html @@ -4,7 +4,7 @@ {% if jekyll.environment == 'production' and site.google_analytics.id != empty and site.google_analytics.id %} diff --git a/_includes/likes-views.html b/_includes/likes-views.html index 1aef965..336310a 100644 --- a/_includes/likes-views.html +++ b/_includes/likes-views.html @@ -29,16 +29,40 @@ const views = document.getElementById("views-count"); const likes = document.getElementById("likes-count"); const postLikesAndViews = document.getElementById("likes-views"); + var commentsCountFromResponse = 0; postLikesAndViews.style.display = "none"; - ajax(serviceUrl + "/GetPostLikesAndViews?siteId=" + siteId + "&postId=" + postId) + ajax(serviceUrl + "/GetPostLikesAndViews?blogUrl=" + siteId + "&postSlug=" + postId, "GET") .then(function (result) { if (result != "N/A") { var response = JSON.parse(result); - views.innerText = response.postViews; - likes.innerText = response.postLikes; - postLikesAndViews.style.display = "inline"; + setPostMetrics(response); + if(!response.postExists){ + postDetails.likes = postDetails.views = postDetails.comments = 0; + if(Number(likes.innerText) !== NaN){ + postDetails.likes = Number(likes.innerText); + } + if(Number(views.innerText) !== NaN){ + postDetails.views = Number(views.innerText); + } + ajax(serviceUrl + "/CreatePost", "POST", postDetails) + .then(function (result) { + if(result != "N/A"){ + var response = JSON.parse(result); + setPostMetrics(response); + } + }); + } } }); + + function setPostMetrics(response){ + if(response.postExists){ + views.innerText = response.views; + likes.innerText = response.likes; + commentsCountFromResponse = response.comments; + postLikesAndViews.style.display = "inline"; + } + } \ No newline at end of file diff --git a/_includes/likes.html b/_includes/likes.html index 41239d5..1c952d7 100644 --- a/_includes/likes.html +++ b/_includes/likes.html @@ -37,9 +37,8 @@ function apiCall(url, event) { onLoadAndClick(); - ajax(url) + ajax(url, "POST") .then(function (result) { - console.log(result); if (event === "click") { heartIcon.classList.toggle("liked"); } @@ -48,7 +47,7 @@ }); } - var apiUrl = serviceUrl + "/GetPostLikes?siteId=" + siteId + "&postId=" + postId; + var apiUrl = serviceUrl + "/GetPostLikes?blogUrl=" + siteId + "&postSlug=" + postId; if(likesOnLoad == "{{include.onload}}"){ apiCall(apiUrl); @@ -56,9 +55,9 @@ heartIcon.addEventListener("click", () => { if (!heartIcon.classList.contains("liked")) { - apiUrl = serviceUrl + "/LikePost?siteId=" + siteId + "&postId=" + postId; + apiUrl = serviceUrl + "/LikePost?blogUrl=" + siteId + "&postSlug=" + postId; } else { - apiUrl = serviceUrl + "/DislikePost?siteId=" + siteId + "&postId=" + postId; + apiUrl = serviceUrl + "/DislikePost?blogUrl=" + siteId + "&postSlug=" + postId; } apiCall(apiUrl, "click"); diff --git a/_includes/views.html b/_includes/views.html index 149c239..5d537d5 100644 --- a/_includes/views.html +++ b/_includes/views.html @@ -1,7 +1,6 @@ - - +