Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(website): Upgrade dependencies and use StarlightPage component #1854

Merged
merged 9 commits into from
Feb 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4,212 changes: 1,823 additions & 2,389 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

49 changes: 8 additions & 41 deletions website/astro.config.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,10 @@
import { netlifyStatic } from "@astrojs/netlify";
import netlify from "@astrojs/netlify";
import react from "@astrojs/react";
import starlight from "@astrojs/starlight";
import { defineConfig } from "astro/config";
import { h } from "hastscript";
import { escape as htmlEscape } from "html-escaper";
import rehypeAutolinkHeadings from "rehype-autolink-headings";
import rehypeSlug from "rehype-slug";
import remarkToc from "remark-toc";

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we weren't using "remark-toc" anywhere, so I've removed it. Also, did the same for @astrojs/vercel, which isn't being used anymore.

const anchorLinkIcon = h(
"span",
{ ariaHidden: "true", class: "anchor-icon" },
h(
"svg",
{ width: 16, height: 16, viewBox: "0 0 24 24" },
h("path", {
fill: "currentcolor",
d: "m12.11 15.39-3.88 3.88a2.52 2.52 0 0 1-3.5 0 2.47 2.47 0 0 1 0-3.5l3.88-3.88a1 1 0 0 0-1.42-1.42l-3.88 3.89a4.48 4.48 0 0 0 6.33 6.33l3.89-3.88a1 1 0 1 0-1.42-1.42Zm8.58-12.08a4.49 4.49 0 0 0-6.33 0l-3.89 3.88a1 1 0 0 0 1.42 1.42l3.88-3.88a2.52 2.52 0 0 1 3.5 0 2.47 2.47 0 0 1 0 3.5l-3.88 3.88a1 1 0 1 0 1.42 1.42l3.88-3.89a4.49 4.49 0 0 0 0-6.33ZM8.83 15.17a1 1 0 0 0 1.1.22 1 1 0 0 0 .32-.22l4.92-4.92a1 1 0 0 0-1.42-1.42l-4.92 4.92a1 1 0 0 0 0 1.42Z",
}),
),
);

const anchorLinkSRLabel = (text: string) =>
h(
"span",
{ "is:raw": true, class: "sr-only" },
`Section titled ${htmlEscape(text)}`,
);

const autolinkConfig = {
properties: { class: "anchor-link" },
behavior: "after",
group: ({ tagName }) =>
h("div", { tabIndex: -1, class: `heading-wrapper level-${tagName}` }),
content: ({ heading }) => [anchorLinkIcon, anchorLinkSRLabel("test")],
};
import { searchForWorkspaceRoot } from "vite";
import { rehypeAutolink } from "./plugins/rehype-autolink";

const site = "https://biomejs.dev";
// https://astro.build/config
Expand All @@ -44,10 +14,6 @@ export default defineConfig({

compressHTML: true,

image: {
domains: ["avatars.githubusercontent.com"],
},

integrations: [
react(),
starlight({
Expand Down Expand Up @@ -397,11 +363,12 @@ export default defineConfig({

markdown: {
syntaxHighlight: "prism",
remarkPlugins: [remarkToc],
rehypePlugins: [rehypeSlug, [rehypeAutolinkHeadings, autolinkConfig]],
rehypePlugins: [rehypeSlug, ...rehypeAutolink()],
},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the unified project had breaking changes, we now have some weird behavior clashing issue when trying to apply the remarkAutolink plugin, had to move it to an external file to make it work properly.


adapter: netlifyStatic(),
adapter: netlify({
imageCDN: false,
}),

vite: {
resolve: {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason Vite is complaining about some imported code by Astro's DevToolbar. Supposedly vite.server.fs.allow the path used should fix it, but didn't work for me.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have to disable their remote image service, because they don't support multiple remote image domains from the config file. Their alternative is to use another configuration file

Copy link
Contributor Author

@yanthomasdev yanthomasdev Feb 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There we go, the vite.server.fs.allow issue should be fixed, Vite now has a utility to allow workspace packages to be served, which fixes the issue with serving files from dependencies.

Expand All @@ -418,7 +385,7 @@ export default defineConfig({
server: {
fs: {
// https://vitejs.dev/config/server-options.html#server-fs-allow
allow: [process.cwd(), "../packages/@biomejs/wasm-web"],
allow: [searchForWorkspaceRoot(process.cwd())],
},
},
},
Expand Down
63 changes: 31 additions & 32 deletions website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,58 +16,57 @@
"textlint:fix": "textlint --fix './src/content/docs/ja/**/*.{md,mdx}'"
},
"devDependencies": {
"@astrojs/netlify": "^3.0.4",
"@astrojs/prism": "^2.1.2",
"@astrojs/react": "^2.3.2",
"@astrojs/rss": "^2.4.4",
"@astrojs/starlight": "^0.13.0",
"@astrojs/vercel": "^5.0.1",
"@astrojs/netlify": "^5.1.2",
"@astrojs/prism": "^3.0.0",
"@astrojs/react": "^3.0.10",
"@astrojs/rss": "^4.0.5",
"@astrojs/starlight": "^0.19.0",
"@biomejs/wasm-web": "link:../packages/@biomejs/wasm-web",
"@codemirror/lang-javascript": "6.1.8",
"@codemirror/lang-json": "6.0.1",
"@codemirror/lint": "6.2.1",
"@codemirror/state": "6.2.1",
"@codemirror/view": "6.12.0",
"@codemirror/lang-javascript": "^6.2.1",
"@codemirror/lang-json": "^6.0.1",
"@codemirror/lint": "^6.5.0",
"@codemirror/state": "^6.4.0",
"@codemirror/view": "^6.24.0",
"@docsearch/css": "^3.5.2",
"@docsearch/js": "^3.5.2",
"@fontsource/inter": "^4.5.15",
"@types/node": "^18.18.0",
"@types/react": "^18.2.23",
"@types/react-dom": "^18.2.8",
"@uiw/react-codemirror": "4.20.2",
"@types/node": "^18.19.17",
"@types/react": "^18.2.56",
"@types/react-dom": "^18.2.19",
"@uiw/react-codemirror": "^4.21.22",
"@vitejs/plugin-react": "^4.2.1",
"autoprefixer": "^10.4.16",
"codemirror-lang-rome-ast": "0.0.6",
"autoprefixer": "^10.4.17",
"codemirror-lang-rome-ast": "^0.0.6",
"fast-diff": "^1.3.0",
"hast-util-to-html": "^8.0.4",
"hastscript": "^8.0.0",
"hast-util-to-html": "^9.0.0",
"hast-util-to-string": "^3.0.0",
"hastscript": "^9.0.0",
"html-escaper": "^3.0.3",
"lang-rome-formatter-ir": "0.0.2",
"mdast-util-to-hast": "^12.3.0",
"mdast-util-to-hast": "^13.1.0",
"mermaid": "^9.4.3",
"postcss": "^8.4.30",
"prettier": "^3.1.0",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"rehype-autolink-headings": "^6.1.1",
"rehype-slug": "^5.1.0",
"rehype-toc": "^3.0.2",
"remark-toc": "^8.0.1",
"postcss": "^8.4.35",
"prettier": "^3.2.5",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Comment on lines +50 to +51
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the playground doesn't work anymore. Unless you want to spend time understanding the issue, maybe we can revert the change

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue doesn't seem related to updating the React dependencies, reverting them doesn't fix, nor does loading the Playground without <StarlightPage> - my best guess it might be Vite-related? But hard to know without context on how the Playground was built.

"rehype-autolink-headings": "^7.1.0",
"rehype-slug": "^6.0.0",
"remark-toc": "^9.0.0",
"rollup": "^3.29.4",
"sass": "^1.68.0",
"sass": "^1.71.0",
"sharp": "^0.32.6",
"textlint": "^13.4.1",
"textlint-rule-preset-jtf-style": "^2.3.13",
"textlint-rule-preset-jtf-style": "^2.3.14",
"textlint-rule-prh": "^5.3.0",
"typescript": "^5.2.2",
"typescript": "^5.3.3",
"vite": "5.0.10",
"vite-plugin-svgr": "^4.2.0"
},
"engines": {
"pnpm": "^8.0.0"
},
"dependencies": {
"astro": "^3.6.0",
"astro": "^4.4.0",
"astro-og-canvas": "^0.4.2",
"canvaskit-wasm": "^0.39.1"
}
Expand Down
43 changes: 43 additions & 0 deletions website/plugins/rehype-autolink.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import type { RehypePlugins } from "astro";
import { toString as hastToString } from "hast-util-to-string";
import { h } from "hastscript";
import { escape as htmlEscape } from "html-escaper";
import rehypeAutolinkHeadings from "rehype-autolink-headings";

const anchorLinkIcon = h(
"span",
{ ariaHidden: "true", class: "anchor-icon" },
h(
"svg",
{ width: 16, height: 16, viewBox: "0 0 24 24" },
h("path", {
fill: "currentcolor",
d: "m12.11 15.39-3.88 3.88a2.52 2.52 0 0 1-3.5 0 2.47 2.47 0 0 1 0-3.5l3.88-3.88a1 1 0 0 0-1.42-1.42l-3.88 3.89a4.48 4.48 0 0 0 6.33 6.33l3.89-3.88a1 1 0 1 0-1.42-1.42Zm8.58-12.08a4.49 4.49 0 0 0-6.33 0l-3.89 3.88a1 1 0 0 0 1.42 1.42l3.88-3.88a2.52 2.52 0 0 1 3.5 0 2.47 2.47 0 0 1 0 3.5l-3.88 3.88a1 1 0 1 0 1.42 1.42l3.88-3.89a4.49 4.49 0 0 0 0-6.33ZM8.83 15.17a1 1 0 0 0 1.1.22 1 1 0 0 0 .32-.22l4.92-4.92a1 1 0 0 0-1.42-1.42l-4.92 4.92a1 1 0 0 0 0 1.42Z",
}),
),
);

const anchorLinkSRLabel = (text: string) =>
h(
"span",
{ "is:raw": true, class: "sr-only" },
`Section titled ${htmlEscape(text)}`,
);

const autolinkConfig = {
properties: { class: "anchor-link" },
behavior: "after",
group: ({ tagName }) =>
h("div", {
tabIndex: -1,
class: `heading-wrapper level-${tagName}`,
}),
content: (heading) => [
anchorLinkIcon,
anchorLinkSRLabel(hastToString(heading)),
],
};

export const rehypeAutolink = (): RehypePlugins => [
[rehypeAutolinkHeadings, autolinkConfig],
];
3 changes: 2 additions & 1 deletion website/src/components/InlineSVG.astro
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ export interface Props {
const { src } = Astro.props as Props;

const files = await import.meta.glob<string>("/src/assets/svg/**/*.svg", {
as: "raw",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as: "raw" was deprecated in Vite, so I've replaced it for the recommended query: "?raw"

query: "?raw",
import: "default",
});

const path = `/src/assets/svg/${src}.svg`;
Expand Down
129 changes: 0 additions & 129 deletions website/src/layouts/StarlightSplashLayout.astro

This file was deleted.

19 changes: 11 additions & 8 deletions website/src/pages/blog/[...slug].astro
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
import { getCollection, type CollectionEntry } from "astro:content";
import BlogLayout from "@/layouts/Blog.astro";
import StarlightSplashLayout from "@/layouts/StarlightSplashLayout.astro";
import StarlightPage from "@astrojs/starlight/components/StarlightPage.astro";
import { getImage } from "astro:assets";

export async function getStaticPaths() {
Expand Down Expand Up @@ -45,14 +45,17 @@ const head = [
];
---

<StarlightSplashLayout
title={post.title}
description={post.description}
slug={entry.slug}
head={head}
editUrl={`https://github.com/biomejs/biome/edit/main/website/src/content/blog/${entry.id}`}
<StarlightPage
frontmatter={{
title: post.title,
description: post.description,
slug: entry.slug,
head: head,
template: "splash",
editUrl: `https://github.com/biomejs/biome/edit/main/website/src/content/blog/${entry.id}`,
}}
>
<BlogLayout post={post}>
<Content />
</BlogLayout>
</StarlightSplashLayout>
</StarlightPage>
Loading
Loading