Skip to content

Commit

Permalink
Reduce subject and topic usage on ResourcePage
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonas-C committed Mar 22, 2024
1 parent e758e17 commit 9754056
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 29 deletions.
28 changes: 8 additions & 20 deletions src/containers/ArticlePage/ArticlePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ const ArticlePage = ({
const { user, authContextLoaded } = useContext(AuthContext);
const { t, i18n } = useTranslation();
const { trackPageView } = useTracker();
const subjectPageUrl = config.ndlaFrontendDomain;

useEffect(() => {
if (!loading && authContextLoaded) {
Expand Down Expand Up @@ -135,32 +134,24 @@ const ArticlePage = ({
const contentType = resource ? getContentType(resource) : undefined;
const resourceType = contentType && isHeroContentType(contentType) ? contentType : undefined;

const copyPageUrlLink = topic ? `${subjectPageUrl}${topic.path}/${resource.id.replace("urn:", "")}` : undefined;
const printUrl = `${subjectPageUrl}/article-iframe/${i18n.language}/article/${resource.article.id}`;
const printUrl = `${config.ndlaFrontendDomain}/article-iframe/${i18n.language}/article/${resource.article.id}`;

const breadcrumbItems = toBreadcrumbItems(t("breadcrumb.toFrontpage"), [...topicPath, resource]);

return (
<main>
<ArticleHero
subject={subject}
resourceType={resourceType}
metaImage={article.metaImage}
breadcrumbItems={breadcrumbItems}
/>
<ArticleHero resourceType={resourceType} metaImage={article.metaImage} breadcrumbItems={breadcrumbItems} />
<Helmet>
<title>{`${getDocumentTitle(t, resource, subject)}`}</title>
{scripts?.map((script) => (
<script key={script.src} src={script.src} type={script.type} async={script.async} defer={script.defer} />
))}
{copyPageUrlLink && (
<link
rel="alternate"
type="application/json+oembed"
href={`${config.ndlaFrontendDomain}/oembed?url=${copyPageUrlLink}`}
title={article.title}
/>
)}
<link
rel="alternate"
type="application/json+oembed"
href={`${config.ndlaFrontendDomain}/oembed?url=${config.ndlaFrontendDomain}${resource.path}`}
title={article.title}
/>
{subject?.metadata.customFields?.[TAXONOMY_CUSTOM_FIELD_SUBJECT_CATEGORY] ===
constants.subjectCategories.ARCHIVE_SUBJECTS && <meta name="robots" content="noindex, nofollow" />}
<meta name="pageid" content={`${article.id}`} />
Expand Down Expand Up @@ -226,9 +217,7 @@ export const articlePageFragments = {
title
}
}
...ArticleHero_Subject
}
${ArticleHero.fragments.subject}
`,
resource: gql`
fragment ArticlePage_Resource on Resource {
Expand Down Expand Up @@ -256,7 +245,6 @@ export const articlePageFragments = {
`,
topic: gql`
fragment ArticlePage_Topic on Topic {
path
...Resources_Topic
}
${Resources.fragments.topic}
Expand Down
12 changes: 3 additions & 9 deletions src/containers/ArticlePage/components/ArticleHero.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { gql } from "@apollo/client";
import styled from "@emotion/styled";
import { stackOrder } from "@ndla/core";
import { Hero, HeroContent, HeroContentType, HomeBreadcrumb, NdlaFilmHero, OneColumn } from "@ndla/ui";
import { GQLArticleHero_MetaImageFragment, GQLArticleHero_SubjectFragment } from "../../../graphqlTypes";
import { GQLArticleHero_MetaImageFragment } from "../../../graphqlTypes";
import { Breadcrumb as BreadcrumbType } from "../../../interfaces";
import { useIsNdlaFilm } from "../../../routeHelpers";

Expand Down Expand Up @@ -52,7 +52,6 @@ const HeroBackground = styled.div`
`;

interface Props {
subject?: GQLArticleHero_SubjectFragment;
resourceType?: HeroContentType;
metaImage?: GQLArticleHero_MetaImageFragment;
breadcrumbItems: BreadcrumbType[];
Expand All @@ -62,7 +61,7 @@ const StyledSection = styled.section`
z-index: ${stackOrder.offsetSingle};
`;

const ArticleHero = ({ resourceType, metaImage, subject, breadcrumbItems }: Props) => {
const ArticleHero = ({ resourceType, metaImage, breadcrumbItems }: Props) => {
const ndlaFilm = useIsNdlaFilm();
return (
<WrapperComponent ndlaFilm={ndlaFilm} resourceType={resourceType} metaImage={metaImage}>
Expand All @@ -74,7 +73,7 @@ const ArticleHero = ({ resourceType, metaImage, subject, breadcrumbItems }: Prop
<OneColumn>
<HeroContent data-image={!!(ndlaFilm && metaImage?.url)}>
<StyledSection>
{subject && <HomeBreadcrumb light={ndlaFilm ? true : undefined} items={breadcrumbItems} />}
{<HomeBreadcrumb light={ndlaFilm ? true : undefined} items={breadcrumbItems} />}
</StyledSection>
</HeroContent>
</OneColumn>
Expand All @@ -83,11 +82,6 @@ const ArticleHero = ({ resourceType, metaImage, subject, breadcrumbItems }: Prop
};

ArticleHero.fragments = {
subject: gql`
fragment ArticleHero_Subject on Subject {
id
}
`,
metaImage: gql`
fragment ArticleHero_MetaImage on MetaImage {
url
Expand Down

0 comments on commit 9754056

Please sign in to comment.