inukshuk / jekyll-scholar

jekyll extensions for the blogging scholar
MIT License
1.12k stars 102 forks source link

Update from 6.6.1 to 6.7.0 broke details_link tag #304

Closed tim-taylor closed 4 years ago

tim-taylor commented 4 years ago

My site uses the details_link tag as described in the documentation to link to a details page for each publication. This was all working fine, but the functionality broke when I upgraded jekyll-scholar from version 6.6.1 to 6.7.0.

The code {% details_link key %} used to generate the correct URLs, but with 6.7.0 the links look something like http://localhost:4000/publications/Liquid%20error:%20internal.

I have reverted to the previous working version of my site and verified that it is this single change in my codebase of updating jekyll-scholar from 6.6.1 to 6.7.0 that causes this problem.

inukshuk commented 4 years ago

What's your configuration like? Can you find a test case that reproduces this?

The only change we between 6.6.1 and 6.7.0 was to fix the base URL handling you reported.

tim-taylor commented 4 years ago

I'm working on finding a minimal test case that reproduces this. But in the meantime I've examined the differences in the jekyll-scholar code between 6.6.1 and 6.7.0. There is one change in particular in lib/jekyll/scholar/utilities.rb which is related to generating the URL of the details page, which seems like it might be relevant (although I'm not a Ruby programmer myself and don't know the significance of the change in syntax):

It's in the function details_path_for(entry)

In 6.6.1:

# generate the URL
File.join(base, 
  URL.new(
    :template => config['details_permalink'],
    :placeholders => url_placeholders
  ).to_s)

In 6.7.0:

URL.new(
  template: config['details_permalink'],
  placeholders: url_placeholders
).to_s

I wonder does this change in syntax from :template => to template: cause a difference in the output?

(In answer to your question about configuration, I'm running Kubuntu 19.10 on two development machines -- 1 laptop and 1 desktop -- and Ubuntu 18.04 on a Linode production server.)

inukshuk commented 4 years ago

I wonder does this change in syntax from :template => to template: cause a difference in the output?

This evaluates to the same thing; template: is just a newer syntax.

tim-taylor commented 4 years ago

tt-test-case.tar.gz

Attached is a minimal test case. Note I've had problems with the details_layout configuration option in this minimal example. In _config.yml details_layout is set to bibtex.html. However, if a file of that name exists in the _layouts directory I get a compilation error, so I have temporarily renamed the file to bibtexXXX.html to avoid this compilation error. I don't get this compilation error with my full site, so it is specific to this minimal example (sorry if I'm doing something stupid there).

The error means that the details page does not actually get produced. Nevertheless, the example still demonstrates the problem I am experiencing with the full site. When you compile it with jekyll-scholar set to 6.6.1 in Gemfile.lock and navigate to http://127.0.0.1:4000/, you will see a "Full details" link that points to http://127.0.0.1:4000/paper-details/taylor2020importance.html, which is the correct URL.

However, if you set jekyll-scholar to 6.7.0 in Gemfile.lock and recompile, you will see that the link now points to http://127.0.0.1:4000/Liquid%20error:%20internal

inukshuk commented 4 years ago

This was helpful, thanks.

Looking at it briefly, I'm not at all sure why this worked in previous version, but the details_link tag is not really supposed to be used like that. You're using it inside a bibliography template like this: {% details_link key %} -- this will compute the details_link tag with input key. The input to this tag is interpreted as a variable, if it exists, otherwise it's used as a string. Since you're not assigning the variable key anywhere this actually means you're adding a link to the detail page of an entry with id 'key' to every reference.

I assume you want to print the link to the page of each item, respectively. This link is already passed to the bibliography item template in the details variable. That is, if you just put in {{ details}} that should fix the problem.

It would be interesting to know why the tag worked for you previously; if the links to each item was produced correctly, the only explanation is that the each entry's id was passed to the bibliography template bound to the variable key.

tim-taylor commented 4 years ago

Thank you!! I've replaced the {% details_link key %} tag with {{ details }} as suggested, and it now works fine with 6.7.0.

I didn't see anything about the use of {{ details }} in README.md. It might be worth adding a sentence about this if/when you get the chance?

(Just for info, I also tried replacing {% details_link key %} in the template with {% details_link entry.key %}, because entry.key is definitely defined in that context as the proper key for the item in question. But this still gave the same problem when I switched from 6.6.1 to 6.7.0. Anyhow, that's really irrelevant now.)

Thanks very much again for your help. Much appreciated.