Compare commits

..

6 Commits

Author SHA1 Message Date
f515b9d969 excerpt -> content 2023-10-09 19:31:05 +02:00
f22e8199e4 adjustable post_type 2023-10-09 19:21:54 +02:00
85ff4c0c6c Docu update 2023-10-09 18:54:06 +02:00
d6f93f2f42 require entfernt 2023-10-09 18:44:51 +02:00
5d4d318a50 helper moved 2023-10-09 18:41:32 +02:00
b2166a8425 debugging messages 2023-10-09 18:33:43 +02:00
3 changed files with 31 additions and 6 deletions

View File

@ -7,13 +7,12 @@
* MIT Licensed. * MIT Licensed.
*/ */
Module.register('MMM-Wordpress', { Module.register('MMM-Wordpress', {
defaults: { defaults: {
updateInterval: 600000, // 10 minutes updateInterval: 600000, // 10 minutes
url: 'YOUR_WORDPRESS_API_URL', // replace with your WordPress API endpoint url: 'YOUR_WORDPRESS_API_URL', // replace with your WordPress API endpoint
numberOfPosts: 5, // number of posts to display numberOfPosts: 5, // number of posts to display
posts: 'posts', //Endpoint ("posts" for normal posts, can be changed to custom post type) posts: 'posts', //Endpoint ("posts" for normal posts, can be changed to custom post type)
}, },
start: function() { start: function() {
@ -30,7 +29,7 @@ Module.register('MMM-Wordpress', {
const numberOfPosts = this.config.numberOfPosts; const numberOfPosts = this.config.numberOfPosts;
//hier müssen die posts noch rein! //hier müssen die posts noch rein!
this.sendSocketNotification('GET_POSTS', { url, numberOfPosts }); this.sendSocketNotification('GET_POSTS', { url, posts, numberOfPosts });
}, },
socketNotificationReceived: function(notification, payload) { socketNotificationReceived: function(notification, payload) {
@ -48,7 +47,8 @@ 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>${this.stripTags(post.title.rendered)}</h2><p>${this.stripTags(post.excerpt.rendered)}</p>`;
postElement.innerHTML = `<h2>${this.stripTags(post.title.rendered)}</h2><p>${this.stripTags(post.content.rendered)}</p>`;
wrapper.appendChild(postElement); wrapper.appendChild(postElement);
} }
} else { } else {

View File

@ -1,5 +1,28 @@
# Info
This module for Magic Mirror should display posts from a WordPress site.
# Install # Install
```bash
git clone https://github.com/tbuss/MMM-Wordpress.git git clone https://github.com/tbuss/MMM-Wordpress.git
cd MMM-Wordpress cd MMM-Wordpress
npm install npm install
```
# Config
Put this in your config.js
```js
{
module: 'MMM-Wordpress',
position: 'bottom_bar', // or any other position
config: {
updateInterval: 10*60*1000, // 10 minutes
url: 'https://www.your_wordpress.url',
numberOfPosts: 5
}
},
```

View File

@ -7,9 +7,11 @@ module.exports = NodeHelper.create({
}, },
socketNotificationReceived: function(notification, payload) { socketNotificationReceived: function(notification, payload) {
console.log('Notification!');
if (notification === 'GET_POSTS') { if (notification === 'GET_POSTS') {
const { url, numberOfPosts } = payload; console.log('Notification: GET_POSTS');
const apiUrl = `${url}/wp-json/wp/v2/posts?per_page=${numberOfPosts}`; const { url, posts, numberOfPosts } = payload;
const apiUrl = `${url}/wp-json/wp/v2/${posts}?per_page=${numberOfPosts}`;
request.get(apiUrl, (error, response, body) => { request.get(apiUrl, (error, response, body) => {
if (!error && response.statusCode == 200) { if (!error && response.statusCode == 200) {