Skip to content

Commit 2385d14

Browse files
committed
feat: highlight GitHub links in rose with icon in parsed markdown
1 parent 950fe92 commit 2385d14

3 files changed

Lines changed: 52 additions & 37 deletions

File tree

src/globals.css

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,26 @@ html {
1919
div[role='group'][tabindex] {
2020
height: 100%;
2121
}
22+
23+
/* Style GitHub links in rendered markdown content */
24+
.parsed-text a[href*='github.com'] {
25+
color: #f088a5;
26+
text-decoration: none;
27+
font-weight: 500;
28+
}
29+
30+
.parsed-text a[href*='github.com']:hover {
31+
text-decoration: underline;
32+
}
33+
34+
.parsed-text a[href*='github.com']::before {
35+
content: '';
36+
display: inline-block;
37+
width: 1em;
38+
height: 1em;
39+
margin-right: 0.25em;
40+
vertical-align: -0.125em;
41+
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23F088A5'%3E%3Cpath d='M12 1.27a11 11 0 00-3.48 21.46c.55.09.73-.28.73-.55v-1.84c-3.03.64-3.67-1.46-3.67-1.46-.55-1.29-1.28-1.65-1.28-1.65-.92-.65.1-.65.1-.65 1.1 0 1.73 1.1 1.73 1.1.92 1.65 2.57 1.2 3.21.92a2.16 2.16 0 01.64-1.47c-2.47-.27-5.04-1.19-5.04-5.5 0-1.1.46-2.1 1.2-2.84a3.76 3.76 0 010-2.93s.91-.28 3.11 1.1c1.8-.49 3.7-.49 5.5 0 2.1-1.38 3.02-1.1 3.02-1.1a3.76 3.76 0 010 2.93c.74.74 1.2 1.74 1.2 2.84 0 4.31-2.58 5.23-5.04 5.5.45.37.82.92.82 2.02v3.03c0 .27.18.64.73.55A11 11 0 0012 1.27'/%3E%3C/svg%3E");
42+
background-size: contain;
43+
background-repeat: no-repeat;
44+
}

src/lib/mdxParser.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function ParsedText({ content }: { content: string }) {
1010
.use(rehypeStringify)
1111
.processSync(content).value
1212

13-
return <div dangerouslySetInnerHTML={{ __html: output }} />
13+
return <div className="parsed-text" dangerouslySetInnerHTML={{ __html: output }} />
1414
}
1515

1616
export default ParsedText

src/pages/simplesites/[slug].tsx

Lines changed: 28 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -25,46 +25,38 @@ function Simplesite({ simplesite }: { simplesite: SimpleSite }) {
2525
showContactHint,
2626
showBackButton,
2727
} = simplesite
28-
let textComponents: React.ReactNode[] = []
2928
const color = pickColor(title)
3029

31-
if (textBlocks != null) {
32-
const orderedTextBlocks = sortBy(textBlocks, [prop('order'), 'asc'])
33-
textComponents = textComponents.concat(
34-
orderedTextBlocks.map((block) => (
35-
<TextBlock
36-
key={block.title}
37-
title={block.title}
38-
content={<ParsedText content={block.content} />}
39-
/>
40-
))
41-
)
42-
}
30+
const allBlocks = [
31+
...(textBlocks ?? []).map((b) => ({ type: 'text' as const, order: b.order, data: b })),
32+
...(multiColumnBlocks ?? []).map((b) => ({ type: 'multiColumn' as const, order: b.order, data: b })),
33+
...(gridBlocks ?? []).map((b) => ({ type: 'grid' as const, order: b.order, data: b })),
34+
]
4335

44-
if (multiColumnBlocks != null) {
45-
const orderedMultiColumnBlocks = sortBy(multiColumnBlocks, [
46-
prop('order'),
47-
'asc',
48-
])
49-
textComponents = textComponents.concat(
50-
orderedMultiColumnBlocks.map((block) => (
51-
<MultiColumnBlock
52-
key={block.title}
53-
color={color}
54-
multiColumnBlock={block}
55-
/>
56-
))
57-
)
58-
}
36+
const orderedBlocks = sortBy(allBlocks, [prop('order'), 'asc'])
5937

60-
if (gridBlocks != null) {
61-
const orderedGridBlocks = sortBy(gridBlocks, [prop('order'), 'asc'])
62-
textComponents = textComponents.concat(
63-
orderedGridBlocks.map((block) => (
64-
<GridBlock key={block.title} gridBlock={block} />
65-
))
66-
)
67-
}
38+
const textComponents: React.ReactNode[] = orderedBlocks.map((block) => {
39+
switch (block.type) {
40+
case 'text':
41+
return (
42+
<TextBlock
43+
key={block.data.title}
44+
title={block.data.title}
45+
content={<ParsedText content={block.data.content} />}
46+
/>
47+
)
48+
case 'multiColumn':
49+
return (
50+
<MultiColumnBlock
51+
key={block.data.title}
52+
color={color}
53+
multiColumnBlock={block.data}
54+
/>
55+
)
56+
case 'grid':
57+
return <GridBlock key={block.data.title} gridBlock={block.data} />
58+
}
59+
})
6860

6961
if (showContactHint === 'true') {
7062
textComponents.push(<ContactHint color={color} />)

0 commit comments

Comments
 (0)