Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update accessible-emoji with enhancements from WebC bed #9

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
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