jekyll / jekyll-avatar

A Jekyll plugin for rendering GitHub avatars
MIT License
90 stars 9 forks source link

doesnt work with variables #61

Open tblobaum opened 2 years ago

tblobaum commented 2 years ago

{% avatar {{ page.author }} %} for some reason tries to load the avatar based on the name of the author instead of the username passed in

{{ page.author }} is tblobaum tblobaum has name set as Thomas Blobaum in GitHub {% avatar {{ page.author }} %} tries to load the avatar for "Thomas " instead of tblobaum

benbalter commented 2 years ago

@tblobaum see https://github.com/jekyll/jekyll-avatar#passing-the-username-as-variable for alternate ways to pass "complex" variables.

tblobaum commented 2 years ago

@benbalter that's the part of the documentation I originally referenced. Unless I'm too dumb to figure it out it doesn't quite work.

ashmaroli commented 2 years ago

@tblobaum Is your repository public? If yes, please provide the link to it and the URL of your webpage where you see the issue. Thanks.

tblobaum commented 2 years ago

The repository is public but I have since changed the code.

First of all, your example doesn't make sense.

{% assign user="hubot" %}
{% avatar {{ username }} %}

Why are you assigning user and then using username?

Secondly, I have narrowed down the issue. It seems that if I set author: tblobaum in the front matter and then try to use {% avatar {{ page.author }} %} it fails and loads the name from the GitHub account as a username to fetch the avatar with. For instance when page.author is tblobaum it tries to load an avatar for Thomas. I found out I can get avatars to work by only using them in an array. For some reason unknown to me, when placed in a loop of all site.authors the same code {% avatar {{ page.author }} %} loads the right avatar. I don't see why simply placing the code inside a loop of site.authors should change its behavior.

ashmaroli commented 2 years ago

First of all, your example doesn't make sense.

Good catch! Its a typo! Would you be interested in submitting a pull request to correct it?


Regarding the main issue here, it needs some investigations. I'll look into it.

ashmaroli commented 2 years ago

I've not been able to reproduce this. I tested with a boilerplate site (wired to use jekyll-avatar-0.7.0) containing the following page:

---
author: tblobaum
---

{% avatar {{ page.author }} %}
{% avatar ashmaroli %}

It rendered as expected into below: localhost_4000_test

Either I do not understand the issue or something is wrong at your end. If former, please provide a reproducible repo.

tblobaum commented 2 years ago

Repo is: https://github.com/tblobaum/thenewworldpost.com

If you clone the repo you first need to uncomment jekyll-avatar in the Gemfile and _config.yml (they are both at the bottom of the page) then you can run it with bundle install and then bundle exec jekyll serve then navigate to _layouts/post.html and paste at the top of the file somewhere {% avatar {{ page.author }} %} then navigate to the entertainment/2022/01/01/kylo-ren-of-star-wars-the-force-awakens-was-inspired-by-nazis.html or another post on the homepage of the website which has tblobaum as the author in frontmatter. If you open up _posts/entertainment/2015-11-28-kylo-ren-of-star-wars-the-force-awakens-was-inspired-by-nazis.markdown you can see in the frontmatter author: tblobaum yet the avatar being rendered is for the github usernamed Thomas

ashmaroli commented 2 years ago

@tblobaum I have been able to reproduce the issue using your repo. (You forgot to tell me that I should clone gh-pages instead of master.. pfft! smh!). Anyways, the issue seems to be differences between Jekyll 3 and Jekyll 4. You should be able to use this plugin either by using Jekyll 3.9 via gem "jekyll", "~> 3.9" or by pointing the jekyll-avatar gem to this repository:

gem "jekyll", "~> 4.2.1"
gem "jekyll-avatar", github: "jekyll/jekyll-avatar"
ashmaroli commented 2 years ago

Related: #59

ashmaroli commented 2 years ago

Hi, v0.8.0 has been released. Please upgrade and confirm if this issue has been resolved. Thanks.