Skip to content

Commit

Permalink
feat(series): e2e fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonLantukh committed May 23, 2023
1 parent 6170b90 commit 2e794d9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ const MediaSeriesContent: ScreenComponent<PlaylistItem> = ({ data: seriesMedia }
if (!series || !seriesMedia) return <ErrorPage title={t('series_error')} />;

const pageTitle = `${selectedItem.title} - ${siteName}`;
const canonicalUrl = `${window.location.origin}${mediaURL({ media: selectedItem, episodeId: episode?.mediaid })}`;
const canonicalUrl = `${window.location.origin}${mediaURL({ media: seriesMedia, episodeId: episode?.mediaid })}`;

const primaryMetadata = formatVideoMetaString(
selectedItem,
Expand Down Expand Up @@ -207,7 +207,7 @@ const MediaSeriesContent: ScreenComponent<PlaylistItem> = ({ data: seriesMedia }
<meta property="og:video:tag" content={tag} key={tag} />
))}
{seriesPlaylist && selectedItem ? (
<script type="application/ld+json">{generateEpisodeJSONLD(series, seriesMedia, episode, episodeMetadata, seriesId)}</script>
<script type="application/ld+json">{generateEpisodeJSONLD(series, seriesMedia, episode, episodeMetadata)}</script>
) : null}
</Helmet>
<VideoLayout
Expand Down
18 changes: 6 additions & 12 deletions src/utils/structuredData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,14 @@ export const generateSeriesMetadata = (series: Series, media: PlaylistItem, seri
'@type': 'TVSeries',
'@id': seriesCanonical,
name: media.title,
numberOfEpisodes: String(series?.episode_count),
numberOfEpisodes: String(series?.episode_count || 0),
numberOfSeasons: String(series?.season_count || 0),
};
};

export const generateEpisodeJSONLD = (
series: Series,
media: PlaylistItem,
episode: PlaylistItem | undefined,
episodeMetadata: EpisodeMetadata | undefined,
seriesId: string,
) => {
const episodeCanonical = `${window.location.origin}${mediaURL({ media, episodeId: episode?.mediaid })}`;
const seriesMetadata = generateSeriesMetadata(series, media, seriesId);
export const generateEpisodeJSONLD = (series: Series, media: PlaylistItem, episode: PlaylistItem | undefined, episodeMetadata: EpisodeMetadata | undefined) => {
const episodeCanonical = `${window.location.origin}/m/${series.series_id}?e=${episode?.mediaid}`;
const seriesMetadata = generateSeriesMetadata(series, media, series.series_id);

if (!episode) {
return JSON.stringify(seriesMetadata);
Expand All @@ -92,8 +86,8 @@ export const generateEpisodeJSONLD = (
'@context': 'http://schema.org/',
'@type': 'TVEpisode',
'@id': episodeCanonical,
episodeNumber: episodeMetadata?.episodeNumber,
seasonNumber: episodeMetadata?.seasonNumber,
episodeNumber: episodeMetadata?.episodeNumber || '0',
seasonNumber: episodeMetadata?.seasonNumber || '0',
name: episode.title,
uploadDate: secondsToISO8601(episode.pubdate),
partOfSeries: seriesMetadata,
Expand Down
15 changes: 12 additions & 3 deletions test-e2e/tests/seo_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,13 @@ Scenario('It renders the correct structured metadata for the episode screen', as
const rawURL = await I.grabCurrentUrl();
const url = removeQueryParams(rawURL, ['r', 'app-config']);
const seriesURL = getSeriesURL(url);
const episodeURL = getEpisodeURL(url);

I.seeTextEquals(
JSON.stringify({
'@context': 'http://schema.org/',
'@type': 'TVEpisode',
'@id': url,
'@id': episodeURL,
episodeNumber: '1',
seasonNumber: '0',
name: 'Blocking',
Expand Down Expand Up @@ -184,8 +185,16 @@ function getPosterUrl(href: string, type: 'series' | 'episode' | 'other' = 'othe
}

function getSeriesURL(url: string) {
const parsedURL = new URL(url);
const parsedURL = new URL(removeQueryParams(url, ['e']));
const mediaId = parsedURL.pathname.split('/')[2];

return `${parsedURL.origin}/m/${mediaId}`;
}

function getEpisodeURL(url: string) {
const episodeId = getQueryParam(url, 'e');
const parsedURL = new URL(removeQueryParams(url, ['e']));
const mediaId = parsedURL.pathname.split('/')[2];

return mediaId;
return `${parsedURL.origin}/m/${mediaId}?e=${episodeId}`;
}

0 comments on commit 2e794d9

Please sign in to comment.