Skip to content

Commit

Permalink
feat(app,registry): improve index page detection, add 404 page
Browse files Browse the repository at this point in the history
  • Loading branch information
trollixx committed Feb 2, 2020
1 parent 096dcbf commit c16945b
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 8 deletions.
66 changes: 66 additions & 0 deletions src/app/resources/browser/404.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<html>

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Welcome</title>
<link rel="stylesheet" type="text/css" href="assets/css/fa-brands.min.css">
<link rel="stylesheet" type="text/css" href="assets/css/fa-solid.min.css">
<link rel="stylesheet" type="text/css" href="assets/css/fontawesome.min.css">
<link rel="stylesheet" type="text/css" href="assets/css/welcome.min.css">
</head>

<body class="is-unselectable">
<section class="hero is-fullheight">
<div class="hero-body">
<div class="container">
<div class="columns is-vcentered">
<div class="column">
<p class="title">File not found</p>
<p class="subtitle">aaa</p>
</div>
<div class="column">
<p class="subtitle is-5">Get in touch</p>
<div class="command-block" onclick="zAppBridge.openShortUrl('gitter')">
<p class="title is-6">Gitter</p>
<p class="subtitle is-6">Chat with developers and other users</p>
</div>
<div class="command-block" onclick="zAppBridge.openShortUrl('github')">
<p class="title is-6">GitHub</p>
<p class="subtitle is-6">Contribute to the project</p>
</div>
</div>
</div>
</div>
</div>

<div class="hero-foot">
<div class="container">
<div class="content has-text-centered">
<p>
<a class="icon" onclick="zAppBridge.openShortUrl('github')">
<i class="fab fa-github"></i>
</a>
<a class="icon" onclick="zAppBridge.openShortUrl('gitter')">
<i class="fab fa-gitter"></i>
</a>
<a class="icon" onclick="zAppBridge.openShortUrl('twiter')">
<i class="fab fa-twitter"></i>
</a>
</p>
<p>
<a class="is-size-7" onclick="zAppBridge.openShortUrl('report-bug')">
<span class="icon">
<i class="fas fa-bug"></i>
</span>
<span>Report a problem</span>
</a>
</p>
<p></p>
</div>
</div>
</div>
</section>
</body>

</html>
1 change: 1 addition & 0 deletions src/app/resources/zeal.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<file>browser/assets/css/welcome.min.css</file>
<file>browser/assets/fonts/fa-brands-400.woff</file>
<file>browser/assets/fonts/fa-solid-900.woff</file>
<file>browser/404.html</file>
<file>browser/welcome.html</file>
<file>icons/type/Abbreviation.png</file>
<file>icons/type/[email protected]</file>
Expand Down
38 changes: 30 additions & 8 deletions src/libs/registry/docset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ namespace {
constexpr char IndexNamePrefix[] = "__zi_name"; // zi - Zeal index
constexpr char IndexNameVersion[] = "0001"; // Current index version

constexpr char NotFoundPageUrl[] = "qrc:///browser/404.html";

namespace InfoPlist {
constexpr char CFBundleName[] = "CFBundleName";
//const char CFBundleIdentifier[] = "CFBundleIdentifier";
Expand Down Expand Up @@ -171,16 +173,36 @@ Docset::Docset(QString path)

m_keywords.removeDuplicates();

// Prefer index path provided by the docset over metadata.
// Determine index page. This is ridiculous.

// Prefer index path provided by the docset.
if (plist.contains(InfoPlist::DashIndexFilePath)) {
m_indexFileUrl = createPageUrl(plist[InfoPlist::DashIndexFilePath].toString());
} else if (m_indexFileUrl.isEmpty()) {
if (dir.exists(QStringLiteral("index.html")))
m_indexFileUrl = createPageUrl(QStringLiteral("index.html"));
else
qWarning("Cannot determine index file for docset %s", qPrintable(m_name));
const QString indexFilePath = plist[InfoPlist::DashIndexFilePath].toString();
if (dir.exists(indexFilePath)) {
m_indexFilePath = indexFilePath;
}
}

// Check the metadata.
if (m_indexFilePath.isEmpty() && !dir.exists(m_indexFilePath)) {
// Well, metadata was wrong.
m_indexFileUrl.clear();
}

// What if there is index.html.
if (m_indexFilePath.isEmpty() && dir.exists(QStringLiteral("index.html"))) {
m_indexFilePath = QStringLiteral("index.html");
}

// Log if unable to determine the index page.
if (m_indexFilePath.isEmpty()) {
qWarning("Cannot determine index file for docset %s", qPrintable(m_name));
m_indexFileUrl.setUrl(NotFoundPageUrl);
} else {
m_indexFileUrl = createPageUrl(m_indexFilePath);
}


countSymbols();
}

Expand Down Expand Up @@ -392,7 +414,7 @@ void Docset::loadMetadata()
const QJsonObject extra = jsonObject[QStringLiteral("extra")].toObject();

if (extra.contains(QStringLiteral("indexFilePath"))) {
m_indexFileUrl = createPageUrl(extra[QStringLiteral("indexFilePath")].toString());
m_indexFilePath = extra[QStringLiteral("indexFilePath")].toString();
}

if (extra.contains(QStringLiteral("keywords"))) {
Expand Down
1 change: 1 addition & 0 deletions src/libs/registry/docset.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ class Docset final
QIcon m_icon;

QUrl m_indexFileUrl;
QString m_indexFilePath;

QMap<QString, QString> m_symbolStrings;
QMap<QString, int> m_symbolCounts;
Expand Down

0 comments on commit c16945b

Please sign in to comment.