Skip to content

Commit

Permalink
Merge pull request #398 from stevencrader/episodes-fm-all
Browse files Browse the repository at this point in the history
Update episodes.fm link to fall back to feed URL if no iTunes Id
  • Loading branch information
daveajones authored Sep 13, 2024
2 parents 814f2b1 + 09afcf3 commit d5483ef
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
10 changes: 7 additions & 3 deletions ui/src/components/PodcastHeader/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Button from "../Button";

import Value from '../Value'
import NoImage from '../../../images/no-cover-art.png'
import { truncateString } from '../../utils'
import { encodeURLSafeBase64, truncateString } from '../../utils'
import RSSLogo from "../../../images/feed.svg";
import EpisodesFMLogo from "../../../images/episodesfm.svg";
import DonationPage from "../../../images/donation-page.svg";
Expand Down Expand Up @@ -153,9 +153,13 @@ export default class PodcastHeader extends React.PureComponent<IProps, PodState>
</a>
: ""
}
{itunesId ?
{itunesId || feedURL ?
<a
href={`https://episodes.fm/${itunesId}`}
href={
`https://episodes.fm/${
itunesId ? itunesId : encodeURLSafeBase64(feedURL)
}`
}
title="Follow in your podcast app"
target="_blank"
>
Expand Down
28 changes: 22 additions & 6 deletions ui/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import queryStringHelper from 'query-string'
import NoImage from "../images/no-cover-art.png";
import NoImage from '../images/no-cover-art.png'

export const updateTitle = (tile?: string) => {
let newTitle = 'Podcastindex.org'
if (tile !== undefined)
newTitle = tile + " | " + newTitle
newTitle = tile + ' | ' + newTitle
document.title = newTitle
}

export const encodeSearch = (searchString: string): string => {
return encodeURIComponent(searchString)
}

export const cleanSearchQuery = (queryString: string, field: string = "q"): string => {
export const cleanSearchQuery = (queryString: string, field: string = 'q'): string => {
let params = queryStringHelper.parse(queryString)
let queryAr = params[field] as string
if (!queryAr) {
Expand Down Expand Up @@ -66,10 +66,10 @@ export const fixURL = (url: string) => {

export const isValidURL = (urlString: string) => {
try {
let url = new URL(urlString);
return url.protocol === "http:" || url.protocol === "https:";
let url = new URL(urlString)
return url.protocol === 'http:' || url.protocol === 'https:'
} catch (_) {
return false;
return false
}
}

Expand All @@ -83,3 +83,19 @@ export const isValidURL = (urlString: string) => {
export const getImage = (item) => {
return item.artwork || item.image || item.feedImage || NoImage
}

/**
* Encodes text to URL safe base64
*
* Based on example from https://developer.mozilla.org/en-US/docs/Glossary/Base64#the_unicode_problem
*
* @param text the text to encode
* @return the base 64 encoded text
*/
export const encodeURLSafeBase64 = (text: string): string => {
const binString = Array.from(new TextEncoder().encode(text), (byte) =>
String.fromCodePoint(byte),
).join('')
// since episodes.fm doesn't need trailing =, remove them
return btoa(binString).replace(/=+$/, '');
}

0 comments on commit d5483ef

Please sign in to comment.