diff --git a/.changeset/silver-fans-wave.md b/.changeset/silver-fans-wave.md new file mode 100644 index 000000000..86453275c --- /dev/null +++ b/.changeset/silver-fans-wave.md @@ -0,0 +1,5 @@ +--- +'myst-to-react': patch +--- + +Add ROR hover links diff --git a/package-lock.json b/package-lock.json index 8b593bf7b..b426b7279 100644 --- a/package-lock.json +++ b/package-lock.json @@ -39665,6 +39665,7 @@ "@heroicons/react": "^2.0.18", "@myst-theme/providers": "^0.9.2", "@radix-ui/react-hover-card": "^1.0.6", + "@scienceicons/react": "^0.0.6", "buffer": "^6.0.3", "classnames": "^2.3.2", "myst-common": "^1.4.0", diff --git a/packages/myst-to-react/package.json b/packages/myst-to-react/package.json index 7a5484f32..ef956a1db 100644 --- a/packages/myst-to-react/package.json +++ b/packages/myst-to-react/package.json @@ -22,6 +22,7 @@ "dependencies": { "@heroicons/react": "^2.0.18", "@myst-theme/providers": "^0.9.2", + "@scienceicons/react": "^0.0.6", "@radix-ui/react-hover-card": "^1.0.6", "buffer": "^6.0.3", "classnames": "^2.3.2", diff --git a/packages/myst-to-react/src/links/index.tsx b/packages/myst-to-react/src/links/index.tsx index 5c1aec3ad..e6c7a370e 100644 --- a/packages/myst-to-react/src/links/index.tsx +++ b/packages/myst-to-react/src/links/index.tsx @@ -9,6 +9,7 @@ import type { NodeRenderer } from '@myst-theme/providers'; import { HoverPopover, LinkCard } from '../components/index.js'; import { WikiLink } from './wiki.js'; import { RRIDLink } from './rrid.js'; +import { RORLink } from './ror.js'; import { GithubLink } from './github.js'; import { MyST } from '../MyST.js'; @@ -83,6 +84,8 @@ export const link: NodeRenderer = ({ node }) => { ); case 'rrid': return ; + case 'ror': + return ; default: if (internal) { return ( diff --git a/packages/myst-to-react/src/links/ror.tsx b/packages/myst-to-react/src/links/ror.tsx new file mode 100644 index 000000000..6a8b1bcc0 --- /dev/null +++ b/packages/myst-to-react/src/links/ror.tsx @@ -0,0 +1,93 @@ +import { default as useSWR } from 'swr'; +import { HoverPopover } from '../components/index.js'; +import { MyST } from '../MyST.js'; +import type { GenericNode } from 'myst-common'; +import { RorIcon } from '@scienceicons/react/24/solid'; + +const fetcher = (...args: Parameters) => + fetch(...args).then((res) => { + if (res.status === 200) return res.json(); + throw new Error(`Content returned with status ${res.status}.`); + }); + +function RORChild({ ror }: { ror: string }) { + const { data, error } = useSWR(`https://api.ror.org/organizations/${ror}`, fetcher); + if (!data && !error) { + return ( +
+ Loading... +
+ ); + } + if (error) { + return ( +
Error loading {ror}.
+ ); + } + const country_name = data?.country?.country_name; + const basicLinks = + (data?.links.map((url: string) => ({ url })) as { url: string; text?: string }[]) ?? []; + const wikiLink = data.wikipedia_url + ? [{ text: 'Wikipedia', url: data.wikipedia_url as string }] + : []; + const links = [...basicLinks, ...wikiLink]; + return ( +
+

+ + + {ror} + +

+
{data.name}
+
+
Country
+
{country_name}
+ {links.length > 0 && ( + <> +
Links
+ {links.map(({ url, text }) => ( +
+ {text || url} +
+ ))} + + )} + {data.acronyms?.length > 0 && ( + <> +
Acronyms
+ {data.acronyms.map((text: string) => ( +
{text}
+ ))} + + )} + {data.labels?.length > 0 && ( + <> +
Labels
+ {data.labels.map(({ label, iso639 }: { label: string; iso639?: string }) => ( +
+ {label} + {iso639 ? ` (${iso639})` : null} +
+ ))} + + )} +
+
+ ); +} + +export function RORLink({ node, ror }: { node: GenericNode; ror: string }) { + return ( + }> + + + + + ); +}