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

chore: improve headings #626

Merged
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
13 changes: 13 additions & 0 deletions next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import remarkHeadingId from "remark-custom-heading-id";
import rehypeAutolinkHeadings from "rehype-autolink-headings";

const { findAndReplace } = await import("mdast-util-find-and-replace");

Expand Down Expand Up @@ -42,6 +43,18 @@ const withMDX = (await import("@next/mdx")).default({
extension: /\.mdx$/,
options: {
remarkPlugins: [githubIssueLinks, majorMinorColoring, remarkHeadingId],
rehypePlugins: [
[
rehypeAutolinkHeadings,
{
behavior: "append",
content: {
type: "text",
value: "#",
},
},
],
],
},
});

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"react-dom": "18.3.1",
"react-elm-components": "^1.1.0",
"react-responsive-carousel": "^3.2.23",
"rehype-autolink-headings": "^7.1.0",
"remark-custom-heading-id": "^2.0.0",
"remark-github": "^12.0.0",
"tailwindcss": "^3.2.1"
Expand Down
25 changes: 25 additions & 0 deletions styles/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,28 @@ button {
by {
display: none;
}

:is(h1, h2, h3, h4, h5, h6)[id] {
& > a {
@apply opacity-0 ml-2 font-normal no-underline;
transition:
color 100ms,
opacity 125ms;
}

&:target {
@apply scroll-m-24;
& > a {
@apply text-cyan-500 opacity-100;
}
}

&:target > a,
> a:hover {
@apply text-cyan-500 opacity-100;
}

&:hover > a {
@apply opacity-100;
}
}
33 changes: 33 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1501,6 +1501,7 @@ __metadata:
react-dom: "npm:18.3.1"
react-elm-components: "npm:^1.1.0"
react-responsive-carousel: "npm:^3.2.23"
rehype-autolink-headings: "npm:^7.1.0"
remark-custom-heading-id: "npm:^2.0.0"
remark-github: "npm:^12.0.0"
tailwindcss: "npm:^3.2.1"
Expand Down Expand Up @@ -2794,6 +2795,24 @@ __metadata:
languageName: node
linkType: hard

"hast-util-heading-rank@npm:^3.0.0":
version: 3.0.0
resolution: "hast-util-heading-rank@npm:3.0.0"
dependencies:
"@types/hast": "npm:^3.0.0"
checksum: 10c0/1879c84f629e73f1f13247ab349324355cd801363b44e3d46f763aa5c0ea3b42dcd47b46e5643a0502cf01a6b1fdb9208fd12852e44ca6c671b3e4bccf9369a1
languageName: node
linkType: hard

"hast-util-is-element@npm:^3.0.0":
version: 3.0.0
resolution: "hast-util-is-element@npm:3.0.0"
dependencies:
"@types/hast": "npm:^3.0.0"
checksum: 10c0/f5361e4c9859c587ca8eb0d8343492f3077ccaa0f58a44cd09f35d5038f94d65152288dcd0c19336ef2c9491ec4d4e45fde2176b05293437021570aa0bc3613b
languageName: node
linkType: hard

"hast-util-to-estree@npm:^3.0.0":
version: 3.1.0
resolution: "hast-util-to-estree@npm:3.1.0"
Expand Down Expand Up @@ -4830,6 +4849,20 @@ __metadata:
languageName: node
linkType: hard

"rehype-autolink-headings@npm:^7.1.0":
version: 7.1.0
resolution: "rehype-autolink-headings@npm:7.1.0"
dependencies:
"@types/hast": "npm:^3.0.0"
"@ungap/structured-clone": "npm:^1.0.0"
hast-util-heading-rank: "npm:^3.0.0"
hast-util-is-element: "npm:^3.0.0"
unified: "npm:^11.0.0"
unist-util-visit: "npm:^5.0.0"
checksum: 10c0/3d6653047c83cf7f9455bc0f5483a40170aee211cc057b7541b491d31e54b08fda72ab5ec4caeacea63e8af130584f0e14d5c63f6ddb86b7f34584b9e3f92dcf
languageName: node
linkType: hard

"remark-custom-heading-id@npm:^2.0.0":
version: 2.0.0
resolution: "remark-custom-heading-id@npm:2.0.0"
Expand Down
Loading