Skip to content

Commit 1366626

Browse files
authored
Merge pull request #893 from timlrx/feature/header-link-icon
add header link icon
2 parents afdda22 + 55cd4b4 commit 1366626

File tree

5 files changed

+62
-3
lines changed

5 files changed

+62
-3
lines changed

app/tag-data.json

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,20 @@
1-
{"markdown":1,"code":1,"features":1,"next-js":6,"math":1,"ols":1,"github":1,"guide":5,"tailwind":3,"hello":1,"holiday":1,"canada":1,"images":1,"feature":2,"writings":1,"book":1,"reflection":1,"multi-author":1}
1+
{
2+
"markdown": 1,
3+
"code": 1,
4+
"features": 1,
5+
"next-js": 6,
6+
"math": 1,
7+
"ols": 1,
8+
"github": 1,
9+
"guide": 5,
10+
"tailwind": 3,
11+
"hello": 1,
12+
"holiday": 1,
13+
"canada": 1,
14+
"images": 1,
15+
"feature": 2,
16+
"writings": 1,
17+
"book": 1,
18+
"reflection": 1,
19+
"multi-author": 1
20+
}

contentlayer.config.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { writeFileSync } from 'fs'
33
import readingTime from 'reading-time'
44
import { slug } from 'github-slugger'
55
import path from 'path'
6+
import { fromHtmlIsomorphic } from 'hast-util-from-html-isomorphic'
67
// Remark packages
78
import remarkGfm from 'remark-gfm'
89
import remarkMath from 'remark-math'
@@ -25,6 +26,19 @@ import { allCoreContent, sortPosts } from 'pliny/utils/contentlayer.js'
2526
const root = process.cwd()
2627
const isProduction = process.env.NODE_ENV === 'production'
2728

29+
// heroicon mini link
30+
const icon = fromHtmlIsomorphic(
31+
`
32+
<span class="content-header-link">
33+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" className="w-5 h-5 linkicon">
34+
<path d="M12.232 4.232a2.5 2.5 0 0 1 3.536 3.536l-1.225 1.224a.75.75 0 0 0 1.061 1.06l1.224-1.224a4 4 0 0 0-5.656-5.656l-3 3a4 4 0 0 0 .225 5.865.75.75 0 0 0 .977-1.138 2.5 2.5 0 0 1-.142-3.667l3-3Z" />
35+
<path d="M11.603 7.963a.75.75 0 0 0-.977 1.138 2.5 2.5 0 0 1 .142 3.667l-3 3a2.5 2.5 0 0 1-3.536-3.536l1.225-1.224a.75.75 0 0 0-1.061-1.06l-1.224 1.224a4 4 0 1 0 5.656 5.656l3-3a4 4 0 0 0-.225-5.865Z" />
36+
</svg>
37+
</span>
38+
`,
39+
{ fragment: true }
40+
)
41+
2842
const computedFields: ComputedFields = {
2943
readingTime: { type: 'json', resolve: (doc) => readingTime(doc.body.raw) },
3044
slug: {
@@ -134,7 +148,6 @@ export default makeSource({
134148
mdx: {
135149
cwd: process.cwd(),
136150
remarkPlugins: [
137-
// @ts-ignore
138151
remarkExtractFrontmatter,
139152
remarkGfm,
140153
remarkCodeTitles,
@@ -143,7 +156,16 @@ export default makeSource({
143156
],
144157
rehypePlugins: [
145158
rehypeSlug,
146-
rehypeAutolinkHeadings,
159+
[
160+
rehypeAutolinkHeadings,
161+
{
162+
behavior: 'prepend',
163+
headingProperties: {
164+
className: ['content-header'],
165+
},
166+
content: icon,
167+
},
168+
],
147169
rehypeKatex,
148170
[rehypeCitation, { path: path.join(root, 'data') }],
149171
[rehypePrismPlus, { defaultLanguage: 'js', ignoreMissing: true }],

css/tailwind.css

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,19 @@ input:-webkit-autofill:focus {
3333
.katex-display {
3434
overflow: auto hidden;
3535
}
36+
37+
.content-header-link {
38+
opacity: 0;
39+
margin-left: -24px;
40+
padding-right: 4px;
41+
}
42+
43+
.content-header:hover .content-header-link,
44+
.content-header-link:hover {
45+
opacity: 1;
46+
}
47+
48+
.linkicon {
49+
display: inline-block;
50+
vertical-align: middle;
51+
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"esbuild": "0.20.2",
2121
"github-slugger": "^2.0.0",
2222
"gray-matter": "^4.0.2",
23+
"hast-util-from-html-isomorphic": "^2.0.0",
2324
"image-size": "1.0.0",
2425
"next": "14.1.4",
2526
"next-contentlayer2": "0.4.4",

yarn.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10750,6 +10750,7 @@ __metadata:
1075010750
eslint-plugin-prettier: ^5.0.0
1075110751
github-slugger: ^2.0.0
1075210752
gray-matter: ^4.0.2
10753+
hast-util-from-html-isomorphic: ^2.0.0
1075310754
husky: ^9.0.0
1075410755
image-size: 1.0.0
1075510756
lint-staged: ^13.0.0

0 commit comments

Comments
 (0)