experimentally discover base url of the feed and use it to relative URLs withing messages
This commit is contained in:
parent
441070f4f2
commit
299415f55a
@ -30,7 +30,7 @@
|
||||
<url type="donation">https://martinrotter.github.io/donate/</url>
|
||||
<content_rating type="oars-1.1" />
|
||||
<releases>
|
||||
<release version="3.9.2" date="2021-07-01"/>
|
||||
<release version="3.9.2" date="2021-07-12"/>
|
||||
</releases>
|
||||
<content_rating type="oars-1.0">
|
||||
<content_attribute id="violence-cartoon">none</content_attribute>
|
||||
|
@ -53,7 +53,7 @@ WebPage* WebViewer::page() const {
|
||||
}
|
||||
|
||||
void WebViewer::displayMessage() {
|
||||
setHtml(m_messageContents /*, QUrl::fromUserInput(INTERNAL_URL_MESSAGE)*/);
|
||||
setHtml(m_messageContents, m_messageBaseUrl /*, QUrl::fromUserInput(INTERNAL_URL_MESSAGE)*/);
|
||||
}
|
||||
|
||||
bool WebViewer::increaseWebPageZoom() {
|
||||
@ -143,6 +143,21 @@ void WebViewer::loadMessages(const QList<Message>& messages, RootItem* root) {
|
||||
}
|
||||
|
||||
m_root = root;
|
||||
|
||||
auto* feed = root->getParentServiceRoot()->getItemFromSubTree([messages](const RootItem* it) {
|
||||
return it->kind() == RootItem::Kind::Feed && it->customId() == messages.at(0).m_feedId;
|
||||
})->toFeed();
|
||||
|
||||
m_messageBaseUrl = QString();
|
||||
|
||||
if (feed != nullptr) {
|
||||
QUrl url(feed->source());
|
||||
|
||||
if (url.isValid()) {
|
||||
m_messageBaseUrl = url.scheme() + QSL("://") + url.host();
|
||||
}
|
||||
}
|
||||
|
||||
m_messageContents = skin.m_layoutMarkupWrapper.arg(messages.size() == 1 ? messages.at(0).m_title : tr("Newspaper view"),
|
||||
messages_layout);
|
||||
|
||||
|
@ -45,6 +45,7 @@ class WebViewer : public QWebEngineView {
|
||||
|
||||
private:
|
||||
RootItem* m_root;
|
||||
QString m_messageBaseUrl;
|
||||
QString m_messageContents;
|
||||
};
|
||||
|
||||
|
@ -50,13 +50,13 @@ QString AtomParser::feedAuthor() const {
|
||||
Message AtomParser::extractMessage(const QDomElement& msg_element, QDateTime current_time) const {
|
||||
Message new_message;
|
||||
QString title = textsFromPath(msg_element, m_atomNamespace, QSL("title"), true).join(QSL(", "));
|
||||
QString summary = textsFromPath(msg_element, m_atomNamespace, QSL("content"), true).join(QSL(", "));
|
||||
QString summary = rawXmlChild(msg_element.elementsByTagNameNS(m_atomNamespace, QSL("content")).at(0).toElement());
|
||||
|
||||
if (summary.isEmpty()) {
|
||||
summary = textsFromPath(msg_element, m_atomNamespace, QSL("summary"), true).join(QSL(", "));
|
||||
summary = rawXmlChild(msg_element.elementsByTagNameNS(m_atomNamespace, QSL("summary")).at(0).toElement());
|
||||
|
||||
if (summary.isEmpty()) {
|
||||
summary = mrssTextFromPath(msg_element, QSL("description"));
|
||||
summary = rawXmlChild(msg_element.elementsByTagNameNS(m_mrssNamespace, QSL("description")).at(0).toElement());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,9 +3,12 @@
|
||||
#include "services/standard/feedparser.h"
|
||||
|
||||
#include "exceptions/applicationexception.h"
|
||||
#include "miscellaneous/application.h"
|
||||
#include "network-web/webfactory.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QRegularExpression>
|
||||
|
||||
#include <utility>
|
||||
|
||||
FeedParser::FeedParser(QString data) : m_xmlData(std::move(data)), m_mrssNamespace(QSL("http://search.yahoo.com/mrss/")) {
|
||||
@ -84,6 +87,28 @@ QString FeedParser::mrssTextFromPath(const QDomElement& msg_element, const QStri
|
||||
return text;
|
||||
}
|
||||
|
||||
QString FeedParser::rawXmlChild(const QDomElement& container) const {
|
||||
QString raw;
|
||||
auto children = container.childNodes();
|
||||
|
||||
for (int i = 0; i < children.size(); i++) {
|
||||
QString raw_ch;
|
||||
|
||||
if (children.at(i).isCDATASection()) {
|
||||
raw_ch = children.at(i).toCDATASection().data();
|
||||
}
|
||||
else {
|
||||
QTextStream str(&raw_ch);
|
||||
|
||||
children.at(i).save(str, 0);
|
||||
}
|
||||
|
||||
raw += qApp->web()->unescapeHtml(raw_ch);
|
||||
}
|
||||
|
||||
return raw;
|
||||
}
|
||||
|
||||
QStringList FeedParser::textsFromPath(const QDomElement& element, const QString& namespace_uri,
|
||||
const QString& xml_path, bool only_first) const {
|
||||
QStringList paths = xml_path.split('/');
|
||||
|
@ -19,6 +19,7 @@ class FeedParser {
|
||||
protected:
|
||||
QList<Enclosure> mrssGetEnclosures(const QDomElement& msg_element) const;
|
||||
QString mrssTextFromPath(const QDomElement& msg_element, const QString& xml_path) const;
|
||||
QString rawXmlChild(const QDomElement& container) const;
|
||||
QStringList textsFromPath(const QDomElement& element, const QString& namespace_uri, const QString& xml_path, bool only_first) const;
|
||||
virtual QDomNodeList messageElements() = 0;
|
||||
virtual QString feedAuthor() const;
|
||||
|
Loading…
x
Reference in New Issue
Block a user