Skip to content

Commit 5126944

Browse files
authored
Merge pull request #52 from mapachurro/def-reorg-mvp
Definition reorganization v2
2 parents f3bbd51 + c0824f7 commit 5126944

5 files changed

Lines changed: 67 additions & 28 deletions

File tree

.cursor/rules/000_rules_staging.md

Whitespace-only changes.

.cursor/rules/001_cursor_rules.mdc

Whitespace-only changes.

css-mods.css

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,17 @@ body {
6868
margin-bottom: 1rem;
6969
}
7070
}
71+
72+
.additional-definition {
73+
margin-bottom: 1rem;
74+
}
75+
76+
.source-line {
77+
margin-top: 0.5rem;
78+
font-size: 0.9rem;
79+
}
80+
81+
.definition-separator {
82+
margin: 1rem 0;
83+
}
7184

locales/en-US/en-US.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,10 @@
117117
"partOfSpeech": "noun",
118118
"termCategory": "",
119119
"phonetic": "/əˈkaʊnt/",
120-
"definition": "An account, in web1 and web2 terms, refers to some sort of identity on some sort of digital platform. It is usually tied to an authentication method, e.g., username and password, which is granted, managed, and secured by the platform or service in question. By contrast, a web3 or crypto account consists of what is known as a public-private key pair; the public half is generally safe to be shared publicly, and in the case of Ethereum, is further processed to create what is known as the 'public address' of the account, always beginning with '0x'. The private half, meanwhile, gives total control over the account; *total*.",
120+
"definition": "An account, in web1 and web2 terms, refers to some sort of identity on some sort of digital platform. It is usually tied to an authentication method, e.g., username and password, which is granted, managed, and secured by the platform or service in question. By contrast, a web3 or crypto account consists of what is known as a public-private key pair; the public half is generally safe to be shared publicly, and in the case of Ethereum, is further processed to create what is known as the 'public address' of the account, always beginning with '0x'. The private half, meanwhile, gives total control over the account.",
121121
"definitionSource": "Education DAO - mapachurro",
122122
"sampleSentence": "",
123-
"extended": "These public-private key pairs can be generated one at a time, or they can be *derived* from what is known as a **seed phrase** or **secret recovery phrase**; for more on this, see HD wallet.",
123+
"extended": "These public-private key pairs can be generated one at a time, or they can be <i>derived</i> from what is known as a <b>seed phrase</b> or <b>secret recovery phrase</b>; for more on this, see HD wallet.",
124124
"additional": [
125125
{
126126
"definition": "A record in the Solana ledger that either holds data or is an executable program. Like an account at a traditional bank, a Solana account may hold funds called lamports. Like a file in Linux, it is addressable by a key, often referred to as a public key or pubkey. The key may be one of: - an ed25519 public key - a program-derived account address (32byte value forced off the ed25519 curve) - a hash of an ed25519 public key with a 32 character string",

utils/build-pages.js

Lines changed: 52 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,19 @@ function logToFile(message) {
2828
// Clear the log file before starting
2929
fs.writeFileSync(logFilePath, "", "utf-8");
3030

31+
// Export the function so it's accessible within the module
32+
export function isValidUrl(string) {
33+
const urlPattern = new RegExp('^(https?:\\/\\/)?' + // protocol
34+
'((([a-z0-9\\-]+\\.)+[a-z]{2,})|' + // domain name
35+
'localhost|' + // localhost
36+
'\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}|' + // IP address
37+
'\\[?[a-f0-9:\\.]+\\]?)' + // IPv6
38+
'(\\:\\d+)?(\\/[-a-z0-9%_.~+]*)*' + // port and path
39+
'(\\?[;&a-z0-9%_.~+=-]*)?' + // query string
40+
'(\\#[-a-z0-9_]*)?$','i'); // fragment locator
41+
return !!urlPattern.test(string);
42+
}
43+
3144
export default async function buildPages() {
3245
// Initialize language codes
3346
await initializeLanguageCodes(); // Make sure language codes are loaded before proceeding
@@ -96,42 +109,55 @@ export default async function buildPages() {
96109
? termData.additional
97110
: null;
98111

112+
// Function to check if a string is a valid URL
99113
const additionalDef = additionalDefsArray
100114
? additionalDefsArray
101-
.map(
102-
(alt) =>
103-
`<p><strong>Additional definition:</strong> ${alt.definition} <em>(${alt.source})</em></p>`,
104-
)
115+
.map((alt) => {
116+
// ✅ 'alt' is properly defined here
117+
let sourceText = "";
118+
if (alt.source) {
119+
if (isValidUrl(alt.source)) {
120+
sourceText = `<a href="${alt.source}" target="_blank" rel="noopener noreferrer">Source</a>`;
121+
} else {
122+
sourceText = `<strong>${alt.source}</strong>`;
123+
}
124+
}
125+
return `<div class="additional-definition">
126+
<p class="definition-text">${alt.definition}</p>
127+
<p class="source-line">${sourceText}</p>
128+
</div>`;
129+
})
105130
.join("")
106131
: "<p>No additional definitions found. Have another? Submit it!</p>";
107132

108133
const termCategoryValue = termData.termCategory || "To be determined";
109-
const definitionSource = termData.definitionSource || "N/A";
110-
const defSourceArray =
111-
Array.isArray(termData.definitionSource) && termData.definitionSource.length
112-
? termData.definitionSource
113-
: null;
114-
115-
const defSource = defSourceArray
116-
? defSourceArray
117-
.map(
118-
(alt) =>
119-
`<p><strong>Definition source:</strong> ${termSource}</p>`,
120-
)
121-
.join("")
122-
: "<p>Mapachurro probably wrote this.</p>";
134+
const definitionSource = termData.definitionSource
135+
? isValidUrl(termData.definitionSource)
136+
? `<a href="${termData.definitionSource}" target="_blank" rel="noopener noreferrer">Source</a>`
137+
: `<strong>${termData.definitionSource}</strong>`
138+
: "Mapachurro probably wrote this.";
139+
140+
const defSourceArray =
141+
Array.isArray(termData.definitionSource) && termData.definitionSource.length
142+
? termData.definitionSource
143+
: termData.definitionSource
144+
? [termData.definitionSource] // Wrap a single string in an array
145+
: null;
146+
147+
const defSource = defSourceArray
148+
? defSourceArray
149+
.map((src) =>
150+
isValidUrl(src)
151+
? `<a href="${src}" target="_blank" rel="noopener noreferrer">Source</a>`
152+
: `<strong>${src}</strong>`
153+
)
154+
.join(", ") // Separate multiple sources with a comma
155+
: "Mapachurro probably wrote this.";
156+
123157

124158
const sampleSentence = termData.sampleSentence || "N/A";
125159
const extended = termData.extended || "No extended definition. ...yet";
126160
// Enhanced handling for termSource
127-
const isValidUrl = (string) => {
128-
try {
129-
new URL(string);
130-
return true;
131-
} catch (_) {
132-
return false;
133-
}
134-
};
135161

136162
const termSource = termData.termSource
137163
? isValidUrl(termData.termSource)

0 commit comments

Comments
 (0)