Better handling of articles with stub URLs that shouldn't be used (happens with newsletters that dont have a URL')

This commit is contained in:
Jackson Harper
2022-11-11 12:41:11 +08:00
parent be941faf39
commit fa99af3f6a
5 changed files with 52 additions and 9 deletions

View File

@ -221,6 +221,12 @@ struct WebReaderContainerView: View {
action: share,
label: { Label("Share Original", systemImage: "square.and.arrow.up") }
)
if viewModel.hasOriginalUrl(item) {
Button(
action: share,
label: { Label("Share Original", systemImage: "square.and.arrow.up") }
)
}
Button(
action: delete,
label: { Label("Delete", systemImage: "trash") }

View File

@ -12,6 +12,16 @@ struct SafariWebLink: Identifiable {
@Published var articleContent: ArticleContent?
@Published var errorMessage: String?
func hasOriginalUrl(_ item: LinkedItem) -> Bool {
if let pageURLString = item.pageURLString, let host = URL(string: pageURLString)?.host {
if host == "omnivore.app" {
return false
}
return true
}
return false
}
func loadContent(dataService: DataService, username: String, itemID: String, retryCount: Int = 0) async {
errorMessage = nil

View File

@ -62,11 +62,22 @@ public extension LinkedItem {
return (pageURLString ?? "").hasSuffix("pdf")
}
func hideHost(_ host: String) -> Bool {
switch host {
case "storage.googleapis.com":
return true
case "omnivore.app":
return true
default:
return false
}
}
var publisherDisplayName: String? {
if let siteName = siteName {
return siteName
}
if let host = URL(string: publisherURLString ?? pageURLString ?? "")?.host, host != "storage.googleapis.com" {
if let host = URL(string: publisherURLString ?? pageURLString ?? "")?.host, !hideHost(host) {
return host
}
return nil

File diff suppressed because one or more lines are too long

View File

@ -12,16 +12,17 @@ type ArticleSubtitleProps = {
hideButton?: boolean
}
export function ArticleSubtitle(props: ArticleSubtitleProps): JSX.Element {
export function ArticleSubtitle(props: ArticleSubtitleProps): JSX.Element {
const textStyle = props.style || 'footnote'
const subtitle = articleSubtitle(props.href, props.author)
return (
<Box>
<StyledText style={textStyle} css={{ wordBreak: 'break-word' }}>
{articleSubtitle(props.href, props.author)}{' '}
<span style={{ position: 'relative', bottom: 1 }}> </span>{' '}
{subtitle}{' '}
{subtitle && (<span style={{ position: 'relative', bottom: 1 }}> </span>)}{' '}
{formattedLongDate(props.rawDisplayDate)}{' '}
{!props.hideButton && (
{!props.hideButton && !shouldHideUrl(props.href) && (
<>
<span style={{ position: 'relative', bottom: 1 }}> </span>{' '}
<StyledLink
@ -42,11 +43,26 @@ export function ArticleSubtitle(props: ArticleSubtitleProps): JSX.Element {
)
}
function articleSubtitle(url: string, author?: string): string {
function shouldHideUrl(url: string): boolean {
const origin = new URL(url).origin
const hideHosts = ['https://storage.googleapis.com', 'https://omnivore.app']
if (hideHosts.indexOf(origin) != -1) {
return true
}
return false
}
function articleSubtitle(url: string, author?: string): string | undefined {
const origin = new URL(url).origin
const hideUrl = shouldHideUrl(url)
if (author) {
return `${authoredByText(author)}, ${new URL(url).hostname}`
const auth = `${authoredByText(author)}`
return hideUrl ? auth : `${auth}, ${new URL(url).hostname}`
} else {
return new URL(url).origin
if (hideUrl) {
return undefined
}
return origin
}
}