mirror of
https://github.com/metabolist/metatext.git
synced 2024-06-02 21:49:36 +00:00
43 lines
1.1 KiB
Swift
43 lines
1.1 KiB
Swift
// Copyright © 2020 Metabolist. All rights reserved.
|
|
|
|
import Foundation
|
|
|
|
extension URL {
|
|
var isAccountURL: Bool {
|
|
(pathComponents.count == 2 && pathComponents[1].starts(with: "@"))
|
|
|| (pathComponents.count == 3 && pathComponents[0...1] == ["/", "users"])
|
|
}
|
|
|
|
var accountID: String? {
|
|
if let accountID = pathComponents.last, pathComponents == ["/", "web", "accounts", accountID] {
|
|
return accountID
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
var statusID: String? {
|
|
guard let statusID = pathComponents.last else { return nil }
|
|
|
|
if pathComponents.count == 3, pathComponents[1].starts(with: "@") {
|
|
return statusID
|
|
} else if pathComponents == ["/", "web", "statuses", statusID] {
|
|
return statusID
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
var tag: String? {
|
|
if let tag = pathComponents.last, pathComponents == ["/", "tags", tag] {
|
|
return tag
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
var shouldWebfinger: Bool {
|
|
isAccountURL || accountID != nil || statusID != nil || tag != nil
|
|
}
|
|
}
|