Skip to content

Commit dfa767e

Browse files
authored
Add ability to define custom socials (#2)
1 parent 1cd8339 commit dfa767e

File tree

2 files changed

+35
-13
lines changed

2 files changed

+35
-13
lines changed

Diff for: lib.typ

+31-13
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,38 @@
2828
#fa-icon(icon) #link(link_prefix + username)[#username]
2929
]
3030

31+
let custom-social(icon, dest, body) = [
32+
#fa-icon(icon) #link(dest, body)
33+
]
34+
35+
let socialsDict = (
36+
// key: (faIcon, linkPrefix)
37+
phone: ("phone", "tel:"),
38+
email: ("envelope", "mailto:"),
39+
github: ("github", "https://github.com/"),
40+
linkedin: ("linkedin", "https://linkedin.com/in/"),
41+
x: ("x-twitter", "https://twitter.com/"),
42+
bluesky: ("bluesky", "https://bsky.app/profile/"),
43+
)
44+
3145
let socialsList = ()
32-
if "phone" in socials {
33-
socialsList.push(social("phone", "tel:", socials.phone))
34-
}
35-
if "email" in socials {
36-
socialsList.push(social("envelope", "mailto:", socials.email))
37-
}
38-
if "github" in socials {
39-
socialsList.push(social("github", "https://github.com/", socials.github))
40-
}
41-
if "linkedin" in socials {
42-
socialsList.push(
43-
social("linkedin", "https://linkedin.com/in/", socials.linkedin),
44-
)
46+
for entry in socials {
47+
assert(type(entry) == array, message: "Invalid social entry type.")
48+
assert(entry.len() == 2, message: "Invalid social entry length.")
49+
let (key, value) = entry
50+
if type(value) == str {
51+
if key not in socialsDict {
52+
panic("Unknown social key: " + key)
53+
}
54+
let (icon, linkPrefix) = socialsDict.at(key)
55+
socialsList.push(social(icon, linkPrefix, value))
56+
} else if type(value) == array {
57+
assert(value.len() == 3, message: "Invalid social entry: " + key)
58+
let (icon, dest, body) = value
59+
socialsList.push(custom-social(icon, dest, body))
60+
} else {
61+
panic("Invalid social entry: " + entry)
62+
}
4563
}
4664

4765
let socialStack = stack(

Diff for: template/example.typ

+4
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@
44
name: "Jane Doe",
55
lang: "en",
66
social: (
7+
// predefined socials: phone, email, github, linkedin, x, bluesky
78
89
github: "jane-doe",
910
linkedin: "jane-doe",
11+
// custom socials: (icon, link, body)
12+
// any fontawesome icon can be used: https://fontawesome.com/search
13+
website: ("link", "https://example.me", "example.me"),
1014
),
1115
)
1216

0 commit comments

Comments
 (0)