From 016592e0a3300ad645583df4b6c36f5efd1e708e Mon Sep 17 00:00:00 2001 From: Frans de Jonge Date: Thu, 2 Jan 2025 12:45:22 +0100 Subject: [PATCH] [plugin] NewsDownloader: add primitive support for relative URLs (#12980) Fixes #8611. --- plugins/newsdownloader.koplugin/main.lua | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/plugins/newsdownloader.koplugin/main.lua b/plugins/newsdownloader.koplugin/main.lua index e70706392..857b1d6e4 100644 --- a/plugins/newsdownloader.koplugin/main.lua +++ b/plugins/newsdownloader.koplugin/main.lua @@ -614,6 +614,24 @@ function NewsDownloader:createFromDescription(feed, title, content, feed_output_ logger.dbg("NewsDownloader: News file will be stored to :", news_file_path) local article_message = T(_("%1\n%2"), message, title_with_date) local footer = _("If this is only a summary, the full article can be downloaded by going to the News Downloader settings and changing 'Download full article' to 'true'.") + + local base_url = getFeedLink(feed.link) + if base_url then + if not base_url:match("/$") then + base_url = base_url .. "/" + end + content = content:gsub('href="(.-)"', function(link) + if link:match("^/") then + local base_url_domain_only = base_url:match("^(.-://[^/]+)/") + return 'href="' .. base_url_domain_only .. link .. '"' + end + if not link:match("^[a-zA-Z][a-zA-Z0-9+.-]*://") then + link = base_url .. link + end + return 'href="' .. link .. '"' + end) + end + local html = string.format([[