-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3f37c9e
commit 4421662
Showing
3 changed files
with
147 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import type { Article } from './types'; | ||
|
||
const getUrlFromPath = (path: string) => { | ||
const base = 'https://www.reuters.com'; | ||
|
||
try { | ||
return new URL(path); | ||
} catch { | ||
try { | ||
return new URL(path, base); | ||
} catch { | ||
return null; | ||
} | ||
} | ||
}; | ||
|
||
const isCurrentPage = (urlPath: string) => { | ||
if (typeof window === 'undefined' || typeof window.location === 'undefined') { | ||
return false; | ||
} | ||
const url = getUrlFromPath(urlPath); | ||
if (!url) return false; | ||
return window.location.href === url.href; | ||
}; | ||
|
||
export const articleIsNotCurrentPage = (article: Article) => { | ||
const { redirect_url: redirectUrl, canonical_url: canonicalUrl } = article; | ||
|
||
if (redirectUrl) return !isCurrentPage(redirectUrl); | ||
if (canonicalUrl) return !isCurrentPage(canonicalUrl); | ||
return true; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
export interface Referrals { | ||
statusCode: number; | ||
message: string; | ||
result: Result; | ||
} | ||
|
||
interface Result { | ||
date_modified: Date; | ||
pagination: Pagination; | ||
fetch_type: string; | ||
title: string; | ||
articles: Article[]; | ||
} | ||
|
||
export interface Article { | ||
id: string; | ||
canonical_url: string; | ||
basic_headline: string; | ||
title: string; | ||
lead_art: LeadArt; | ||
description: string; | ||
web: string; | ||
content_code: string; | ||
updated_time: Date; | ||
published_time: Date; | ||
display_time: Date; | ||
thumbnail: LeadArt; | ||
primary_media_type: string; | ||
source: Source; | ||
redirect_url: string; | ||
distributor: string; | ||
authors: Author[]; | ||
kicker: Kicker; | ||
content_elements: unknown[]; | ||
headline_category?: unknown; | ||
content?: { | ||
third_party?: unknown; | ||
}; | ||
} | ||
|
||
interface Author { | ||
topic_url: string; | ||
thumbnail: Thumbnail; | ||
id: string; | ||
name: string; | ||
first_name: string; | ||
last_name: string; | ||
company: string; | ||
social_links: SocialLink[]; | ||
byline: string; | ||
} | ||
|
||
interface SocialLink { | ||
url: string; | ||
site: string; | ||
} | ||
|
||
interface Thumbnail { | ||
url: string; | ||
resizer_url: string; | ||
renditions: Renditions; | ||
} | ||
|
||
interface Renditions { | ||
square: Landscape; | ||
landscape: Landscape; | ||
portrait: Landscape; | ||
original: Landscape; | ||
} | ||
|
||
interface Landscape { | ||
'60w': string; | ||
'120w': string; | ||
'240w': string; | ||
'480w': string; | ||
'960w': string; | ||
'1080w': string; | ||
'1200w': string; | ||
'1920w': string; | ||
} | ||
|
||
interface Kicker { | ||
name: string; | ||
path: string; | ||
names: string[]; | ||
} | ||
|
||
interface LeadArt { | ||
type: string; | ||
url: string; | ||
resizer_url: string; | ||
renditions: Renditions; | ||
id: string; | ||
caption?: string; | ||
alt_text: string; | ||
width: number; | ||
height: number; | ||
subtitle: string; | ||
updated_at: Date; | ||
} | ||
|
||
interface Source { | ||
name: string; | ||
} | ||
|
||
interface Pagination { | ||
size: number; | ||
expected_size: number; | ||
} |