In dire need of comments

My plan on how I will implement a comment board.

I recently migrated my website from ghost blog to hugo which is a static site generator compared to the all in one package you get with ghost blog. One of the reasons I decided to make this change was honestly, I had no need for all of the many features that ghost blog provided. Something like Hugo was simple, and effective. It also allowed me to write my documents in mark down, and store the entirety of it in a git repository. Making the portability of my website insanely simple, compared to managing the ghost blog.

One of the features I missed from ghost blog though, was the comment feature. Something I really enjoyed. With some Hugo blogs, they do enable you to add a comment feature, but requires that you have some kind of third party application that you sign up for. That pretty much was a no go for me. I don’t want to have my self or readers sign up for some ooey gooey third party provider. So because i’m lazy, I decided to create my own comment board.

Ive been learning rust for some time now so I settled on that language. It would be a good proof of concept and really help me get my foot in the door when it comes to getting confidence in the language.

Planning

Lets break down how we are going to do this.

  1. User must reach URL.
  2. User inputs the following, username, comment.
  3. User submits comment.
  4. Program submits comment to database after running it through some checks.
  5. Comment board is updated.

Now that we have a general road map there are quite a few things we can extrapolate from this. One, I can already imagine how my data will look. Two, we can create a general rest API from this point forward. Lets start with our data template

Data

I decided to go with sqlite because Im not sure that this website will ever get enough use that I will need to migrate away from an sqlite file. Although if it ever did, im sure it wouldn’t be too much more complicated to migrate to a MariaDB or a full fledged Sql database.

In general lets get what our data structure will look like

1
2
3
4
5
6
7
Comment {
    id: String,
    ip: String,
    username: String,
    timestamp: String,
    visible: int32,
}

You’ll notice there are a few things here that I have added besides the username and comment. One of them being ID. That will be our entry’s primary key. I plan on keeping the IP for governance reasons (issue bans, etc), as well as a timestamp, for historical records. The visible key, will be a simple 1 or 0. If it is 1 then it is visible. If it is 0 then it is hidden. Say I get a derogatory or inappropriate comment, I would’t want to necessarily delete it these comments should be kept to be referenced to for example for a ban appeal.I would want to especially keep them if it were to say be life threatening etc. So to prevent displaying it, I will switch the visible to 0 and contact or inform the police of said threat. This way, I still have the comment but its not visible.

API

From the requirements above, theres a few things we can already build out API wise.

  • /comment/new
  • /comment/id/
  • /comment/ip/
  • /comment/username/

Building out the API this way also allows us to tailor, how and what we write when we begin to create our program. I now know that I will need quite a few get functions that return data based off of 3 unique queries. I can also identify that I only need one query to create any data.

I hope that by now you can very clearly see the benefit of planning your program out, before actually typing any code. This will help you keep from getting lost while creating your program.

Thats about it for the theory on how this comment board will work. In the future, when i’ve got everything figured out. I may look into creating either a tutorial series on what i’ve done so far, or create youtube videos (as there are not many tutorials out on youtube for rust quite yet).

Licensed under GNU General Public License v3.0
Built with Hugo
Theme Stack designed by Jimmy