Skip to content
Discussion options

You must be logged in to vote

A few possible suggestions (for Nunjucks; Liquid would probably need a slightly tweaked syntax):

---
author: "@twitter"
---
{% if author[0] === "@" %}TWITTER1{% endif %}
{% if author.at(0) === "@" %}TWITTER2{% endif %}
{% if author.startsWith("@") %}TWITTER3{% endif %}
{% if author|first === "@" %}TWITTER4{% endif %}

{{ "TWITTER" if author|first === "@" else "MASTODON" }}

Or if this is something you're using in 1+ places, I might suggest a custom Eleventy filter that you can reuse a bit more easily.

  eleventyConfig.addFilter("social", function (username="") {
    if (!username) {
      return "";
    }
    if (username.startsWith("@")) {
      return `<a href="https://twitter.com/${user…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@j9t
Comment options

Answer selected by j9t
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants