DEV Community

Cover image for The devto module
Victor Avelar
Victor Avelar

Posted on

The devto module

⚠️ The module is up and awaiting for review ⚠️

Here is the source code

Thoughts on the process

There is a lack of explicit information on how to create modules, so if you are eager to create a module you will need to read tons and tons of code.

Another thing that I found tricky was properly configuring the keyboard integration, but there are amazing modules with this feature that you can copy and modify.

Make sure to read the CONTRIBUTING.md file before starting, it will allow you to plan the development with all the requirements.

Finally, please update the docs, if you take a look at the source code, you will find a lot of good modules that have poor or no documentation at all.

The process

  1. Get familiar with Go Modules as it is the dependency management system used by wtfutil/wtf.

  2. Check the existing modules so that you can get ideas and also so that you understand how everything works.

  3. If you're going to install some modules this is the time, for the current module, I just used the API client we built along this series.

    GitHub logo VictorAvelar / devto-api-go

    A go client for the dev.to API

    devto-api-go

    A go client for the dev.to API

    License: MIT

    Travis CI

    Build Status

    Scrutinizer

    Scrutinizer Build Status Scrutinizer Code Quality Code Coverage

    Go ecosystem

    Go Report Card GoDoc

    Roadmap

    • Base client and configuration
    • Articles resource
    • CLI utility
    • Authentication resource
    • Extend the tests suite
    • Provide code examples

    Disclaimer

    This library is not an official dev.to API library, but a friendly contribution to the dev.to community

  4. Go to the modules directory and create a sub directory to start coding, for this module it is modules/devto

The files

It will be possible to have everything in one file, but I like to split the code so that the filename refers to the content.

After checking how the hackernews module works (which heavily inspired this whole series) I have a good idea of what I need.

In keyboard.go we are going to place all the keyboard bindings for our module, we need to be able to navigate from one history to another, and also we need to be able to open the content in our default browser.

So to make things easier, I will put here a screenshot from the module documentation:

Keyboard bindings

Code wise it is not that amazing, here you have the fragment that accomplishes this functionality

func (widget *Widget) initializeKeyboardControls() {
    widget.InitializeCommonControls(widget.Refresh)

    widget.SetKeyboardKey(tcell.KeyDown, widget.Next, "Select next item")
    widget.SetKeyboardKey(tcell.KeyUp, widget.Prev, "Select previous item")
    widget.SetKeyboardKey(tcell.KeyEnter, widget.openStory, "Open story in browser")
    widget.SetKeyboardKey(tcell.KeyEsc, widget.Unselect, "Clear selection")
}
Enter fullscreen mode Exit fullscreen mode

In settings.go you grab the values from the user's config.yaml file and put it into your Widget.

Settings

And here is the yaml to use this module:

devto:
  enabled: true
  numberOfArticles: 10
  position:
    top: 1
    left: 1
    height: 1
    width: 2
  contentTag: "showdev" 
  contentUsername: "victoravelar"
  contentState: "rising"
Enter fullscreen mode Exit fullscreen mode

And finally the widget.go, TBH this is just the hackernews widget file with some customization to make it work with the dev.to API.

Conclusions

It was not as hard as expected, and I hope a lot of people is able to get the articles from this community straight to their terminal.

Do your own and please let the world know.

Top comments (0)