Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 27 additions & 5 deletions _components/accessible-emoji.webc
Original file line number Diff line number Diff line change
@@ -1,8 +1,30 @@
<script webc:root="override" webc:type="js" webc:raw>
let label = emojiShortName(emoji);
// via
// https://kittygiraudel.com/2021/01/02/accessible-emojis-with-11ty/
// https://tink.uk/accessible-emoji/
// https://adrianroselli.com/2016/12/accessible-emoji-tweaked.html
/**
* Make emoji more accessible.
*
* @param {string} alt - Optionally override the Unicode short name passed
* to aria-label
* @param {string} emoji - emoji to make more accessible
*
* Current bug in emoji-short-name/emoji-essential puts extraneous
* `⊛ ` into names, so filtering here.
* https://github.com/WebReflection/emoji-essential/issues/1
*
* Newer emoji may not be in emoji-essential, so we need to be extra defensive
*
* Learn more:
* - https://kittygiraudel.com/2021/01/02/accessible-emojis-with-11ty/
* - https://tink.uk/accessible-emoji/
* - https://adrianroselli.com/2016/12/accessible-emoji-tweaked.html
*/
let label = "";
if (alt && typeof alt === 'string') {
label = alt;
} else if (typeof emoji === 'string' && typeof alt === 'undefined') {
shortName = emojiShortName(emoji);
if (typeof shortName !== "undefined") {
label = shortName.replace("⊛ ", "");
}
}
`<span role="img" aria-label="${label}">${emoji}</span>`
</script>
3 changes: 2 additions & 1 deletion index.webc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
let layout = "layouts/base.webc";
// Hi
---
<h1>Welcome to Tugboat <accessible-emoji emoji="🛟"></accessible-emoji></h1>
<!--- Optionally override the Unicode emoji name with alt --->
<h1>Welcome to Tugboat <accessible-emoji emoji="🛟" alt="life preserver"></accessible-emoji></h1>

<p @text="pkg.description"></p>

Expand Down