Skip to content

Commit

Permalink
🚀 Update myst
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanc1 committed Oct 18, 2024
1 parent d71e179 commit 8ffb5de
Show file tree
Hide file tree
Showing 22 changed files with 6,500 additions and 4,849 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: CI

on:
push:
branches: [main, ci-*]
pull_request:
branches: [main]

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 2
submodules: recursive
- name: Use Node.js 18.x
uses: actions/setup-node@v3
with:
node-version: 18.x
- run: npm install
working-directory: theme
- run: npm run lint:format
working-directory: theme
- run: npm run lint
working-directory: theme
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 2
submodules: recursive
- name: Use Node.js 18.x
uses: actions/setup-node@v3
with:
node-version: 18.x
- run: npm install
working-directory: theme
- run: npm run compile # check the types of the site and themes
working-directory: theme
4 changes: 4 additions & 0 deletions theme/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
root: true,
extends: ['curvenote'],
};
4 changes: 0 additions & 4 deletions theme/.eslintrc.js

This file was deleted.

7 changes: 7 additions & 0 deletions theme/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"singleQuote": true,
"trailingComma": "all",
"printWidth": 100,
"semi": true,
"tabWidth": 2
}
2 changes: 1 addition & 1 deletion theme/app/components/ArticlePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import type { SiteAction } from 'myst-config';
*/
function combineDownloads(
siteDownloads: SiteAction[] | undefined,
pageFrontmatter: PageLoader['frontmatter']
pageFrontmatter: PageLoader['frontmatter'],
) {
if (pageFrontmatter.downloads) {
return pageFrontmatter.downloads;
Expand Down
2 changes: 0 additions & 2 deletions theme/app/components/Page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
SiteProvider,
TabStateProvider,
UiStateProvider,
useBaseurl,
useSiteManifest,
useThemeTop,
} from '@myst-theme/providers';
Expand Down Expand Up @@ -165,7 +164,6 @@ export function NavigationAndFooter({
export function ArticleWithProviders({
children,
article,
top = DEFAULT_NAV_HEIGHT,
}: {
top?: number;
children: React.ReactNode;
Expand Down
4 changes: 2 additions & 2 deletions theme/app/components/TopNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function NavItem({ item }: { item: SiteNavItem }) {
'inline-flex items-center justify-center w-full mx-2 py-1 text-md font-medium text-black dark:text-white focus:outline-none focus-visible:ring-2 focus-visible:ring-white focus-visible:ring-opacity-75',
{
'border-b border-stone-200': isActive,
}
},
)
}
>
Expand Down Expand Up @@ -115,7 +115,7 @@ function NavItem({ item }: { item: SiteNavItem }) {
' block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100 hover:text-black ',
{
'text-black font-bold': isActive,
}
},
)
}
>
Expand Down
2 changes: 1 addition & 1 deletion theme/app/entry.client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function hydrate() {
document,
<StrictMode>
<RemixBrowser />
</StrictMode>
</StrictMode>,
);
});
}
Expand Down
16 changes: 7 additions & 9 deletions theme/app/entry.server.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
import type { EntryContext } from "@remix-run/node";
import { RemixServer } from "@remix-run/react";
import { renderToString } from "react-dom/server";
import type { EntryContext } from '@remix-run/node';
import { RemixServer } from '@remix-run/react';
import { renderToString } from 'react-dom/server';

export default function handleRequest(
request: Request,
responseStatusCode: number,
responseHeaders: Headers,
remixContext: EntryContext
remixContext: EntryContext,
) {
const markup = renderToString(
<RemixServer context={remixContext} url={request.url} />
);
const markup = renderToString(<RemixServer context={remixContext} url={request.url} />);

responseHeaders.set("Content-Type", "text/html");
responseHeaders.set('Content-Type', 'text/html');

return new Response("<!DOCTYPE html>" + markup, {
return new Response('<!DOCTYPE html>' + markup, {
headers: responseHeaders,
status: responseStatusCode,
});
Expand Down
4 changes: 1 addition & 3 deletions theme/app/root.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import type { LinksFunction, V2_MetaFunction, LoaderFunction } from '@remix-run/node';
import tailwind from '~/styles/app.css';
import { getConfig } from '~/utils/loaders.server';
import type { SiteLoader } from '@myst-theme/common';
import {
App,
responseNoSite,
getMetaTagsForSite,
getThemeSession,
KatexCSS,
} from '@myst-theme/site';
export { AppCatchBoundary as CatchBoundary } from '@myst-theme/site';

export const meta: V2_MetaFunction = ({ data }) => {
return getMetaTagsForSite({
Expand All @@ -26,7 +24,7 @@ export const links: LinksFunction = () => {
];
};

export const loader: LoaderFunction = async ({ request }): Promise<SiteLoader> => {
export const loader: LoaderFunction = async ({ request }) => {
const [config, themeSession] = await Promise.all([
getConfig('overview').catch(() => null),
getThemeSession(request),
Expand Down
4 changes: 2 additions & 2 deletions theme/app/routes/$project.$slug[.json].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ function api404(message = 'No API route found at this URL') {
status: 404,
message,
},
{ status: 404 }
{ status: 404 },
);
}

export const loader: LoaderFunction = async ({ request, params }) => {
export const loader: LoaderFunction = async ({ params }) => {
const { project, slug } = params;
const data = await getPage({ name: project as string, slug }).catch(() => null);
if (!data) return api404('No page found at this URL.');
Expand Down
9 changes: 7 additions & 2 deletions theme/app/routes/$project.($slug).tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const meta: V2_MetaFunction = ({ data, location }) => {
});
};

export const loader: LoaderFunction = async ({ params, request }) => {
export const loader: LoaderFunction = async ({ params }) => {
const { project, slug } = params;
const page = await getPage({ name: project as string, slug });
return page;
Expand Down Expand Up @@ -76,7 +76,12 @@ export default function Page() {
className="sticky z-10 hidden h-0 pt-5 ml-10 col-margin-right lg:block"
style={{ top }}
>
<DocumentOutline top={16} className="relative lg:block" outlineRef={outline} />
<DocumentOutline
top={16}
className="relative lg:block"
outlineRef={outline}
isMargin={false}
/>
</div>
<ArticlePage article={article} />
</ArticleWithProviders>
Expand Down
2 changes: 1 addition & 1 deletion theme/app/routes/$project.[sitemap.xml].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ export const loader: LoaderFunction = async ({ params, request }): Promise<Respo
if (!config) return new Response('Project not found', { status: 404 });
return createSitemapResponse(
getDomainFromRequest(request),
getSiteSlugs(config).map((s) => `/${project}${s}`)
getSiteSlugs(config).map((s) => `/${project}${s}`),
);
};
8 changes: 3 additions & 5 deletions theme/app/routes/$project.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import type { LinksFunction, LoaderFunction } from '@remix-run/node';
import type { SiteLoader } from '@myst-theme/common';
import { KatexCSS, responseNoSite } from '@myst-theme/site';
import { Outlet, useLoaderData, useParams } from '@remix-run/react';
import { NavigationAndFooter } from '../components/Page';
import { getConfig } from '../utils/loaders.server';
import { BaseUrlProvider, SiteProvider, useSiteManifest } from '@myst-theme/providers';
import { Error404 } from '../components/Error404';
import type { SiteManifest } from 'myst-config';

type ArticleConfig = Omit<SiteLoader, 'theme'>;

export const loader: LoaderFunction = async ({ params, request }): Promise<ArticleConfig> => {
export const loader: LoaderFunction = async ({ params }) => {
const { project } = params;
if (!project) throw responseNoSite();
const [config] = await Promise.all([getConfig(project).catch(() => null)]);
Expand All @@ -23,7 +21,7 @@ export const links: LinksFunction = () => [KatexCSS];
export default function LandingPage() {
const siteConfig = useSiteManifest();
const { project } = useParams();
const { config } = useLoaderData<ArticleConfig>();
const { config } = useLoaderData<{ config: SiteManifest }>();
return (
<BaseUrlProvider baseurl={`/${project}`}>
<SiteProvider config={config}>
Expand Down
4 changes: 2 additions & 2 deletions theme/app/routes/$project[.json].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ function api404(message = 'No API route found at this URL') {
status: 404,
message,
},
{ status: 404 }
{ status: 404 },
);
}

export const loader: LoaderFunction = async ({ request, params }) => {
export const loader: LoaderFunction = async ({ params }) => {
const { project } = params;
const data = await getPage({ name: project as string }).catch(() => null);
if (!data) return api404('No page found at this URL.');
Expand Down
2 changes: 1 addition & 1 deletion theme/app/routes/_index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const meta: V2_MetaFunction = ({ data, location }) => {

export const links: LinksFunction = () => [KatexCSS];

export const loader: LoaderFunction = async ({ request }) => {
export const loader: LoaderFunction = async () => {
return getPage({ name: 'overview' });
};

Expand Down
4 changes: 2 additions & 2 deletions theme/app/routes/overview.$slug[.json].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ function api404(message = 'No API route found at this URL') {
status: 404,
message,
},
{ status: 404 }
{ status: 404 },
);
}

export const loader: LoaderFunction = async ({ request, params }) => {
export const loader: LoaderFunction = async ({ params }) => {
const { slug } = params;
const data = await getPage({ name: 'overview', slug }).catch(() => null);
if (!data) return api404('No page found at this URL.');
Expand Down
2 changes: 1 addition & 1 deletion theme/app/routes/overview.($slug).tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const meta: V2_MetaFunction = ({ data, location }) => {
});
};

export const loader: LoaderFunction = async ({ params, request }) => {
export const loader: LoaderFunction = async ({ params }) => {
const { slug } = params;
const page = await getPage({ name: 'overview', slug });
return page;
Expand Down
2 changes: 1 addition & 1 deletion theme/app/routes/overview.[sitemap.xml].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createSitemapResponse, getSiteSlugs, getDomainFromRequest } from '@myst
import type { LoaderFunction } from '@remix-run/node';
import { getConfig } from '~/utils/loaders.server';

export const loader: LoaderFunction = async ({ params, request }): Promise<Response> => {
export const loader: LoaderFunction = async ({ request }) => {
const project = 'overview';
if (!project) return new Response('Project not found', { status: 404 });
const config = await getConfig(project).catch(() => null);
Expand Down
12 changes: 6 additions & 6 deletions theme/app/routes/sandbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { json } from '@remix-run/node';
import { isRouteErrorResponse, useLoaderData, useRouteError } from '@remix-run/react';
import { useEffect, useState } from 'react';

export const meta: V2_MetaFunction<typeof loader> = (args) => {
export const meta: V2_MetaFunction = (args) => {
return getMetaTagsForArticle({
origin: '',
url: args.location.pathname,
Expand All @@ -20,7 +20,7 @@ export const meta: V2_MetaFunction<typeof loader> = (args) => {
// https://developer.mozilla.org/en-US/docs/Web/API/btoa#unicode_strings
function fromBinary(binary: string) {
const bytes = Uint8Array.from({ length: binary.length }, (element, index) =>
binary.charCodeAt(index)
binary.charCodeAt(index),
);
const charCodes = new Uint16Array(bytes.buffer);

Expand All @@ -33,7 +33,7 @@ function fromBinary(binary: string) {

function toBinary(string: string) {
const codeUnits = Uint16Array.from({ length: string.length }, (element, index) =>
string.charCodeAt(index)
string.charCodeAt(index),
);
const charCodes = new Uint8Array(codeUnits.buffer);

Expand Down Expand Up @@ -139,12 +139,12 @@ export default function ContentPage() {
const { data, tab } = useLoaderData();

const copy = () => {
const tab = Array(...document.getElementsByTagName('button'))
const whichTab = Array(...document.getElementsByTagName('button'))
.filter((el) => el.ariaPressed === 'true')[0]
.innerText.toLowerCase();
const encoded = btoa(toBinary(document.getElementsByTagName('textarea')[0].value));
const params = new URLSearchParams(location.search);
params.set('tab', tab);
params.set('tab', whichTab);
params.set('myst', encoded);
window.history.replaceState({}, '', `${location.pathname}?${params}`);
navigator.clipboard.writeText(window.location.href).then(() => {
Expand All @@ -158,7 +158,7 @@ export default function ContentPage() {
setTimeout(() =>
Array(...document.getElementsByTagName('button'))
.find((el) => el.innerText.toLowerCase() === tab)
?.click()
?.click(),
);
}, [tab]);

Expand Down
Loading

0 comments on commit 8ffb5de

Please sign in to comment.