Search code examples
githubjekyllliquidjekyll-theme

CSV Data in jekyll: how to sort and display data according to "Publication year"


I am trying to work on a simple workflow to sort out my publications csv to a list in my jekyll-based website.

This is my references.csv extracted from referencing software Mendeley and converted from bib to csv using online converter. I want to place this in my _data folder and make a list of publications in the page on jekyll website hosted on github. The sampe data is shown below:

"Item type","Authors","Title","Journal","Publication year","Volume","Issue","Pages","Publisher","Date published","ISSN","URLs","DOI","PMID","Abstract","Keywords"
"Book","Wilden H","PCI design handbook: Precast and prestressed concrete","","2017","","","","Precast/Prestressed Concrete Institute Wakefield, MA, USA","2017","","","","","",""
"Journal Article","Nanni A,Di Ludovico M,Parretti R","Shear strengthening of a PC bridge girder with NSM CFRP rectangular bars","Advances in Structural Engineering","2004","7","4","297-309","SAGE PublicationsSage UK: London, England","2004-11","1369-4332","https://journals.sagepub.com/doi/10.1260/1369433041653570;http://dx.doi.org/10.1260/1369433041653570","10.1260/1369433041653570","","trimmed down abstract","keyword 1"
"Journal Article","Di B,Wang J,Li H,Zheng J,Zheng Y,Song G","Investigation of Bonding Behavior of FRP and Steel Bars in Self-Compacting Concrete Structures Using Acoustic Emission Method","Sensors 2019, Vol. 19, Page 159","2019","19","1","159","Multidisciplinary Digital Publishing Institute","2019-01","1424-8220","http://dx.doi.org/10.3390/S19010159;https://www.ncbi.nlm.nih.gov/pubmed/30621189","10.3390/S19010159","30621189","To extend ","FRP,acoustic emission,bonding,compacting concrete,out test,pull,self"
"Journal Article","Crivelli D,Bland S","Structural health monitoring via acoustic emission","Reinforced Plastics","2016","60","6","390-392","Elsevier Ltd","2016-11","0034-3617","http://dx.doi.org/10.1016/j.repl.2015.05.004","10.1016/j.repl.2015.05.004","","Reinforced Plastics spoke to Dr Davide Crivelli from the Politecnico di Milano about new methods for detecting damage in composites.",""
"Journal Article","Tonelli D,Luchetta M,Rossi F,Migliorino P,Zonta D","Structural health monitoring based on acoustic emissions: Validation on a prestressed concrete bridge tested to failure","Sensors (Switzerland)","2020","20","24","1-20","Multidisciplinary Digital Publishing Institute","2020-12","1424-8220","http://dx.doi.org/10.3390/s20247272;https://www.ncbi.nlm.nih.gov/pubmed/33352961","10.3390/s20247272","33352961","very small abstract","AE"

Now, I want to make the list from these data as a citation data without getting into complexities of _includes. I want to keep it simple in a separate "Publications" page.

For example, I used the following code

{% assign cards = site.data.references | sort: 'Publication_year' | 'reverse' %}
{% for card in cards %}
<ul>
  <li>{{ card.Publication year }} {{ card.Title }} {{ card.Publication }} </li>
  <ul> {{ card.Authors }} {{ card.Authors }} </ul>
</ul>
{% endfor %}

In the code, when I use the heading in csv as "Year" and then sort using sort: 'Year' | 'reverse' %,it works. Maybe, there is a different way to write it for "two-worded" headings, as I think the card.Publication year won't work. i have spent a lot of time on this and I think I need to just use the code once and then just work with the csv file only.

The output I intend to only pick up the Journal Article from the Item type and prepare a list with the following information with items shown in the following:

  • [Publication year][title][Journal]
    • [Authors]

    Also, I tried italisizing the text in one of the items, it should work like {{ __card.Publication year__ }} but it does not. I also read somewhere that the csv encoding doesn't allow to extract the first column due to some BOM or UTF-8 something encoding. But I want to filter using the item type.

    ps I have tried to compromise with another simplified code with headings same as this, but the google scholar exported csv has ; as delimiters and while using card.Authors does not work to call the data.

    I apologize I am not at all familiar with this and I am struggling with using this syntax. However, I foresee that if the code works, it will make my life easier. I would really appreciate your help. I apologize for any lack of proper jargon while explaining the problem.

    Thank you in advance.

    I tried to display the data from csv data file on the website but some values are missing. I cannot figure out the solution


    Solution

  • You're on the right track but you are incorrectly referencing the CSV file column. Since "Publication year" is a two-worded heading, you need to reference it using underscores instead of spaces.

    Try changing this line:

    {% assign cards = site.data.references | sort: 'Publication_year' | 'reverse' %}
    

    You can use sort_by instead of sort and provide 'Publication_year' as an argument.

     {% assign cards = site.data.references | sort_by: 'Publication_year' | reverse %}
    

    When you reference the column in the for loop, you should also use underscores:

    <li>{{ card.Publication_year }} {{ card.Title }} {{ card.Journal }} </li>