I Don't Think Names Work Like This


Tags: in8l, devlog

I was adding open graph to my website and got to adding my name’s metadata. I’ve got a first name and a surname so my open graph will look like this:

{{ $name := split site.Author.name " " }}
<meta property="og:profile:first_name" content="{{ index $name 0 }}">
<meta property="og:profile:last_name" content="{{ index $name (sub (len $name) 1) }}">
{{- end }}

Splitting the name string by spaces and using the first and last item of the resulting array for the first and last name respectively seems simple enough. Unfortunately, names don’t always work like that.

For instance, Chinese names have the surname first so Xi Jinping’s surname is Xi and yet my algorithm would have it as Jinping. Also, what’s to say that you can only have one surname? Spanish names use both parent’s surnames. There are many assumptions about names that fall apart as more people use product.

Here’s my attempted solution:

{{ $name := split site.Author.name " " }}
<meta property="og:profile:first_name" content="{{ or site.Author.fname (index $name 0) }}">
{{ if or (gt (len $name) 1) (isset site.Author "sname") -}}
<meta property="og:profile:last_name" content="{{ or site.Author.same (index $name (sub (len $name) 1)) }}">
{{- end }}

Seems good enough, since people can specify their own first name and surnames. There’s the question of whether they even have a first name, but if you have any better ideas let me know. Ironically, writing this post exposed more bugs I made while writing this post.

Reply via Email

Thanks for reading! If you liked this post, consider supporting my work by: