Warn for sources in included html
This commit is contained in:
parent
657f8c4ef4
commit
8a3a0f1797
@ -5,6 +5,7 @@ enum PageContentAnomaly {
|
||||
case missingPage(page: String, markdown: String)
|
||||
case missingTag(tag: String, markdown: String)
|
||||
case invalidCommand(command: ShorthandMarkdownKey?, markdown: String)
|
||||
case warning(String)
|
||||
}
|
||||
|
||||
extension PageContentAnomaly: Identifiable {
|
||||
@ -21,6 +22,8 @@ extension PageContentAnomaly: Identifiable {
|
||||
return "missing-tag-\(string)"
|
||||
case .invalidCommand(_, let markdown):
|
||||
return "invalid-command-\(markdown)"
|
||||
case .warning(let string):
|
||||
return "warning-\(string)"
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -50,7 +53,7 @@ extension PageContentAnomaly {
|
||||
switch self {
|
||||
case .failedToLoadContent:
|
||||
return .error
|
||||
case .missingFile, .missingPage, .missingTag, .invalidCommand:
|
||||
case .missingFile, .missingPage, .missingTag, .invalidCommand, .warning:
|
||||
return .warning
|
||||
}
|
||||
}
|
||||
@ -70,6 +73,8 @@ extension PageContentAnomaly: CustomStringConvertible {
|
||||
return "Missing tag: \(string)"
|
||||
case .invalidCommand(_, let markdown):
|
||||
return "Invalid command: \(markdown)"
|
||||
case .warning(let string):
|
||||
return "Warning: \(string)"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -121,11 +121,9 @@ final class PageContentParser {
|
||||
|
||||
private func handleHTML(_: String, markdown: Substring) -> String {
|
||||
let result = String(markdown)
|
||||
#warning("Check HTML code in markdown for required resources")
|
||||
findImages(in: result)
|
||||
findLinks(in: result)
|
||||
findSourceSets(in: result)
|
||||
// Things to check: <img src= <a href= <source>
|
||||
return result
|
||||
}
|
||||
|
||||
@ -138,10 +136,12 @@ final class PageContentParser {
|
||||
let imgElements = try document.select("img")
|
||||
|
||||
// Extract the 'src' attributes from each 'img' element
|
||||
let srcAttributes = try imgElements.array().compactMap { try $0.attr("src") }
|
||||
let srcAttributes = try imgElements.array()
|
||||
.compactMap { try $0.attr("src") }
|
||||
.filter { !$0.trimmed.isEmpty }
|
||||
|
||||
for src in srcAttributes {
|
||||
print("Found image in html: \(src)")
|
||||
results.issues.insert(.warning("Found image in html: \(src)"))
|
||||
}
|
||||
} catch {
|
||||
print("Error parsing HTML: \(error)")
|
||||
@ -157,10 +157,16 @@ final class PageContentParser {
|
||||
let linkElements = try document.select("a")
|
||||
|
||||
// Extract the 'src' attributes from each 'img' element
|
||||
let srcAttributes = try linkElements.array().compactMap { try $0.attr("href") }
|
||||
let srcAttributes = try linkElements.array()
|
||||
.compactMap { try $0.attr("href").trimmed }
|
||||
.filter { !$0.isEmpty }
|
||||
|
||||
for src in srcAttributes {
|
||||
print("Found link in html: \(src)")
|
||||
for url in srcAttributes {
|
||||
if url.hasPrefix("http://") || url.hasPrefix("https://") {
|
||||
results.externalLinks.insert(url)
|
||||
} else {
|
||||
results.issues.insert(.warning("Relative link in HTML: \(url)"))
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
print("Error parsing HTML: \(error)")
|
||||
@ -176,10 +182,28 @@ final class PageContentParser {
|
||||
let linkElements = try document.select("source")
|
||||
|
||||
// Extract the 'src' attributes from each 'img' element
|
||||
let srcAttributes = try linkElements.array().compactMap { try $0.attr("srcset") }
|
||||
let srcsetAttributes = try linkElements.array()
|
||||
.compactMap { try $0.attr("srcset") }
|
||||
.filter { !$0.trimmed.isEmpty }
|
||||
|
||||
for src in srcsetAttributes {
|
||||
results.issues.insert(.warning("Found source set in html: \(src)"))
|
||||
}
|
||||
|
||||
let srcAttributes = try linkElements.array()
|
||||
.compactMap { try $0.attr("src") }
|
||||
.filter { !$0.trimmed.isEmpty }
|
||||
|
||||
for src in srcAttributes {
|
||||
print("Found source set in html: \(src)")
|
||||
guard content.isValidIdForFile(src) else {
|
||||
results.issues.insert(.warning("Found source in html: \(src)"))
|
||||
continue
|
||||
}
|
||||
guard let file = content.file(src) else {
|
||||
results.issues.insert(.warning("Found source in html: \(src)"))
|
||||
continue
|
||||
}
|
||||
results.files.insert(file)
|
||||
}
|
||||
} catch {
|
||||
print("Error parsing HTML: \(error)")
|
||||
|
@ -1,9 +1,10 @@
|
||||
import SwiftUI
|
||||
import SFSafeSymbols
|
||||
|
||||
#warning("Allow selection of pages as navigation bar items")
|
||||
#warning("Show all warnings on page content")
|
||||
#warning("Button to delete file")
|
||||
#warning("Fix podcast")
|
||||
#warning("Allow selection of pages as navigation bar items")
|
||||
#warning("Add link to other language")
|
||||
#warning("Transfer images of posts to other language")
|
||||
#warning("Show tag selection view for pages")
|
||||
|
@ -32,5 +32,6 @@ struct IconButton: View {
|
||||
.fill(background)
|
||||
.padding(1))
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ struct LocalizedPostDetailView: View {
|
||||
.font(.headline)
|
||||
OptionalTextField("", text: $item.linkPreviewTitle,
|
||||
prompt: item.title)
|
||||
.textFieldStyle(.roundedBorder)
|
||||
.textFieldStyle(.roundedBorder)
|
||||
.padding(.bottom)
|
||||
|
||||
HStack {
|
||||
@ -29,7 +29,7 @@ struct LocalizedPostDetailView: View {
|
||||
size: 22,
|
||||
color: .blue) {
|
||||
showImagePicker = true
|
||||
}
|
||||
}.padding(.bottom)
|
||||
|
||||
IconButton(symbol: .trashCircleFill,
|
||||
size: 22,
|
||||
|
@ -86,6 +86,8 @@ struct PageIssueView: View {
|
||||
|
||||
private var buttons: [ButtonAction] {
|
||||
switch issue.message {
|
||||
case .warning:
|
||||
return [.init(name: "Retry", action: retryPageCheck)]
|
||||
case .failedToLoadContent:
|
||||
return [.init(name: "Retry", action: retryPageCheck)]
|
||||
case .missingFile(let missing, _):
|
||||
|
Loading…
x
Reference in New Issue
Block a user