migrated to new api
This commit is contained in:
parent
09d1c94a92
commit
82276dbb8a
@ -216,4 +216,5 @@ future: true
|
||||
# Custom configuration
|
||||
custom-config:
|
||||
blog-services:
|
||||
service_url: 'http://localhost:5000'
|
||||
service_url: 'https://localhost:7013/api/v1/blog/posts'
|
||||
service_key: ''
|
||||
@ -104,21 +104,51 @@
|
||||
<!-- JavaScript -->
|
||||
<script>
|
||||
var serviceUrl = "{{site.custom-config.blog-services.service_url}}";
|
||||
var siteId = "{{site.id}}";
|
||||
var serviceApiKey = "{{site.custom-config.blog-services.service_key}}"
|
||||
var siteId = "{{site.url}}{{site.baseurl}}";
|
||||
var postId = "{{page.slug}}";
|
||||
var remark42Host = "{{ site.comments.remark42.host }}";
|
||||
|
||||
function ajax(url) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.onload = function () {
|
||||
resolve(this.responseText);
|
||||
};
|
||||
xhr.onerror = reject;
|
||||
xhr.open('GET', url);
|
||||
xhr.send();
|
||||
});
|
||||
var postDetails = {
|
||||
postUrl: "{{site.url}}{{site.baseurl}}{{page.url}}",
|
||||
slug: "{{page.slug}}",
|
||||
title: "{{page.title}}",
|
||||
description: "{{page.description}}",
|
||||
categories: [],
|
||||
image: "{{page.image.path}}",
|
||||
createdDate: "{{page.date}}",
|
||||
modifiedDate: "{{page.last_modified_at | strip}}",
|
||||
blogUrl: "{{site.url}}{{site.baseurl}}"
|
||||
};
|
||||
|
||||
function liquidArrayToJsonArray(){
|
||||
var items = [];
|
||||
{% for category in page.categories %}
|
||||
{% assign cat = category %}
|
||||
items.push("{{cat}}");
|
||||
{% endfor %}
|
||||
console.log(items);
|
||||
return items;
|
||||
}
|
||||
|
||||
postDetails.categories = liquidArrayToJsonArray();
|
||||
|
||||
function ajax(url, type, payload) {
|
||||
if (payload === undefined) {
|
||||
payload = null;
|
||||
}
|
||||
return new Promise(function (resolve, reject) {
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.onload = function () {
|
||||
resolve(this.responseText);
|
||||
};
|
||||
xhr.onerror = reject;
|
||||
xhr.open(type, url);
|
||||
xhr.setRequestHeader('XApiKey', 'c6eAXYcNT873TT7BfMgQyS4ii7hxa53TLEUN7pAGaaU=');
|
||||
xhr.setRequestHeader('Content-Type', 'application/json');
|
||||
xhr.send(JSON.stringify(payload));
|
||||
});
|
||||
}
|
||||
</script>
|
||||
{% if jekyll.environment == 'production' and site.google_analytics.id != empty and site.google_analytics.id %}
|
||||
<!-- Google Tag Manager -->
|
||||
|
||||
@ -24,21 +24,53 @@
|
||||
|
||||
{% include views.html tooltip=true onload=false lang=lang %}
|
||||
{% include likes.html tooltip=true onload=false lang=lang %}
|
||||
{% include comments-counter.html tooltip=true lang=lang %}
|
||||
|
||||
<script>
|
||||
const views = document.getElementById("views-count");
|
||||
const likes = document.getElementById("likes-count");
|
||||
const comments = document.getElementsByClassName("remark42__counter");
|
||||
const postLikesAndViews = document.getElementById("likes-views");
|
||||
|
||||
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){
|
||||
// ajax(serviceUrl + "/CreatePost", "GET", page)
|
||||
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);
|
||||
}
|
||||
if(Number(comments.innerText) !== NaN){
|
||||
postDetails.comments = Number(comments.innerText);
|
||||
}
|
||||
console.log(postDetails);
|
||||
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;
|
||||
if(Number(comments.innerText) !== NaN){
|
||||
comments.innerText = response.comments;
|
||||
}
|
||||
postLikesAndViews.style.display = "inline";
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@ -37,7 +37,7 @@
|
||||
|
||||
function apiCall(url, event) {
|
||||
onLoadAndClick();
|
||||
ajax(url)
|
||||
ajax(url, "POST")
|
||||
.then(function (result) {
|
||||
console.log(result);
|
||||
if (event === "click") {
|
||||
@ -48,7 +48,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 +56,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");
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
<i class="fa fa-eye fa-fw" aria-hidden="true" {% if include.tooltip %} title="{{site.data.locales[include.lang].post.views}}"
|
||||
data-bs-toggle="tooltip" data-bs-placement="bottom" {% endif %}></i>
|
||||
<em id="views-count" style="margin-right: 12px">
|
||||
</em>
|
||||
<em id="views-count" style="margin-right: 12px"></em>
|
||||
|
||||
<script>
|
||||
const viewsOnLoad = "true";
|
||||
|
||||
@ -36,7 +36,7 @@ tail_includes:
|
||||
<!-- post counter -->
|
||||
<div id="likes-views">
|
||||
{% include likes-views.html tooltip=true lang=lang %}
|
||||
{% include comments-counter.html tooltip=true lang=lang %}
|
||||
<!-- {% include comments-counter.html tooltip=true lang=lang %} -->
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
@ -3,14 +3,17 @@ var siteId = document.currentScript.getAttribute('siteid');
|
||||
var postId = document.currentScript.getAttribute('postid');
|
||||
var remark42Host = document.currentScript.getAttribute('remark42host');
|
||||
|
||||
function ajax(url) {
|
||||
function ajax(url, type, payload) {
|
||||
if (payload === undefined) {
|
||||
payload = null;
|
||||
}
|
||||
return new Promise(function (resolve, reject) {
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.onload = function () {
|
||||
resolve(this.responseText);
|
||||
};
|
||||
xhr.onerror = reject;
|
||||
xhr.open('GET', url);
|
||||
xhr.send();
|
||||
xhr.open(type, url);
|
||||
xhr.send(payload);
|
||||
});
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user