Skip to content

Commit 75c4e8b

Browse files
Merge pull request #1 from desireddymohithreddy0925/fix/social-url-validation
fix: auto-prepend https to social URLs lacking a protocol to prevent …
2 parents 61ec3f9 + 89f9c79 commit 75c4e8b

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

app/generator/utils/readmeGenerator.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,17 @@ export function generateReadme(state: GeneratorState): string {
135135
.map((id) => {
136136
const social = getSocialById(id);
137137
if (!social) return null;
138-
const url = state.socialLinks[id];
139-
const resolvedUrl =
138+
const rawUrl = state.socialLinks[id]?.trim() || '';
139+
let resolvedUrl =
140140
social.id === 'email'
141-
? `mailto:${url.replace(/^mailto:/i, '')}`
142-
: url.startsWith('http')
143-
? url
144-
: `${social.baseUrl}${url}`;
141+
? `mailto:${rawUrl.replace(/^mailto:/i, '')}`
142+
: rawUrl.startsWith('http')
143+
? rawUrl
144+
: `${social.baseUrl || ''}${rawUrl}`;
145+
146+
if (social.id !== 'email' && !/^https?:\/\//i.test(resolvedUrl)) {
147+
resolvedUrl = `https://${resolvedUrl}`;
148+
}
145149

146150
if (social.type === 'simpleicon' && social.siSlug) {
147151
return [

0 commit comments

Comments
 (0)