7.7 KiB
title | date | tags | author | ||
---|---|---|---|---|---|
Want to Learn a New Language? Write a Blog Backend! | 2022-03-02 |
|
Twi |
Most of the content on my blog requires a fair bit of technical context to understand. This post is aimed at beginners as well as people with a lot more experience in the industry. It also covers a question that I get asked a lot:
Here is a project that you can use as an end goal for learning to program in a new language: I call it Within's Minimal Viable Blog. With this project you will build a blog engine that can also function as a portfolio site.
It's also designed to make you dip your toes into a lot of commonly used technologies and computer science fundamentals in the process. Namely it makes you deal with these buzzwords:
- State management (remembering/recalling things persistently)
- Basic web serving
- HTML templating
- Static file serving
- Input sanitization (making sure that invalid input can't cause JavaScript injections, etc)
- Sessions (remembering who a user is between visits to a page)
At a high level, here's what you should end up with:
- An abstract "Post" datatype with a title, publication date, a "URL slug" and content in plain text
- A home page at
/
that describes yourself to the world - A list of blog posts at
/blog
- Individual blog posts at
/blog/{date}/{slug}
- A
/contact
page explaining how to contact you - An admin area at
/admin/*
that is protected by a username and password - An admin form that lets you create new posts
- An admin form that lets you edit existing posts
- An admin form that lets you delete posts
- An admin view that lets you list all posts
- Use a CSS theme you like (worst case: pick one at random) to make it look nice
- HTML templates for the base layout and page details
For extra credit, you can do the following extra things:
- Add an "updated at" date that shows up if the post has been edited
- Add tags on posts that let users find posts by tag
- JSONFeed support
- "Draft" posts which aren't visible on the public blog index or feeds, but can be shared by URL
- Use CSRF protection on the admin panel
- Deploy it on a VPS and serve it to the internet (use Caddy to make this easier)
- Pagination of post lists
If you've never done a project like this, this may take you a bit longer. You will have to do some research on the best way to write things in your language of choice. A good starting language for this is something like Python with Flask or Go with the standard library, namely with net/http and html/template. This may take you a week or two. If you've done this kind of thing before, it may take a few days to a week depending on how much experimentation you are doing.
What the heck is a "URL slug"?
Here are a few steps that may help you get started doing this:
- Serve a static file at
/
that contains<h1>Hello, world!</h1>
- Create a SQLite connection and the posts table
- Insert a post into your database by hand with the
sqlite3
console - Wire up a
/blog/{date}/{slug}
route to show that post - Wire up
/blog
to show all the posts in the database - Make static pages for
/
and/contact
- Choose a templating language and create a base template
- Edit all your routes to use that base template
- Create the admin login page and a POST route to receive the HTML form and check the username/password against something in the SQLite database, creating a session for the admin panel
- Create an external tool that lets you manually set your username and password
- Create an admin view that shows all posts
- Create a form that lets you create a new post and its associated POST handler
- Create a form that lets you edit an existing post and its associated POST handler
- Use a CSS theme to make it all look nice
There are no wrong ways to do this. You can take shortcuts where you want. You can use Markdown for formatting posts. You can do anything you want based on this skeleton and it will be your creation. Nobody else will have something exactly like this. It will let you stand out as a professional and can help you create your own home on the internet.
If you do go through with this and want to show it off to people in a followup post, email your results to blogchallenge2022@xeserv.us with the following information:
- Your name/alias (you don't have to use your legal name)
- How much background you have in programming
- The language you are writing this in
- Screenshots you want to share
- Anything you learned along the way, where you got stuck, what got you unstuck and anything else you want to say
- If you uploaded it to GitHub, the repository URL would be nice but is not required
- If you deployed it to a server, the link to where it's running would also be nice but is definitely not required
The road to expertise is paved with the effort of experimentation. I hope that this open-ended project can help you learn things.