Compare commits
No commits in common. "2a594e0974f3a812e679ae9ac4de08d60950fb3f" and "814694c97ee1857942365575e9e450a4217107c8" have entirely different histories.
2a594e0974
...
814694c97e
@ -29,15 +29,14 @@ Module.register('MMM-Wordpress', {
|
|||||||
const posts = this.config.posts;
|
const posts = this.config.posts;
|
||||||
const numberOfPosts = this.config.numberOfPosts;
|
const numberOfPosts = this.config.numberOfPosts;
|
||||||
|
|
||||||
//hier müssen die posts noch rein!
|
const request = require('request');
|
||||||
this.sendSocketNotification('GET_POSTS', { url, numberOfPosts });
|
|
||||||
},
|
|
||||||
|
|
||||||
socketNotificationReceived: function(notification, payload) {
|
request.get(`${url}/wp-json/wp/v2/${posts}?per_page=${numberOfPosts}`, (error, response, body) => {
|
||||||
if (notification === 'POSTS_RESULT' && payload) {
|
if (!error && response.statusCode == 200) {
|
||||||
this.posts = payload;
|
this.posts = JSON.parse(body);
|
||||||
this.updateDom();
|
this.updateDom();
|
||||||
}
|
}
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
getDom: function() {
|
getDom: function() {
|
||||||
@ -48,18 +47,15 @@ Module.register('MMM-Wordpress', {
|
|||||||
for (let i = 0; i < posts.length; i++) {
|
for (let i = 0; i < posts.length; i++) {
|
||||||
const post = posts[i];
|
const post = posts[i];
|
||||||
const postElement = document.createElement('div');
|
const postElement = document.createElement('div');
|
||||||
postElement.innerHTML = `<h2>${this.stripTags(post.title.rendered)}</h2><p>${this.stripTags(post.excerpt.rendered)}</p>`;
|
postElement.innerHTML = `<h2>${post.title.rendered}</h2><p>${post.excerpt.rendered}</p>`;
|
||||||
wrapper.appendChild(postElement);
|
wrapper.appendChild(postElement);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
wrapper.innerHTML = 'Keine Beiträge gefunden';
|
wrapper.innerHTML = 'No posts found';
|
||||||
}
|
}
|
||||||
|
|
||||||
return wrapper;
|
return wrapper;
|
||||||
},
|
|
||||||
|
|
||||||
stripTags: function(html) {
|
|
||||||
const doc = new DOMParser().parseFromString(html, 'text/html');
|
|
||||||
return doc.body.textContent || "";
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -1,22 +0,0 @@
|
|||||||
const NodeHelper = require('node_helper');
|
|
||||||
const request = require('request');
|
|
||||||
|
|
||||||
module.exports = NodeHelper.create({
|
|
||||||
start: function() {
|
|
||||||
console.log('MMM-Wordpress helper started...');
|
|
||||||
},
|
|
||||||
|
|
||||||
socketNotificationReceived: function(notification, payload) {
|
|
||||||
if (notification === 'GET_POSTS') {
|
|
||||||
const { url, numberOfPosts } = payload;
|
|
||||||
const apiUrl = `${url}/wp-json/wp/v2/posts?per_page=${numberOfPosts}`;
|
|
||||||
|
|
||||||
request.get(apiUrl, (error, response, body) => {
|
|
||||||
if (!error && response.statusCode == 200) {
|
|
||||||
const posts = JSON.parse(body);
|
|
||||||
this.sendSocketNotification('POSTS_RESULT', posts);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
Loading…
Reference in New Issue
Block a user