migrated to new api
This commit is contained in:
parent
09d1c94a92
commit
82276dbb8a
@ -216,4 +216,5 @@ future: true
|
|||||||
# Custom configuration
|
# Custom configuration
|
||||||
custom-config:
|
custom-config:
|
||||||
blog-services:
|
blog-services:
|
||||||
service_url: 'http://localhost:5000'
|
service_url: 'https://localhost:7013/api/v1/blog/posts'
|
||||||
|
service_key: ''
|
||||||
@ -104,19 +104,49 @@
|
|||||||
<!-- JavaScript -->
|
<!-- JavaScript -->
|
||||||
<script>
|
<script>
|
||||||
var serviceUrl = "{{site.custom-config.blog-services.service_url}}";
|
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 postId = "{{page.slug}}";
|
||||||
var remark42Host = "{{ site.comments.remark42.host }}";
|
var remark42Host = "{{ site.comments.remark42.host }}";
|
||||||
|
|
||||||
function ajax(url) {
|
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) {
|
return new Promise(function (resolve, reject) {
|
||||||
var xhr = new XMLHttpRequest();
|
var xhr = new XMLHttpRequest();
|
||||||
xhr.onload = function () {
|
xhr.onload = function () {
|
||||||
resolve(this.responseText);
|
resolve(this.responseText);
|
||||||
};
|
};
|
||||||
xhr.onerror = reject;
|
xhr.onerror = reject;
|
||||||
xhr.open('GET', url);
|
xhr.open(type, url);
|
||||||
xhr.send();
|
xhr.setRequestHeader('XApiKey', 'c6eAXYcNT873TT7BfMgQyS4ii7hxa53TLEUN7pAGaaU=');
|
||||||
|
xhr.setRequestHeader('Content-Type', 'application/json');
|
||||||
|
xhr.send(JSON.stringify(payload));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@ -24,21 +24,53 @@
|
|||||||
|
|
||||||
{% include views.html tooltip=true onload=false lang=lang %}
|
{% include views.html tooltip=true onload=false lang=lang %}
|
||||||
{% include likes.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>
|
<script>
|
||||||
const views = document.getElementById("views-count");
|
const views = document.getElementById("views-count");
|
||||||
const likes = document.getElementById("likes-count");
|
const likes = document.getElementById("likes-count");
|
||||||
|
const comments = document.getElementsByClassName("remark42__counter");
|
||||||
const postLikesAndViews = document.getElementById("likes-views");
|
const postLikesAndViews = document.getElementById("likes-views");
|
||||||
|
|
||||||
postLikesAndViews.style.display = "none";
|
postLikesAndViews.style.display = "none";
|
||||||
|
|
||||||
ajax(serviceUrl + "/GetPostLikesAndViews?siteId=" + siteId + "&postId=" + postId)
|
ajax(serviceUrl + "/GetPostLikesAndViews?blogUrl=" + siteId + "&postSlug=" + postId, "GET")
|
||||||
.then(function (result) {
|
.then(function (result) {
|
||||||
if (result != "N/A") {
|
if (result != "N/A") {
|
||||||
var response = JSON.parse(result);
|
var response = JSON.parse(result);
|
||||||
views.innerText = response.postViews;
|
setPostMetrics(response);
|
||||||
likes.innerText = response.postLikes;
|
if(!response.postExists){
|
||||||
postLikesAndViews.style.display = "inline";
|
// 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>
|
</script>
|
||||||
@ -37,7 +37,7 @@
|
|||||||
|
|
||||||
function apiCall(url, event) {
|
function apiCall(url, event) {
|
||||||
onLoadAndClick();
|
onLoadAndClick();
|
||||||
ajax(url)
|
ajax(url, "POST")
|
||||||
.then(function (result) {
|
.then(function (result) {
|
||||||
console.log(result);
|
console.log(result);
|
||||||
if (event === "click") {
|
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}}"){
|
if(likesOnLoad == "{{include.onload}}"){
|
||||||
apiCall(apiUrl);
|
apiCall(apiUrl);
|
||||||
@ -56,9 +56,9 @@
|
|||||||
|
|
||||||
heartIcon.addEventListener("click", () => {
|
heartIcon.addEventListener("click", () => {
|
||||||
if (!heartIcon.classList.contains("liked")) {
|
if (!heartIcon.classList.contains("liked")) {
|
||||||
apiUrl = serviceUrl + "/LikePost?siteId=" + siteId + "&postId=" + postId;
|
apiUrl = serviceUrl + "/LikePost?blogUrl=" + siteId + "&postSlug=" + postId;
|
||||||
} else {
|
} else {
|
||||||
apiUrl = serviceUrl + "/DislikePost?siteId=" + siteId + "&postId=" + postId;
|
apiUrl = serviceUrl + "/DislikePost?blogUrl=" + siteId + "&postSlug=" + postId;
|
||||||
}
|
}
|
||||||
|
|
||||||
apiCall(apiUrl, "click");
|
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}}"
|
<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>
|
data-bs-toggle="tooltip" data-bs-placement="bottom" {% endif %}></i>
|
||||||
<em id="views-count" style="margin-right: 12px">
|
<em id="views-count" style="margin-right: 12px"></em>
|
||||||
</em>
|
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
const viewsOnLoad = "true";
|
const viewsOnLoad = "true";
|
||||||
|
|||||||
@ -36,7 +36,7 @@ tail_includes:
|
|||||||
<!-- post counter -->
|
<!-- post counter -->
|
||||||
<div id="likes-views">
|
<div id="likes-views">
|
||||||
{% include likes-views.html tooltip=true lang=lang %}
|
{% 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>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -3,14 +3,17 @@ var siteId = document.currentScript.getAttribute('siteid');
|
|||||||
var postId = document.currentScript.getAttribute('postid');
|
var postId = document.currentScript.getAttribute('postid');
|
||||||
var remark42Host = document.currentScript.getAttribute('remark42host');
|
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) {
|
return new Promise(function (resolve, reject) {
|
||||||
var xhr = new XMLHttpRequest();
|
var xhr = new XMLHttpRequest();
|
||||||
xhr.onload = function () {
|
xhr.onload = function () {
|
||||||
resolve(this.responseText);
|
resolve(this.responseText);
|
||||||
};
|
};
|
||||||
xhr.onerror = reject;
|
xhr.onerror = reject;
|
||||||
xhr.open('GET', url);
|
xhr.open(type, url);
|
||||||
xhr.send();
|
xhr.send(payload);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user