I contributed to geeksblabla 🎉, the whole story
Sat Nov 09, 2019 · 634 words

Hello Again 👋 A Week or so ago, I discovered Geeksblabla’s github repo, and was blown by the amount of work put there by the community. So I decided to contribute to it. Fortunately, there is a chance for everyone (Even for those who do not know React) to contribute through adding and modifying episodes Notes. In this quick post, I’ll try to share with you what I learned while contributing to geeksblabla, and how I used what I learned in my own blog.

The Git Stuff

First things first, I forked the repo, created a local branch for the episode, opened my text editor with ep22’s video on the side and started adding the notes.

1$ git clone https://github.com/iduoad/geeksblabla.com.git
2$ cd geeksblabla.com
3$ git checkout -b notes/ep22
4$ vim blablas/ep22/index.md

One hour later, notes are ready for the commit - merge - push.

1$ git add ep22/index.md
2$ git commit -m "added ep22 notes"
3$ git checkout master
4$ git merge notes/ep22
5$ git push origin master

and Tada !!

Then I created a pull request, and after a few requests for change my pull was accepted by the awesome Youssouf 🙌.

Spelling mistakes.

A day later, I re-read the notes, and realized that I’ve made some spelling mistakes here and there. So I started the boring hunt for those spelling mistakes, and while doing so an idea came to my mind.

Why not the automate the process of spell checking and maybe correction ?

Right away, I opened a new tab and googled “aspell travis ci”! Huuray It seems that I am not the first one to think of the idea 😅. I found this awesome blog post which describe almost exactly the same case as ours. It took me some minutes to realize that the project does not rely on travis or any other CI tool, and integrating one with it for the sake of spelling mistakes would be a little bit cumbersome. From the other hand, I don’t think that blocking commits, merges, deployments… because of spelling mistakes is good idea 😛. Still, I am too lazy to execute aspell manually every time I have to add a note.

Git Hooks

I knew about them before, but I’ve never came near them ! And this was the best time to learn about them. Git hooks are scripts (written in whatever scripting language you want) than get executed before or after git events (commit, push …). You can learn more about git hooks here ! All we have to do is cd into .git/hooks folder and create a shell script named “hook-name” in our case, we used the pre-commit hook. Pre commits hooks, as their name suggest get executed before commits, if their return status is other than 0 the commit will be aborted.

The most basic, pre-commit script we can create is the following.

# get names of changed markdown files
MARKDOWN_FILES_CHANGED=`(git diff --cached --name-only || true) | grep .md`
# cat out the all the changed files
TEXT_CONTENT_WITHOUT_METADATA=`cat $(echo "$MARKDOWN_FILES_CHANGED" | sed -E ':a;N;$!ba;s/\n/ /g')`
# look for misspelled words
MISSPELLED=`echo "$TEXT_CONTENT_WITHOUT_METADATA" | aspell --lang=en --encoding=utf-8 --personal=$HOME/.local/share/aspell/.aspell.en.pws list | sort -u`
# check if there are misspelled words or not
if [ "$NB_MISSPELLED" -gt 0 ]
then
    echo "Words that might be misspelled, please check"
    MISSPELLED=`echo "$MISSPELLED" | sed -E ':a;N;$!ba;s/\n/, /g'`
    echo "$MISSPELLED"
    exit 1
else
    exit 0
fi

In fact, this is not enough! Especially for our case. We need add more text filters to our markdown content. We need to strip the metadata and the heading tags out, and we need to extract the notes section only too. A little bit of sed and grep commands did the thing ! you can check out the entire script here !

Thank you for reading, see you the next time 👋


back · About · Blog · TIL · Links · Projects · Contact ·