Skip to content
Coding4GaiAmaOpen Source straight from the jungle

Table of contents

Cover showing GatsbyJS & Leasot Logos

#Gatsby Transformer Leasot

Last updatedOriginally published

2020-02-29 Released gatsby-theme-leasot for convenience.

2020-02-29 v1.2.0 adds internalType setting

I finally published gatsby-transformer-leasot 🎉 I started working on this half a year ago I believe, yet couldn’t manage to bring it to a state I’d feel comfortable releasing. In the last couple of days I could spare some time improving the API, convert it to Typescript 🚀 and improve the docs.

#So what does it do?

It extracts all comments in provided source files like the following

JavaScript
// TODO: water the seedlings

and makes them available to you via GrapqhQL as accessible object containing the comment along useful information.

JSON
{
"todo": {
"ref": "",
"line": 1,
"value": "find a more concise way",
"file": {
"relativePath": "gatsby-config.js"
}
}
}

#How to install it

Bash
yarn add -D gatsby-transformer-leasot
# or
npm i -D gatsby-transformer-leasot

It requires: gatsby-source-filesystem, this way you can use a separate instance to define which files to source only used by gatsby-transformer-leasot.
You can use gatsby-theme-leasot for convenience.
Alternatively, since v1.2.0, you can bring your own source plugin and set the internalType accordingly.

#How to configure it

gatsby-config.js
JavaScript
module.exports = {
plugins: [
{
resolve: `gatsby-source-filesystem`,
options: {
path: __dirname,
name: `leasot`,
ignore: [
/\.*.*\/(node_modules|\.cache|public|static|dist|\.yarn)\/./,
/\.*.\.(log|jpe?g|png|gif|ico|json|map|gz|pdf)/,
],
},
},
`gatsby-transformer-leasot`,
],
}

That’s the minimum required setup using the defaults.

#How to query

GraphQL
allLeasot(
sort: { fields: [todo___modifiedTime], order: DESC }
) {
group(field: todo___tag) {
fieldValue
totalCount
nodes {
id
todo {
tag
line
ref
value
modifiedTime(formatString: "YYYY-MM-DD H:mm") # More about modifiedTime below
file {
relativePath
}
}
}
}
}

Note: The name allLeasot depends on the provided sourceInstanceName in the configs. So when you change it you have to change the name option of gatsby-source-filesystem accordingly, lets say todo then you query for allTodo or todo if you just want a single one.

#All config options

nametypedefaultdescription
sourceInstanceNamestring‘leasot’Has to match the name prop of gatsby-source-filesystem.
customTagsarray[]Other tags to look for (besides todos and fixmes). Tags are case-insensitive and are strict matching, i.e PROD tag will match PROD but not PRODUCTS. More in Leasot’s Docs
modestring‘text’Supports one of: text, mdx, html.
truncateLinksint|object{length: 32,style: ‘smart’}Provide int to change the length only. style can be one of: smart, middle, end.
associateParserobject{}Associate the filetypes with parsers. This allows adding support for new filetypes. More in Leasot’s Docs
customParsersobject{}Extend the parsers by parserName, for example override the defaultParser or add a new parser. Leasot’s Docs
internalType
(since v1.2.0)
string“File”Has to match node.internal.type

All by default supported languages (file extensions) can be found in Leasot’s Readme

#More examples

JavaScript
// FIXME(Reference): improve example
// TODO: you can add a reference like this as well /Reference
// TODO: example without reference

See the full supported comment format by Leasot in their readme.

#Sadly

Even though the node in GraphQL also provides modifiedTime of the file it’s currently only locally useful as file times will all be the same on CI. I don’t have an easy fix for that so far.

#Alternative todo lists

I’ve installed & tried VSCode extensions like TODO Highlight and some others yet never really remember to let them generate the list to see my notes. Global search could work, too. Yet I find this automatic integration much more pleasing. And making it public kinda helps at least trying to get back to those notes so they won’t stick around forever 😅. Let’s see how that goes 🤓.

#The near future

This website is not only meant as my / GaiAma’s dev knowledge base, but as a playground and place to try things out before implementing on GaiAma.org 😉

My next plans are improving the donation experience on GaiAma.org, then, or maybe along that, improving the various open source projects and probably releasing more stuff, not just to share them with others but with myself, too. 😁

Some time in the near future I think about merging this repository with GaiAma/gaiama.org, not exactly sure about that though. 🤔 One benefit would be that the roadmap could then easily show GaiAma.org notes as well, without having to source it from GitHub. Just thinking out loud.

#By the way

truncateLinks uses remark-truncate-links which I open sourced separately. I use it for all MDX content as well. It’ll truncate all links not manually named. Go check it out 🤩

Find it on GitHub & NPM

Discuss on Twitter
Share

Can Rau

Open Source & Rainforest Maintainer at GaiAma.org 🌴