generated from ConductionNL/product-website-template
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #148 from ConductionNL/feature/XW-103/Markdown-page
feature/XW-103/Markdown-page
- Loading branch information
Showing
37 changed files
with
834 additions
and
10 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,17 @@ | ||
import { TSendFunction } from "../apiService"; | ||
import { AxiosInstance } from "axios"; | ||
|
||
export default class Markdown { | ||
private _instance: AxiosInstance; | ||
private _send: TSendFunction; | ||
constructor(_instance: AxiosInstance, send: TSendFunction) { | ||
this._instance = _instance; | ||
this._send = send; | ||
} | ||
|
||
public getContent = async (filePath: string): Promise<any> => { | ||
const { data } = await this._send(this._instance, "GET", filePath); | ||
|
||
return data; | ||
}; | ||
} |
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,17 @@ | ||
.container { | ||
margin-block-start: var(--utrecht-space-block-3xl); | ||
} | ||
|
||
.container > div > article > *:not(:last-child), | ||
.backLink { | ||
margin-block-end: var(--utrecht-space-block-lg); | ||
} | ||
|
||
.backLink:hover { | ||
cursor: pointer; | ||
} | ||
|
||
.backLink { | ||
display: flex; | ||
align-items: center; | ||
} |
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,85 @@ | ||
import * as React from "react"; | ||
import * as styles from "./ParsedHTML.module.css"; | ||
import Parser from "html-react-parser"; | ||
import Skeleton from "react-loading-skeleton"; | ||
import clsx from "clsx"; | ||
import showdown from "showdown"; | ||
import { Alert } from "@utrecht/component-library-react/dist/css-module"; | ||
import { UseQueryResult } from "react-query"; | ||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; | ||
import { faArrowLeft, faWarning } from "@fortawesome/free-solid-svg-icons"; | ||
import { useHtmlParser } from "../../hooks/htmlParser/useHtmlParser"; | ||
import { isHtml } from "../../services/isHtml"; | ||
import { Link } from "@utrecht/component-library-react/dist/css-module"; | ||
import { navigate } from "gatsby"; | ||
import { useTranslation } from "react-i18next"; | ||
|
||
interface ParsedHTMLProps { | ||
contentQuery: UseQueryResult<any, Error>; | ||
location: string; | ||
layoutClassName?: string; | ||
} | ||
|
||
export const ParsedHTML: React.FC<ParsedHTMLProps> = ({ contentQuery, location, layoutClassName }) => { | ||
const { t } = useTranslation(); | ||
const { options } = useHtmlParser(location); | ||
let htmlContent; | ||
|
||
showdown.setFlavor("github"); | ||
|
||
if (!isHtml(contentQuery.data)) { | ||
const converter = new showdown.Converter(); | ||
htmlContent = `<div><article class="markdown-body entry-content container-lg" itemprop="text">${converter.makeHtml( | ||
contentQuery.data, | ||
)}</article></div>`; | ||
} | ||
if (isHtml(contentQuery.data)) { | ||
htmlContent = contentQuery.data; | ||
} | ||
|
||
if (contentQuery.isLoading) | ||
return ( | ||
<div className={styles.container}> | ||
<Skeleton height="200px" /> | ||
</div> | ||
); | ||
|
||
if (contentQuery.isError) | ||
return ( | ||
<div className={styles.container}> | ||
<div> | ||
<Link | ||
className={styles.backLink} | ||
href="/" | ||
onClick={(e: any) => { | ||
e.preventDefault(), navigate("/"); | ||
}} | ||
tabIndex={0} | ||
> | ||
<FontAwesomeIcon icon={faArrowLeft} /> <span>{t("Back to homepage")}</span> | ||
</Link> | ||
</div> | ||
<Alert icon={<FontAwesomeIcon icon={faWarning} />} type="error"> | ||
Oops, something went wrong retrieving the .md file from GitHub. | ||
</Alert> | ||
</div> | ||
); | ||
|
||
return ( | ||
<div className={clsx(styles.container, layoutClassName && layoutClassName)}> | ||
<div> | ||
<Link | ||
className={styles.backLink} | ||
href="/" | ||
onClick={(e: any) => { | ||
e.preventDefault(), navigate("/"); | ||
}} | ||
tabIndex={0} | ||
> | ||
<FontAwesomeIcon icon={faArrowLeft} /> <span>{t("Back to homepage")}</span> | ||
</Link> | ||
</div> | ||
{Parser(htmlContent, options)} | ||
</div> | ||
); | ||
}; |
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,28 @@ | ||
.info svg { | ||
fill: var(--utrecht-alert-icon-info-color); | ||
} | ||
.info p { | ||
color: var(--utrecht-alert-info-color); | ||
} | ||
|
||
.warning svg { | ||
fill: var(--utrecht-alert-icon-warning-color); | ||
} | ||
.warning p { | ||
color: var(--utrecht-alert-warning-color); | ||
} | ||
|
||
.error svg { | ||
fill: var(--utrecht-alert-icon-error-color); | ||
} | ||
.error p { | ||
color: var(--utrecht-alert-error-color); | ||
} | ||
|
||
.ok svg { | ||
fill: var(--utrecht-alert-icon-ok-color); | ||
} | ||
.ok p { | ||
color: var(--utrecht-alert-ok-color); | ||
} | ||
|
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,34 @@ | ||
import * as styles from "./getAlert.module.css"; | ||
import { Alert } from "@utrecht/component-library-react/dist/css-module"; | ||
import { domToReact } from "html-react-parser"; | ||
|
||
export const getAlert = (children: any, options: any, type: any) => { | ||
switch (true) { | ||
case type.includes("note") || type.includes("info"): | ||
return ( | ||
<Alert className={styles.info} type="info"> | ||
{domToReact(children, options)} | ||
</Alert> | ||
); | ||
case type.includes("error"): | ||
return ( | ||
<Alert className={styles.error} type="error"> | ||
{domToReact(children, options)} | ||
</Alert> | ||
); | ||
case type.includes("warning"): | ||
return ( | ||
<Alert className={styles.warning} type="warning"> | ||
{domToReact(children, options)} | ||
</Alert> | ||
); | ||
case type.includes("succes") || type.includes("ok"): | ||
return ( | ||
<Alert className={styles.ok} type="ok"> | ||
{domToReact(children, options)} | ||
</Alert> | ||
); | ||
default: | ||
return <Alert type="info">{domToReact(children, options)}</Alert>; | ||
} | ||
}; |
Oops, something went wrong.