Skip to content

Commit

Permalink
Add ability to define custom socials (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelzw authored Nov 30, 2024
1 parent 1cd8339 commit dfa767e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 13 deletions.
44 changes: 31 additions & 13 deletions lib.typ
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,38 @@
#fa-icon(icon) #link(link_prefix + username)[#username]
]

let custom-social(icon, dest, body) = [
#fa-icon(icon) #link(dest, body)
]

let socialsDict = (
// key: (faIcon, linkPrefix)
phone: ("phone", "tel:"),
email: ("envelope", "mailto:"),
github: ("github", "https://github.com/"),
linkedin: ("linkedin", "https://linkedin.com/in/"),
x: ("x-twitter", "https://twitter.com/"),
bluesky: ("bluesky", "https://bsky.app/profile/"),
)

let socialsList = ()
if "phone" in socials {
socialsList.push(social("phone", "tel:", socials.phone))
}
if "email" in socials {
socialsList.push(social("envelope", "mailto:", socials.email))
}
if "github" in socials {
socialsList.push(social("github", "https://github.com/", socials.github))
}
if "linkedin" in socials {
socialsList.push(
social("linkedin", "https://linkedin.com/in/", socials.linkedin),
)
for entry in socials {
assert(type(entry) == array, message: "Invalid social entry type.")
assert(entry.len() == 2, message: "Invalid social entry length.")
let (key, value) = entry
if type(value) == str {
if key not in socialsDict {
panic("Unknown social key: " + key)
}
let (icon, linkPrefix) = socialsDict.at(key)
socialsList.push(social(icon, linkPrefix, value))
} else if type(value) == array {
assert(value.len() == 3, message: "Invalid social entry: " + key)
let (icon, dest, body) = value
socialsList.push(custom-social(icon, dest, body))
} else {
panic("Invalid social entry: " + entry)
}
}

let socialStack = stack(
Expand Down
4 changes: 4 additions & 0 deletions template/example.typ
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@
name: "Jane Doe",
lang: "en",
social: (
// predefined socials: phone, email, github, linkedin, x, bluesky
email: "jane.doe@example.com",
github: "jane-doe",
linkedin: "jane-doe",
// custom socials: (icon, link, body)
// any fontawesome icon can be used: https://fontawesome.com/search
website: ("link", "https://example.me", "example.me"),
),
)

Expand Down

0 comments on commit dfa767e

Please sign in to comment.