@myst-theme/site 0.4.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +11 -11
- package/src/components/Bibliography.tsx +4 -2
- package/src/components/ContentBlocks.tsx +3 -1
- package/src/components/DocumentOutline.tsx +22 -1
- package/src/components/FooterLinksBlock.tsx +1 -1
- package/src/components/Headers.tsx +59 -0
- package/src/components/Navigation/TableOfContents.tsx +5 -1
- package/src/components/index.ts +1 -0
- package/src/pages/Article.tsx +33 -2
- package/src/pages/Root.tsx +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@myst-theme/site",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"main": "./src/index.ts",
|
|
5
5
|
"types": "./src/index.ts",
|
|
6
6
|
"files": [
|
|
@@ -16,18 +16,18 @@
|
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"@headlessui/react": "^1.7.15",
|
|
18
18
|
"@heroicons/react": "^2.0.18",
|
|
19
|
-
"@myst-theme/diagrams": "^0.
|
|
20
|
-
"@myst-theme/frontmatter": "^0.
|
|
21
|
-
"@myst-theme/jupyter": "^0.
|
|
22
|
-
"@myst-theme/common": "^0.
|
|
23
|
-
"@myst-theme/providers": "^0.
|
|
19
|
+
"@myst-theme/diagrams": "^0.5.0",
|
|
20
|
+
"@myst-theme/frontmatter": "^0.5.0",
|
|
21
|
+
"@myst-theme/jupyter": "^0.5.0",
|
|
22
|
+
"@myst-theme/common": "^0.5.0",
|
|
23
|
+
"@myst-theme/providers": "^0.5.0",
|
|
24
24
|
"classnames": "^2.3.2",
|
|
25
25
|
"lodash.throttle": "^4.1.1",
|
|
26
|
-
"myst-common": "^1.1.
|
|
27
|
-
"myst-spec-ext": "^1.1.
|
|
28
|
-
"myst-config": "^1.1.
|
|
29
|
-
"myst-demo": "^0.
|
|
30
|
-
"myst-to-react": "^0.
|
|
26
|
+
"myst-common": "^1.1.1",
|
|
27
|
+
"myst-spec-ext": "^1.1.1",
|
|
28
|
+
"myst-config": "^1.1.1",
|
|
29
|
+
"myst-demo": "^0.5.0",
|
|
30
|
+
"myst-to-react": "^0.5.0",
|
|
31
31
|
"nbtx": "^0.2.3",
|
|
32
32
|
"node-cache": "^5.1.2",
|
|
33
33
|
"node-fetch": "^2.6.11",
|
|
@@ -1,17 +1,19 @@
|
|
|
1
|
-
import { useReferences } from '@myst-theme/providers';
|
|
1
|
+
import { useGridSystemProvider, useReferences } from '@myst-theme/providers';
|
|
2
|
+
import classNames from 'classnames';
|
|
2
3
|
import { useState } from 'react';
|
|
3
4
|
|
|
4
5
|
const HIDE_OVER_N_REFERENCES = 5;
|
|
5
6
|
|
|
6
7
|
export function Bibliography() {
|
|
7
8
|
const references = useReferences();
|
|
9
|
+
const grid = useGridSystemProvider();
|
|
8
10
|
const { order, data } = references?.cite ?? {};
|
|
9
11
|
const filtered = order?.filter((l) => l);
|
|
10
12
|
const [hidden, setHidden] = useState(true);
|
|
11
13
|
if (!filtered || !data || filtered.length === 0) return null;
|
|
12
14
|
const refs = hidden ? filtered.slice(0, HIDE_OVER_N_REFERENCES) : filtered;
|
|
13
15
|
return (
|
|
14
|
-
<section className=
|
|
16
|
+
<section className={classNames(grid, 'subgrid-gap col-screen')}>
|
|
15
17
|
<div>
|
|
16
18
|
{filtered.length > HIDE_OVER_N_REFERENCES && (
|
|
17
19
|
<button
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
NotebookRunCell,
|
|
8
8
|
NotebookRunCellSpinnerOnly,
|
|
9
9
|
} from '@myst-theme/jupyter';
|
|
10
|
+
import { useGridSystemProvider } from '@myst-theme/providers';
|
|
10
11
|
|
|
11
12
|
function isACodeCell(node: GenericParent) {
|
|
12
13
|
return (
|
|
@@ -30,7 +31,8 @@ function Block({
|
|
|
30
31
|
node: GenericParent;
|
|
31
32
|
className?: string;
|
|
32
33
|
}) {
|
|
33
|
-
const
|
|
34
|
+
const grid = useGridSystemProvider();
|
|
35
|
+
const subGrid = `${grid} subgrid-gap col-screen`;
|
|
34
36
|
const dataClassName = typeof node.data?.class === 'string' ? node.data?.class : undefined;
|
|
35
37
|
// Hide the subgrid if either the dataClass or the className exists and includes `col-`
|
|
36
38
|
const noSubGrid =
|
|
@@ -70,6 +70,25 @@ const Headings = ({ headings, activeId, highlight, selector }: Props) => (
|
|
|
70
70
|
</ul>
|
|
71
71
|
);
|
|
72
72
|
|
|
73
|
+
function cloneHeadingElement(originalElement: HTMLSpanElement) {
|
|
74
|
+
// Clone the original element
|
|
75
|
+
const clonedElement = originalElement.cloneNode(true) as HTMLSpanElement;
|
|
76
|
+
|
|
77
|
+
// Get all <abbr> elements in the cloned element
|
|
78
|
+
const abbrElements = clonedElement.getElementsByTagName('abbr');
|
|
79
|
+
|
|
80
|
+
// Move children of <abbr> elements to their parent
|
|
81
|
+
for (let i = 0; i < abbrElements.length; i++) {
|
|
82
|
+
const abbr = abbrElements[i];
|
|
83
|
+
const parent = abbr.parentNode as HTMLSpanElement;
|
|
84
|
+
while (abbr.firstChild) {
|
|
85
|
+
parent.insertBefore(abbr.firstChild, abbr);
|
|
86
|
+
}
|
|
87
|
+
parent.removeChild(abbr);
|
|
88
|
+
}
|
|
89
|
+
return clonedElement;
|
|
90
|
+
}
|
|
91
|
+
|
|
73
92
|
function getHeaders(selector: string): HTMLHeadingElement[] {
|
|
74
93
|
const headers = Array.from(document.querySelectorAll(selector)).filter((e) => {
|
|
75
94
|
const parent = e.closest('.exclude-from-outline');
|
|
@@ -135,7 +154,9 @@ function useHeaders(selector: string) {
|
|
|
135
154
|
})
|
|
136
155
|
.filter((h) => !!h.text)
|
|
137
156
|
.map(({ level, text, id }) => {
|
|
138
|
-
const { innerText: title, innerHTML: titleHTML } =
|
|
157
|
+
const { innerText: title, innerHTML: titleHTML } = cloneHeadingElement(
|
|
158
|
+
text as HTMLSpanElement,
|
|
159
|
+
);
|
|
139
160
|
return { title, titleHTML, id, level };
|
|
140
161
|
});
|
|
141
162
|
|
|
@@ -36,7 +36,7 @@ const FooterLink = ({
|
|
|
36
36
|
};
|
|
37
37
|
|
|
38
38
|
export function FooterLinksBlock({ links }: { links?: FooterLinks }) {
|
|
39
|
-
if (!links) return null;
|
|
39
|
+
if (!links || (!links.navigation?.prev && !links.navigation?.next)) return null;
|
|
40
40
|
return (
|
|
41
41
|
<div className="flex pt-10 mb-10 space-x-4">
|
|
42
42
|
{links.navigation?.prev && <FooterLink {...links.navigation?.prev} right />}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import {
|
|
2
|
+
FrontmatterBlock,
|
|
3
|
+
GitHubLink,
|
|
4
|
+
Journal,
|
|
5
|
+
LicenseBadges,
|
|
6
|
+
OpenAccessBadge,
|
|
7
|
+
} from '@myst-theme/frontmatter';
|
|
8
|
+
import { useGridSystemProvider } from '@myst-theme/providers';
|
|
9
|
+
import classNames from 'classnames';
|
|
10
|
+
import type { PageFrontmatter } from 'myst-frontmatter';
|
|
11
|
+
|
|
12
|
+
export function ArticleHeader({ frontmatter }: { frontmatter: PageFrontmatter }) {
|
|
13
|
+
const grid = useGridSystemProvider();
|
|
14
|
+
const { subject, venue, biblio, ...rest } = frontmatter ?? {};
|
|
15
|
+
return (
|
|
16
|
+
<header
|
|
17
|
+
className={classNames('w-full relative pt-[2rem] col-screen article', grid, 'subgrid-gap', {
|
|
18
|
+
'bg-no-repeat bg-cover bg-top': frontmatter?.banner,
|
|
19
|
+
'pb-[4rem] min-h-[300px]': frontmatter?.banner,
|
|
20
|
+
})}
|
|
21
|
+
style={{
|
|
22
|
+
backgroundImage: frontmatter?.banner ? `url(${frontmatter?.banner})` : undefined,
|
|
23
|
+
}}
|
|
24
|
+
>
|
|
25
|
+
{frontmatter?.banner && (
|
|
26
|
+
<div className="absolute border-white shadow-2xl bg-white/80 dark:bg-black/80 backdrop-blur top-[2rem] h-[calc(100%-4rem)] w-full col-screen md:col-screen-inset pointer-events-none"></div>
|
|
27
|
+
)}
|
|
28
|
+
<div
|
|
29
|
+
className={classNames('flex w-full align-middle z-10 py-2 mb-[1rem] text-sm', {
|
|
30
|
+
'col-screen md:col-screen-inset px-4': frontmatter?.banner,
|
|
31
|
+
'col-page-right': !frontmatter?.banner,
|
|
32
|
+
'bg-white/80 dark:bg-black/80': frontmatter?.banner,
|
|
33
|
+
})}
|
|
34
|
+
>
|
|
35
|
+
{subject && (
|
|
36
|
+
<div
|
|
37
|
+
className={classNames('flex-none pr-2 smallcaps', {
|
|
38
|
+
'border-r mr-2': venue,
|
|
39
|
+
})}
|
|
40
|
+
>
|
|
41
|
+
{subject}
|
|
42
|
+
</div>
|
|
43
|
+
)}
|
|
44
|
+
<Journal venue={venue} biblio={biblio} />
|
|
45
|
+
<div className="flex-grow"></div>
|
|
46
|
+
<LicenseBadges license={frontmatter?.license} />
|
|
47
|
+
<OpenAccessBadge open_access={frontmatter?.open_access} />
|
|
48
|
+
<GitHubLink github={frontmatter?.github} />
|
|
49
|
+
</div>
|
|
50
|
+
<FrontmatterBlock
|
|
51
|
+
frontmatter={rest}
|
|
52
|
+
authorStyle="list"
|
|
53
|
+
className={classNames('z-10', { 'pt-4': frontmatter?.banner })}
|
|
54
|
+
hideBadges
|
|
55
|
+
hideExports
|
|
56
|
+
/>
|
|
57
|
+
</header>
|
|
58
|
+
);
|
|
59
|
+
}
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
useSiteManifest,
|
|
9
9
|
useBaseurl,
|
|
10
10
|
withBaseurl,
|
|
11
|
+
useGridSystemProvider,
|
|
11
12
|
} from '@myst-theme/providers';
|
|
12
13
|
import { getProjectHeadings, type Heading } from '@myst-theme/common';
|
|
13
14
|
|
|
@@ -143,6 +144,7 @@ export const TableOfContents = ({
|
|
|
143
144
|
projectSlug?: string;
|
|
144
145
|
footer?: React.ReactNode;
|
|
145
146
|
}) => {
|
|
147
|
+
const grid = useGridSystemProvider();
|
|
146
148
|
const footerRef = useRef<HTMLDivElement>(null);
|
|
147
149
|
const [open] = useNavOpen();
|
|
148
150
|
const config = useSiteManifest();
|
|
@@ -162,7 +164,9 @@ export const TableOfContents = ({
|
|
|
162
164
|
<div
|
|
163
165
|
ref={tocRef}
|
|
164
166
|
className={classNames(
|
|
165
|
-
'fixed
|
|
167
|
+
'fixed',
|
|
168
|
+
`xl:${grid}`, // for example, xl:article-grid
|
|
169
|
+
'grid-gap xl:w-screen xl:pointer-events-none overflow-auto max-xl:min-w-[300px]',
|
|
166
170
|
{ hidden: !open },
|
|
167
171
|
{ 'z-30': open },
|
|
168
172
|
)}
|
package/src/components/index.ts
CHANGED
|
@@ -3,6 +3,7 @@ export { DocumentOutline, useOutlineHeight } from './DocumentOutline';
|
|
|
3
3
|
export { FooterLinksBlock } from './FooterLinksBlock';
|
|
4
4
|
export { ContentReload } from './ContentReload';
|
|
5
5
|
export { Bibliography } from './Bibliography';
|
|
6
|
+
export { ArticleHeader } from './Headers';
|
|
6
7
|
export { ExternalOrInternalLink } from './ExternalOrInternalLink';
|
|
7
8
|
export * from './Navigation';
|
|
8
9
|
export { renderers } from './renderers';
|
package/src/pages/Article.tsx
CHANGED
|
@@ -4,7 +4,7 @@ import { Bibliography, ContentBlocks, FooterLinksBlock } from '../components';
|
|
|
4
4
|
import { ErrorDocumentNotFound } from './ErrorDocumentNotFound';
|
|
5
5
|
import { ErrorProjectNotFound } from './ErrorProjectNotFound';
|
|
6
6
|
import type { PageLoader } from '@myst-theme/common';
|
|
7
|
-
import type
|
|
7
|
+
import { copyNode, extractPart, type GenericParent } from 'myst-common';
|
|
8
8
|
import { SourceFileKind } from 'myst-spec-ext';
|
|
9
9
|
import {
|
|
10
10
|
useComputeOptions,
|
|
@@ -17,18 +17,26 @@ import {
|
|
|
17
17
|
ErrorTray,
|
|
18
18
|
} from '@myst-theme/jupyter';
|
|
19
19
|
import { FrontmatterBlock } from '@myst-theme/frontmatter';
|
|
20
|
+
import classNames from 'classnames';
|
|
20
21
|
|
|
21
22
|
export const ArticlePage = React.memo(function ({
|
|
22
23
|
article,
|
|
23
24
|
hide_all_footer_links,
|
|
25
|
+
showAbstract,
|
|
26
|
+
hideKeywords,
|
|
24
27
|
}: {
|
|
25
28
|
article: PageLoader;
|
|
26
29
|
hide_all_footer_links?: boolean;
|
|
30
|
+
showAbstract?: boolean;
|
|
31
|
+
hideKeywords?: boolean;
|
|
27
32
|
}) {
|
|
28
33
|
const canCompute = useCanCompute(article);
|
|
29
34
|
const { binderBadgeUrl } = useComputeOptions();
|
|
30
35
|
const { hide_title_block, hide_footer_links } = (article.frontmatter as any)?.design ?? {};
|
|
31
36
|
|
|
37
|
+
const tree = copyNode(article.mdast);
|
|
38
|
+
const keywords = article.frontmatter?.keywords ?? [];
|
|
39
|
+
const abstract = showAbstract ? extractPart(tree, 'abstract') : undefined;
|
|
32
40
|
// take binder url from article frontmatter or fallback to project
|
|
33
41
|
const binderUrl = article.frontmatter.binder ?? binderBadgeUrl;
|
|
34
42
|
|
|
@@ -53,7 +61,30 @@ export const ArticlePage = React.memo(function ({
|
|
|
53
61
|
)}
|
|
54
62
|
{canCompute && article.kind === SourceFileKind.Notebook && <NotebookToolbar showLaunch />}
|
|
55
63
|
<ErrorTray pageSlug={article.slug} />
|
|
56
|
-
|
|
64
|
+
{abstract && (
|
|
65
|
+
<>
|
|
66
|
+
<span className="font-semibold">Abstract</span>
|
|
67
|
+
<div className="px-6 py-1 m-3 rounded-sm bg-slate-50 dark:bg-slate-800">
|
|
68
|
+
<ContentBlocks mdast={abstract as GenericParent} className="col-body" />
|
|
69
|
+
</div>
|
|
70
|
+
{!hideKeywords && keywords.length > 0 && (
|
|
71
|
+
<div className="mb-10">
|
|
72
|
+
<span className="mr-2 font-semibold">Keywords:</span>
|
|
73
|
+
{keywords.map((k, i) => (
|
|
74
|
+
<span
|
|
75
|
+
key={k}
|
|
76
|
+
className={classNames({
|
|
77
|
+
"after:content-[','] after:mr-1": i < keywords.length - 1,
|
|
78
|
+
})}
|
|
79
|
+
>
|
|
80
|
+
{k}
|
|
81
|
+
</span>
|
|
82
|
+
))}
|
|
83
|
+
</div>
|
|
84
|
+
)}
|
|
85
|
+
</>
|
|
86
|
+
)}
|
|
87
|
+
<ContentBlocks pageKind={article.kind} mdast={tree as GenericParent} />
|
|
57
88
|
<Bibliography />
|
|
58
89
|
<ConnectionStatusTray />
|
|
59
90
|
{!hide_footer_links && !hide_all_footer_links && (
|
package/src/pages/Root.tsx
CHANGED
|
@@ -92,7 +92,7 @@ export function AppCatchBoundary() {
|
|
|
92
92
|
return (
|
|
93
93
|
<Document theme={Theme.light}>
|
|
94
94
|
<article className="article">
|
|
95
|
-
<main className="article-grid
|
|
95
|
+
<main className="article-grid subgrid-gap col-screen">
|
|
96
96
|
<Error404 />
|
|
97
97
|
</main>
|
|
98
98
|
</article>
|