inukshuk / jekyll-scholar

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

Access to raw bib entries ? #279

Open maxandersen opened 4 years ago

maxandersen commented 4 years ago

Can I get access to the bib entries as data structures to use my own layout and not be bound by

    nor Csl styles ?

inukshuk commented 4 years ago

If you define a custom template you have access to the entry as well as the formatted reference string. Some special fields are added to your entry, for example, entry.author should give you the author string, but if the names satisfy bibtex name formatting, you can also get them parsed in entry.author_array (each name should have first/last name).

maxandersen commented 4 years ago

I changed the custom template as a workaround for now but I still get forced add of <ol>, mangled the author field by the CSL style and without ability to use liquid expressions as queries it is quite tedious to get the results i'm looking for.

I would essentially just like to get access to the bib entries just like you can with posts and use them in my custom layout.

inukshuk commented 4 years ago

You can set the bibliography_list_tag option to div in the config to get rid of the ol. But if I understand this correctly, you want to access all entries globally, i.e., outside of a specific bibliography tag? If so, that's currently not implemented.

maxandersen commented 4 years ago

yeah, basically I would like to do something like:

  {% for entry in site.bibliography --query @*[year=2013] %}
        <item>
            <title>{{ entry.title }}</title>
            <link>

to allow for full control over grouping etc.

the existing functionality is great for sticking to "classic" bibliography but sometimes I would like to do some more dynamic/custom stuff with the data :)

inukshuk commented 4 years ago

Yes, that looks pretty useful. Are parameterized variables possible in Liquid?

If not, a quick solution might be to add a new parameter to the bibliography tag which stores the entries into a page variable, instead of rendering them. So you would do something like: {% bibliography --query x --assign y%} to store the result in a variable y.

maxandersen commented 4 years ago

not sure if parameterized variables possible but filters are available, like

{% for post in site.posts limit: 5 %}

could be a start at least.

rateldajer commented 4 years ago

Yes that would be useful. I'm trying to create a way to expose the keywords in a bibtex file into a list of publications and publications details pages. At first I was trying to do this with layouts but I think something in the implementation would need to change or it would require what @maxandersen was requesting, full access to the bib datastructure so we could easily create a list of keywords and iterate through them.

rriemann commented 4 years ago

yeah, basically I would like to do something like:

  {% for entry in site.bibliography --query @*[year=2013] %}
        <item>
            <title>{{ entry.title }}</title>
            <link>

I like to iterate over the bibliography to get a list of locations from my bib entries. Is this for loop working?

DanAndersen commented 4 years ago

Has there been any update on enabling this kind of functionality? I'm setting up a page for my research lab and am currently hindered by the lack of support for getting at the raw entry data (i.e., without all the <ol> <li> tags getting put into the output. Attempting to replace them all with <div> leads to unwanted mangling of the output. Even just having that --assign y feature that was mentioned above would be a lifesaver.

mdave commented 4 years ago

I was playing around with this myself; I don't think there's an easy way to have the syntax suggested above, but for example to set site.bibliography to a list of all entries for a query you could use the following minimal plugin:

module Jekyll
  class Scholar

    class BibVariableTag < Liquid::Tag
      include Scholar::Utilities

      def initialize(tag_name, arguments, tokens)
        super

        @config = Scholar.defaults.dup

        optparse(arguments)
      end

      def render(context)
        set_context_to context

        # Add bibtex files to dependency tree.
        update_dependency_tree

        items = cited_entries

        context['site']['bibliography'] = items.map { |entry|
          {
            'data' => liquidify(entry),
            'key' => entry.key,
            'type' => entry.type.to_s
          }
        }

        ""
      end

    end

  end
end

Liquid::Template.register_tag('bib_variable', Jekyll::Scholar::BibVariableTag)

Usage would then be something like:

{% bib_variable -f journal-abbrev.bib -f pubs.bib -q @article %}
{% for entry in site.bibliography %}
  {{ entry.key }}: {{ entry.data.title }} <br />
{% endfor %}

You can then repeat that block in your template if you want multiple calls to bib_variable. If there's interest in that approach (and this is not considered too hacky -- I'm no Ruby expert), I could try to work this into a PR.

maxandersen commented 3 years ago

the key part is to get have the ability to use the query expressions to filter the data imo.

if thats doable in your suggestion via the "-q" that sounds great imo.