DEV Community

Samina Rahman Purba
Samina Rahman Purba

Posted on • Updated on

Rwar – A Simple Static Site Generator Written in Python

Week 2 of Open-Source Development and I can already feel the pressure building up.

What is rwar?

I created rwar, which is a simple bare-bones Static Site Generator (SSG) with minimal features. An SSG allows a user to generate a complete HTML website from raw data and files, without having to write out the HTML themselves. Rwar is a command line tool that takes .txt files as input and generates .html files as output.

The Features

  • It takes .txt files as input and generates .html as output. For example if I input a file ‘test.txt’ then ‘test.html’ will be generated.

  • It allows the user to specify a different output directory using --output or -o. If not specified, dist will be used by default.

  • It allows the user to specify a stylesheet of their choice.

  • The user can specify a folder for the input, which automatically generates an index.html file, containing relative links to each of the generated HTML files.

The Setup

Please check the GitHub repo for cloning and using the project.

As Written in the

  • Please ensure Python 3 is installed.

  • The requirements.txt file lists all the dependencies needed for rwar
    Please ensure Python 3 is installed.

  • The requirements.txt file lists all the dependencies needed for rwar

  • To satisfy these requirements run the following command pip install -r requirements.txt
    You can then run the program by running the following command:

python3 -i <input> # (For input either put .txt file or specify the directory containing txt files)
Enter fullscreen mode Exit fullscreen mode

If you are in a Unix environment, you can use the following commands to run:

chmod +x # This will make the file executable
./ -i <input> #works in macOS or Unix based systems
Enter fullscreen mode Exit fullscreen mode

Note: If you are not using bash, you may need to use python instead of python3.

  • The program will generate a static site in the ./dist directory within the project by default. You can change this behavior by using the -o flag. If you choose to specify your desired directory, it will create dist as a sub-folder within the directory you specify.
  • You can also provide a custom stylesheet by using the -s flag.
  • To see all available options, run the following command: ./rwar -h or python3 -h

The Learning Curve

For this project, I chose to use Python, a language I have been wanting to learn for the longest time. I even purchased a Udemy course months ago to learn Python – “100 days of Code in Python” – but due to ongoing assignments, my obsession with procrastination, and work pressure, I just could not move beyond Day 2 of the course. This Static Site Generator assignment paved the path for me to take those first steps toward learning the language. The other rationale behind using Python was that many of the jobs I intend to apply for after graduation listed knowledge in Python as a requirement.

It was not easy for me to implement rwar, and I spent two days just learning new things and planning out how the implementation would work. After spending hours on my learning curve to the point that I started panicking about the approaching deadline – I finally got started on the coding part.

I am used to working with step-by-step guidelines on how to start and implement a project. But this was different. Without a proper blueprint or requirements list, I felt lost. Overcoming inertia and gaining enough momentum to see some real progress was challenging. However, instead of viewing the entire project as one giant piece – I broke it down into smaller digestible pieces. Upon doing that, the entire project seemed less intimidating. In fact, I took my time and went beyond just implementing the required features and added as many extra features as possible.

The Disaster

Trying anything new also comes with some risk, and guess what? This project did too! While creating the option for letting the user specify the output directory of their choice with the ‘-o’ flag I accidentally deleted all my folders on my desktop. Poof. It was all gone. I sat in shock for 10 minutes before realizing the magnitude of the loss.

Did I accidentally create malware and infect my machine? How did it just all go away?

Part of the requirement for this project was to ensure every time the user inputs a .txt file, that the old contents in the generated dist folder get cleared and a new one gets created. Upon specifying my output directory as my desktop with -o, it cleared my entire desktop, except for one folder that was resilient enough to not get deleted. How and why, that happened is still a mystery to me. I am seeking answers. I was able to fix that issue through a try-catch block, which took me about half a day.

The Overall Experience

I learned a lot through this project and shed some tears as well when I realized that seven out of eight folders on my desktop disappeared without a trace. I did try using some fancy SetApp tool to bring those back but had no success.

The Rwar Demo

The Rwar Demo contains some test cases illustrating rwar’s capabilities. I used the sample folder provided by the professor and two of my custom text files which was a set of poems written by me during the pandemic lockdown months under the title ‘Turkish Delight’ and a science fiction story written for EAC384 -Creative Writing class at Seneca. The pandemic lockdown forced my partner, Batuhan, and I to be geographically separated for two years across the globe – so we did as much fun stuff as possible online. I wrote him silly love poems and he wrote me some cool bash scripts that I ran on my Mac's terminal.

Next Steps

I am excited to keep working on this SSG! I am looking forward to adding more features and improving the look of the html files generated.

I hope you enjoyed reading my long blog post. Thank you!

Top comments (0)