Skip to content

Commit 6590509

Browse files
committed
Pass articletext to metadescription
1 parent 6527a03 commit 6590509

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/containers/ArticlePage/LearningResourcePage/components/LearningResourcePanels.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ interface Props {
3838
contexts?: TaxonomyContext[];
3939
}
4040

41+
const getTextFromHTML = (html: string) => {
42+
const parser = new DOMParser();
43+
const doc = parser.parseFromString(html, "text/html");
44+
return doc.body.textContent || "";
45+
};
46+
4147
const LearningResourcePanels = ({
4248
article,
4349
articleHistory,
@@ -58,6 +64,11 @@ const LearningResourcePanels = ({
5864
);
5965
const copyrightFields = useMemo<FlatArticleKeys[]>(() => ["copyright"], []);
6066

67+
const articleText = useMemo(() => {
68+
if (!article?.content) return " ";
69+
return getTextFromHTML(article.content.content);
70+
}, [article?.content]);
71+
6172
return (
6273
<FormAccordionsWithComments
6374
defaultOpen={defaultOpen}
@@ -116,7 +127,7 @@ const LearningResourcePanels = ({
116127
title={t("form.metadataSection")}
117128
hasError={!!(errors.metaDescription || errors.metaImageAlt || errors.tags)}
118129
>
119-
<MetaDataField articleLanguage={articleLanguage} />
130+
<MetaDataField articleContent={articleText} articleLanguage={articleLanguage} />
120131
</FormAccordion>
121132
<FormAccordion id={"learning-resource-grepCodes"} title={t("form.name.grepCodes")} hasError={!!errors.grepCodes}>
122133
<GrepCodesField />

src/containers/FormikForm/MetaDataField.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import { useSession } from "../Session/SessionProvider";
4545

4646
interface Props {
4747
articleLanguage: string;
48+
articleContent?: string;
4849
showCheckbox?: boolean;
4950
checkboxAction?: (image: IImageMetaInformationV3) => void;
5051
}
@@ -57,7 +58,7 @@ const StyledButton = styled(Button, {
5758
},
5859
});
5960

60-
const MetaDataField = ({ articleLanguage, showCheckbox, checkboxAction }: Props) => {
61+
const MetaDataField = ({ articleLanguage, articleContent, showCheckbox, checkboxAction }: Props) => {
6162
const { t } = useTranslation();
6263
const [isLoading, setIsLoading] = useState(false);
6364
const { userPermissions } = useSession();

0 commit comments

Comments
 (0)