mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-24 04:38:16 +00:00
Inline release notes if they don't look like a standalone HTML document
This commit is contained in:
1 parent
1683d2de34
commit
662e84400a
2 files changed
+35
-3
No files matched your search
@@ -119,17 +119,42 @@ class ArchiveItem: CustomStringConvertible {
|
||||
return (self.archiveFileAttributes[.size] as! NSNumber).int64Value;
|
||||
}
|
||||
|
||||
private var releaseNotesPath : URL {
|
||||
private var releaseNotesPath : URL? {
|
||||
let basename = self.archivePath.deletingPathExtension();
|
||||
let releaseNotes = basename.appendingPathExtension("html");
|
||||
if !FileManager.default.fileExists(atPath: releaseNotes.path) {
|
||||
return nil;
|
||||
}
|
||||
return releaseNotes;
|
||||
}
|
||||
|
||||
private func getReleaseNotesAsHTMLFragment(_ path: URL) -> String? {
|
||||
if let html = try? String(contentsOf: path) {
|
||||
if html.utf8.count < 1000 &&
|
||||
!html.localizedCaseInsensitiveContains("<!DOCTYPE") &&
|
||||
!html.localizedCaseInsensitiveContains("<body") {
|
||||
return html;
|
||||
}
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
var releaseNotesHTML : String? {
|
||||
if let path = self.releaseNotesPath {
|
||||
return self.getReleaseNotesAsHTMLFragment(path);
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
var releaseNotesURL : URL? {
|
||||
if !FileManager.default.fileExists(atPath: self.releaseNotesPath.path) {
|
||||
guard let path = self.releaseNotesPath else {
|
||||
return nil;
|
||||
}
|
||||
guard let escapedFilename = self.releaseNotesPath.lastPathComponent.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) else {
|
||||
// The file is already used as inline description
|
||||
if self.getReleaseNotesAsHTMLFragment(path) != nil {
|
||||
return nil;
|
||||
}
|
||||
guard let escapedFilename = path.lastPathComponent.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) else {
|
||||
return nil;
|
||||
}
|
||||
if let relative = self.feedURL {
|
||||
|
||||
@@ -105,6 +105,13 @@ func writeAppcast(appcastDestPath: URL, updates: [ArchiveItem]) throws {
|
||||
item.addChild(XMLElement.element(withName: "pubDate", stringValue: update.pubDate) as! XMLElement);
|
||||
}
|
||||
|
||||
if let html = update.releaseNotesHTML {
|
||||
let descElement = findOrCreateElement(name: "description", parent: item);
|
||||
let cdata = XMLNode(kind:.text, options:.nodeIsCDATA);
|
||||
cdata.stringValue = html;
|
||||
descElement.setChildren([cdata]);
|
||||
}
|
||||
|
||||
var minVer = findElement(name: "sparkle:minimumSystemVersion", parent: item);
|
||||
if nil == minVer {
|
||||
minVer = XMLElement.element(withName: "sparkle:minimumSystemVersion", uri: sparkleNS) as? XMLElement;
|
||||
|
||||
Reference in new issue
Block a user