Skip to content

Commit 6ddbfc1

Browse files
committed
#4 헤딩 링크 스타일 추가
1 parent fb1210f commit 6ddbfc1

File tree

4 files changed

+70
-7
lines changed

4 files changed

+70
-7
lines changed

next.config.mjs

+45-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,51 @@ const withMDX = mdx({
116116
[remarkCodeHike, chConfig],
117117
[remarkToc, { heading: "목차" }],
118118
],
119-
rehypePlugins: [rehypeSlug, rehypeAutolinkHeadings],
119+
rehypePlugins: [
120+
rehypeSlug,
121+
[
122+
rehypeAutolinkHeadings,
123+
{
124+
properties: {
125+
ariaHidden: true,
126+
tabIndex: -1,
127+
className: "heading-anchor",
128+
},
129+
content: {
130+
type: "element",
131+
tagName: "svg",
132+
properties: {
133+
className: "icon-link",
134+
xmlns: "http://www.w3.org/2000/svg",
135+
width: "24",
136+
height: "24",
137+
viewBox: "0 0 24 24",
138+
fill: "none",
139+
stroke: "currentColor",
140+
"stroke-width": "2",
141+
"stroke-linecap": "round",
142+
"stroke-linejoin": "round",
143+
},
144+
children: [
145+
{
146+
type: "element",
147+
tagName: "path",
148+
properties: {
149+
d: "M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71",
150+
},
151+
},
152+
{
153+
type: "element",
154+
tagName: "path",
155+
properties: {
156+
d: "M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71",
157+
},
158+
},
159+
],
160+
},
161+
},
162+
],
163+
],
120164
},
121165
});
122166

src/common/globals.css

+20
Original file line numberDiff line numberDiff line change
@@ -145,3 +145,23 @@
145145
.ch-scrollycoding-step-content {
146146
@apply border-gray-200;
147147
}
148+
149+
article .heading-anchor {
150+
@apply absolute text-gray-300 -left-6 sm:-left-7 top-1 w-6 h-6 p-1;
151+
}
152+
153+
h2:has(.heading-anchor),
154+
h3:has(.heading-anchor),
155+
h4:has(.heading-anchor),
156+
h5:has(.heading-anchor),
157+
h6:has(.heading-anchor) {
158+
@apply relative ml-2 sm:ml-0;
159+
}
160+
161+
article .heading-anchor:hover {
162+
@apply text-inherit;
163+
}
164+
165+
article .heading-anchor svg {
166+
@apply w-4 h-4;
167+
}

src/modules/article/format-components.tsx

+4-5
Original file line numberDiff line numberDiff line change
@@ -136,15 +136,14 @@ export function Strong({ children }: { children?: React.ReactNode }) {
136136
export function Anchor({
137137
children,
138138
href,
139-
}: {
140-
children?: React.ReactNode;
141-
href?: string;
142-
}) {
139+
...restProps
140+
}: React.ComponentProps<"a">) {
143141
const isInternal = href?.startsWith("/article") || href?.startsWith("#");
144142

145143
return (
146144
<Link
147-
className={style.link}
145+
{...restProps}
146+
className={twMerge(restProps.className, style.link)}
148147
{...(!isInternal
149148
? {
150149
target: "_blank",

src/modules/article/style.module.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
}
4545

4646
.heading {
47-
@apply font-semibold mt-[1.5em] mb-[0.5em];
47+
@apply font-semibold mt-[1.5em] mb-[0.5em] relative;
4848
}
4949

5050
.heading1 {

0 commit comments

Comments
 (0)