Skip to content

Commit ed6608b

Browse files
rakesh2OO5ksen0
authored andcommitted
Fix broken p5.* reference links in reference pages
1 parent 328d625 commit ed6608b

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/layouts/ReferenceItemLayout.astro

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,15 @@ const descriptionParts = description.split(
9090
/(<pre><code class="language-js(?: example)?">[\s\S]+?<\/code><\/pre>)/gm
9191
);
9292
93-
---
93+
// Normalizes malformed p5.* reference anchors (e.g. "#/p5.Element")
94+
// to proper reference routes ("/reference/p5/p5.Element/")
95+
function normalizeP5ReferenceLinks(html) {
96+
if (!html) return html;
97+
return html.replace(
98+
/href="#\/(p5\.[^"]+)"/g,
99+
'href="/reference/p5/$1/"'
100+
);
101+
}
94102
95103
<Head title={entry.data.title} locale={currentLocale} />
96104
@@ -208,7 +216,7 @@ const descriptionParts = description.split(
208216
class="col-span-5 [&_p]:m-0 [&_p]:inline [&_a]:underline"
209217
>
210218
{param.type && <span>{param.type}: </span>}
211-
<span set:html={param.description} />
219+
<span set:html={normalizeP5ReferenceLinks(param.description)} />
212220
</div>
213221
</div>
214222
))}
@@ -226,7 +234,7 @@ const descriptionParts = description.split(
226234
class="col-span-5 [&_p]:m-0 [&_p]:inline [&_a]:underline"
227235
>
228236
{param.type && <span>{param.type}: </span>}
229-
<span set:html={param.description} />
237+
<span set:html={normalizeP5ReferenceLinks(param.description)} />
230238
</div>
231239
</div>
232240
)
@@ -246,7 +254,7 @@ const descriptionParts = description.split(
246254
class="col-span-5 [&_p]:m-0 [&_p]:inline [&_a]:underline"
247255
>
248256
{entry.data.return.type && <span>{entry.data.return.type}: </span>}
249-
<span set:html={entry.data.return.description} />
257+
<span set:html={normalizeP5ReferenceLinks(entry.data.return.description)} />
250258
</div>
251259
</div>
252260
</div>

0 commit comments

Comments
 (0)