Skip to content

Commit 00d72fe

Browse files
TOO LAGGY
1 parent b502d5b commit 00d72fe

File tree

6 files changed

+237
-27
lines changed

6 files changed

+237
-27
lines changed

package-lock.json

Lines changed: 177 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"rehype-format": "^5.0.1",
2323
"rehype-highlight": "^7.0.2",
2424
"rehype-parse": "^9.0.1",
25+
"rehype-pretty-code": "^0.14.1",
2526
"rehype-stringify": "^10.0.1",
2627
"remark-parse": "^11.0.0",
2728
"remark-rehype": "^11.1.2",

public/article-2025/04/renewed-with-nextjs/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ React の JSX と組み合わせることで、**よりモダンで保守性の
3838

3939
#### TypeScriptの例
4040

41-
```tsx
41+
```tsx title="example.tsx" showLineNumbers
4242
"use client";
4343

4444
import { useState, useEffect } from "react";

src/app/[article_year]/[month]/[aid]/page.css

Lines changed: 55 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ html {
7777
margin-bottom: 16px;
7878
}
7979

80-
.article-content {
80+
.article-container>.article-detail>.article-content {
8181
display: flex;
8282
align-items: stretch;
8383
flex-direction: column;
@@ -86,20 +86,52 @@ html {
8686
padding: 2px;
8787
}
8888

89-
.article-content pre {
89+
.article-container>.article-detail>.article-content pre {
9090
padding: 0;
9191
border: 2px solid var(--primary);
92-
border-radius: 16px;
92+
border-radius: 0 0 16px 16px;
9393
width: 100%;
9494
overflow: scroll;
9595
font-family: monospace;
96+
}
9697

98+
.article-container>.article-detail>.article-content figcaption[data-rehype-pretty-code-title] {
99+
background-color: var(--background);
100+
color: var(--foreground);
101+
border-radius: 16px 16px 0 0;
102+
border: 2px solid var(--primary);
103+
padding:4px;
104+
}
105+
.article-container>.article-detail>.article-content code[data-line-numbers] {
106+
counter-reset: line;
107+
}
108+
109+
.article-container>.article-detail>.article-content code[data-line-numbers] > [data-line]::before {
110+
display: inline-block;
111+
width: 12px;
112+
margin-right: 1rem;
113+
color: gray;
114+
text-align: right;
115+
content: counter(line);
116+
counter-increment: line;
117+
}
118+
119+
.article-container>.article-detail>.article-content code[data-line-numbers-max-digits="2"] > [data-line]::before {
120+
width: 1.25rem;
121+
}
122+
123+
.article-container>.article-detail>.article-content code[data-line-numbers-max-digits="3"] > [data-line]::before {
124+
width: 1.75rem;
125+
}
126+
127+
.article-container>.article-detail>.article-content code[data-line-numbers-max-digits="4"] > [data-line]::before {
128+
width: 2.25rem;
97129
}
98130

99-
.article-content h1,
100-
.article-content h2,
101-
.article-content h3,
102-
.article-content h4 {
131+
.article-container>.article-detail>.article-content h1,
132+
.article-container>.article-detail>.article-content h2,
133+
.article-container>.article-detail>.article-content h3,
134+
.article-container>.article-detail>.article-content h4 {
103135
line-height: 2;
104136
padding-left: 10px;
105137
margin: 10px 0 20px -5px;
@@ -108,31 +140,31 @@ html {
108140
animation: article-h-borders 5s linear infinite;
109141
}
110142

111-
.article-content h1[id],
112-
.article-content h2[id],
113-
.article-content h3[id],
114-
.article-content h4[id],
115-
.article-content h5[id],
116-
.article-content h6[id] {
143+
.article-container>.article-detail>.article-content h1[id],
144+
.article-container>.article-detail>.article-content h2[id],
145+
.article-container>.article-detail>.article-content h3[id],
146+
.article-container>.article-detail>.article-content h4[id],
147+
.article-container>.article-detail>.article-content h5[id],
148+
.article-container>.article-detail>.article-content h6[id] {
117149
scroll-margin-top: 64px;
118150
/* 固定ヘッダーの高さに応じて調整 */
119151
}
120152

121-
.article-content h5,
122-
.article-content h6,
153+
.article-container>.article-detail>.article-content h5,
154+
.article-container>.article-detail>.article-content h6,
123155
.article-content p {
124156
color: var(--foreground);
125157
font-weight: 500;
126158
}
127159

128-
.article-content h1::before,
129-
.article-content h2::before,
130-
.article-content h3::before,
131-
.article-content h4::before,
132-
.article-content h1::after,
133-
.article-content h2::after,
134-
.article-content h3::after,
135-
.article-content h4::after {
160+
.article-container>.article-detail>.article-content h1::before,
161+
.article-container>.article-detail>.article-content h2::before,
162+
.article-container>.article-detail>.article-content h3::before,
163+
.article-container>.article-detail>.article-content h4::before,
164+
.article-container>.article-detail>.article-content h1::after,
165+
.article-container>.article-detail>.article-content h2::after,
166+
.article-container>.article-detail>.article-content h3::after,
167+
.article-container>.article-detail>.article-content h4::after {
136168
background: linear-gradient(to right, #f00, #ff0, #0f0, #0ff, #00f, #f0f, #f00) 0 / 200%;
137169
content: "";
138170
display: block;

src/app/[article_year]/[month]/[aid]/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export default async function ArticlePage({
7070
/>
7171
)}
7272
<div
73-
className="article-content "
73+
className="article-content"
7474
dangerouslySetInnerHTML={{
7575
__html: article.content.replace(
7676
/<h([1-6])>(.*?)<\/h[1-6]>/g,

src/app/article/article.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import fs from "fs";
22
import path from "path";
33
import matter from "gray-matter";
4-
import rehypeHighlight from "rehype-highlight";
4+
import rehypePrettyCode from "rehype-pretty-code";
55
import rehypeFormat from "rehype-format";
66
import remarkParse from "remark-parse";
77
import remarkRehype from "remark-rehype";
@@ -90,7 +90,7 @@ export async function toHTML(
9090
const processedContent = await unified()
9191
.use(remarkParse)
9292
.use(remarkRehype)
93-
.use(rehypeHighlight)
93+
.use(rehypePrettyCode)
9494
.use(rehypeFormat)
9595
.use(rehypeStringify)
9696
.process(content);

0 commit comments

Comments
 (0)