diff --git a/MMM-Wordpress.js b/MMM-Wordpress.js index 38ed994..a7fa4d0 100644 --- a/MMM-Wordpress.js +++ b/MMM-Wordpress.js @@ -1,13 +1,3 @@ -/* global Module, MMM-Wordpress */ - -/* Magic Mirror - * Module: MMM-Wordpress - * - * By Tobias Buss - * MIT Licensed. - */ - - Module.register('MMM-Wordpress', { defaults: { updateInterval: 600000, // 10 minutes @@ -26,12 +16,11 @@ Module.register('MMM-Wordpress', { getPosts: function() { const url = this.config.url; - const posts = this.config.posts; const numberOfPosts = this.config.numberOfPosts; const request = require('request'); - request.get(`${url}/wp-json/wp/v2/${posts}?per_page=${numberOfPosts}`, (error, response, body) => { + request.get(`${url}/wp-json/wp/v2/posts?per_page=${numberOfPosts}`, (error, response, body) => { if (!error && response.statusCode == 200) { this.posts = JSON.parse(body); this.updateDom(); @@ -47,15 +36,19 @@ Module.register('MMM-Wordpress', { for (let i = 0; i < posts.length; i++) { const post = posts[i]; const postElement = document.createElement('div'); - postElement.innerHTML = `

${post.title.rendered}

${post.excerpt.rendered}

`; + postElement.innerHTML = `

${this.stripTags(post.title.rendered)}

${this.stripTags(post.excerpt.rendered)}

`; wrapper.appendChild(postElement); } } else { - wrapper.innerHTML = 'No posts found'; + wrapper.innerHTML = 'Keine Beiträge gefunden'; } return wrapper; + }, + + stripTags: function(html) { + const doc = new DOMParser().parseFromString(html, 'text/html'); + return doc.body.textContent || ""; } }); - \ No newline at end of file