[plugin] NewsDownloader: add primitive support for relative URLs (#12980)
Some checks are pending
macos / macOS ${{ matrix.image }} ${{ matrix.platform }} 🔨${{ matrix.xcode_version }} 🎯${{ matrix.deployment_target }} (10.15, 13, x86-64, 15.2) (push) Waiting to run
macos / macOS ${{ matrix.image }} ${{ matrix.platform }} 🔨${{ matrix.xcode_version }} 🎯${{ matrix.deployment_target }} (11.0, 14, ARM64, 15.4) (push) Waiting to run

Fixes #8611.
This commit is contained in:
Frans de Jonge
2025-01-02 12:45:22 +01:00
committed by GitHub
parent 10f627e3f9
commit 016592e0a3

View File

@@ -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([[
<!DOCTYPE html>
<html>