npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gatsby-transformer-bibtex

v0.1.5

Published

Gatsby transformer plugin for bibtex files

Downloads

68

Readme

Gatsby transformer Bibtex

This plugin relies on gatsby-source-filesystem to detect bibtex files in your project and provide the associated nodes in GraphQL queries.

Usage

Adding the plugin

In your gatsby-config.js, add gatsby-source-filesystem and gatsby-transformer-bibtex, making sure that the former is before the latter.

plugins: [
  // ...,
  {
    resolve: `gatsby-source-filesystem`,
    options: {
      name: `documents`,
      path: `${__dirname}/src/assets/documents`,
    },
  },
  'gatsby-transformer-bibtex',
  // ...
]

The path you specify in the options of gatsby-source-filesystem must contain all the bibtex files, with a .bib extension.

Static Queries

Once added, the plugin will add Reference nodes to your GraphQL queries, allowing you for example to write the following query in a StaticQuery component or a page:

query {
  allReference {
    edges {
      node {
        key
        title
        authors
        journal
        date
      }
    }
  }
}

Special fields

Every field is simply the string value that was in the corresponding Bibtex entry, except for some fields that have a special behaviour.

  • The entry_type field contains the type of the entry. For example, an entry starting with @article{... will have "article" in its entry_type field.
  • The date field is either the provided issue_date if it exists, or year if it does not. It is always a string.
  • The authors field is a list of the authors' names, that has been extracted from the bibtex.
  • The raw field contains the entire bibtex entry as a raw string.
  • The youtubeId is created if a youtube field is in your bibtex file. If your youtube field contains a youtubeId, it's just copied, if it contains a youtube link, the id is extracted from it.

Working with files

It is possible to work with local files, and to create fields of type File in your nodes. If in every of your entries, for a given field, the value is not specified (null) or it is a relative path to a file, then Gatsby will transform it into a File field provided by gatsby-source-filesystem. In particular, this field contains a publicURL field that is useful if you want to add a link to the file.

For example, if the path you gave to gatsby-source-fileystem contains

publications
    ├── paper_a.pdf
    └── publications.bib

where publications.bib contains

@article{some_key,
 author = {Name, Your and Of-Yours, Coauthor},
 title = {Paper A},
 ...
 file = {paper_a.pdf}
} 

In the code above, paper_a.pdf should be replaced by a path relative to where the .bib file is. Note that the parser does not handle comments, bibtex file should be kept comment-free.

I would also advise to keep the bibtex entries as simple as possible, since gatsby-transformer-bibtex has to handle fields manually, so only a limited amount of field will be working correctly.

Then you can create a component in the following way:

import React from "react"
import { StaticQuery, graphql } from "gatsby"

const ComponentName = () => (
  <StaticQuery
    query={graphql`
      {
        reference(key: {eq: "some_key"}) {
          file {
            publicURL
          }
        }
      }
    `}
    render={data => <a href={data.reference.file.publicURL}>Link to Paper A</a>}
  ></StaticQuery>
)

export default ComponentName

Contributions

This project is not extremely mature, but I've had feedback that it is used. PRs and issues are more than welcome 😁

LICENSE

This project is under MIT License, see License file.