Software /
code /
prosody-modules
Comparison
mod_pubsub_summary/mod_pubsub_summary.lua @ 4507:86a97e7572b2
mod_pubsub_summary: Fix traceback when <content> not included
Noticed while posting entries with only <title> present
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 12 Mar 2021 11:00:26 +0100 |
parent | 4438:2bb11055e4bb |
child | 4513:ade2064160e3 |
comparison
equal
deleted
inserted
replaced
4506:508cb880b163 | 4507:86a97e7572b2 |
---|---|
5 local payload = event.payload; | 5 local payload = event.payload; |
6 local title = payload:get_child_text("title"); | 6 local title = payload:get_child_text("title"); |
7 -- Note: This prefers content over summary, it was made for a news feed where | 7 -- Note: This prefers content over summary, it was made for a news feed where |
8 -- the interesting stuff was in the content and the summary was .. meh. | 8 -- the interesting stuff was in the content and the summary was .. meh. |
9 local content_tag = payload:get_child("content") or payload:get_child("summary"); | 9 local content_tag = payload:get_child("content") or payload:get_child("summary"); |
10 local content = content_tag:get_text(); | 10 local content = content_tag and content_tag:get_text(); |
11 if content_tag.attr.type == "html" then | 11 if content and content_tag.attr.type == "html" then |
12 content = content:gsub("\n*<p[^>]*>\n*(.-)\n*</p>\n*", "%1\n\n"); | 12 content = content:gsub("\n*<p[^>]*>\n*(.-)\n*</p>\n*", "%1\n\n"); |
13 content = content:gsub("<li>(.-)</li>\n", "* %1\n"); | 13 content = content:gsub("<li>(.-)</li>\n", "* %1\n"); |
14 content = content:gsub("<a[^>]*href=[\"'](.-)[\"'][^>]*>(.-)</a>", "%2 <%1>"); | 14 content = content:gsub("<a[^>]*href=[\"'](.-)[\"'][^>]*>(.-)</a>", "%2 <%1>"); |
15 content = content:gsub("<b>(.-)</b>", "*%1*"); | 15 content = content:gsub("<b>(.-)</b>", "*%1*"); |
16 content = content:gsub("<strong>(.-)</strong>", "*%1*"); | 16 content = content:gsub("<strong>(.-)</strong>", "*%1*"); |