Skip to content

Commit 624c037

Browse files
authored
docs: Add a HumanLink for ecosystem entries (#7635)
This makes a guess at a more human-friendly link for ecosystem entries, without us needing to go around and get all the link titles. Signed-off-by: Charlie Egan <[email protected]>
1 parent 283c7ff commit 624c037

File tree

2 files changed

+56
-10
lines changed

2 files changed

+56
-10
lines changed

docs/src/EcosystemEntry.js

Lines changed: 55 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,57 @@ import ReactMarkdown from "react-markdown";
66
import entries from "@generated/ecosystem-data/default/entries.json";
77
import getLogoAsset from "./lib/ecosystem/getLogoAsset.js";
88

9+
function humanizeSegment(segment) {
10+
const words = segment.replace(/-/g, " ").split(" ");
11+
12+
// Filter out words with more than 3 digits, this is a heuristic to avoid URL
13+
// ids and so on.
14+
const filteredWords = words.filter((word) => {
15+
const digitCount = (word.match(/\d/g) || []).length;
16+
return digitCount <= 3;
17+
});
18+
19+
return filteredWords
20+
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
21+
.map((word) => {
22+
if (word.toLowerCase() === "opa") return "OPA";
23+
return word.charAt(0).toUpperCase() + word.slice(1);
24+
})
25+
.join(" ");
26+
}
27+
28+
function getHumanLabelFromUrl(url) {
29+
try {
30+
const parsed = new URL(url);
31+
const domain = parsed.hostname.replace(/^www\./, "");
32+
33+
const parts = parsed.pathname
34+
.split("/")
35+
.filter(Boolean)
36+
.map(humanizeSegment);
37+
38+
const label = parts.length > 0 ? parts.join(" > ") : domain;
39+
40+
return { domain, label };
41+
} catch (err) {
42+
console.error(err);
43+
return { domain: "", label: url };
44+
}
45+
}
46+
47+
const HumanLink = ({ href }) => {
48+
const { domain, label } = getHumanLabelFromUrl(href);
49+
50+
return (
51+
<>
52+
<a href={href} target="_blank" rel="noopener noreferrer">
53+
{label}
54+
</a>{" "}
55+
({domain})
56+
</>
57+
);
58+
};
59+
960
const EcosystemEntry = (props) => {
1061
const { id } = props.route.customData;
1162
const page = entries[id];
@@ -65,9 +116,7 @@ const EcosystemEntry = (props) => {
65116
<ul>
66117
{blogs.map((url, idx) => (
67118
<li key={`blog-${idx}`}>
68-
<a href={url} target="_blank" rel="noopener noreferrer">
69-
{url}
70-
</a>
119+
<HumanLink href={url} />
71120
</li>
72121
))}
73122
</ul>
@@ -81,9 +130,7 @@ const EcosystemEntry = (props) => {
81130
<ul>
82131
{code.map((url, idx) => (
83132
<li key={`code-${idx}`}>
84-
<a href={url} target="_blank" rel="noopener noreferrer">
85-
{url}
86-
</a>
133+
<HumanLink href={url} />
87134
</li>
88135
))}
89136
</ul>
@@ -101,7 +148,7 @@ const EcosystemEntry = (props) => {
101148
return (
102149
<li key={`video-${idx}`}>
103150
<a href={video} target="_blank" rel="noopener noreferrer">
104-
{video}
151+
{video.replace(/https?:\/\//, "").replace(/\/$/, "")}
105152
</a>
106153
</li>
107154
);
@@ -143,9 +190,7 @@ const EcosystemEntry = (props) => {
143190
<ul>
144191
{tutorials.map((url, idx) => (
145192
<li key={`tutorial-${idx}`}>
146-
<a href={url} target="_blank" rel="noopener noreferrer">
147-
{url}
148-
</a>
193+
<HumanLink href={url} />
149194
</li>
150195
))}
151196
</ul>

docs/src/data/ecosystem/entries/regal.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ code:
1313
- https://github.com/StyraInc/regal
1414
videos:
1515
- "https://www.youtube.com/live/Xx8npd2TQJ0?feature=share&t=2567"
16+
- "https://youtu.be/XtA-NKoJDaI?feature=shared&t=934"
1617
tutorials:
1718
- https://docs.styra.com/regal#try-it-out
1819
docs_features:

0 commit comments

Comments
 (0)