DEV Community

Kien Nguyen Chi
Kien Nguyen Chi

Posted on

OSD600 - Week 2 - Release 0.1

This week my task is to create a Static Site Generator (SSG) tool with any languages that I'm comfortable with. I choose C++. Although sometimes I feel it's hard for me, I still love C++. I name my SSG tool is Potato Generator.

Basically, this tool receives input from a text file or a folder name in order to generate a single HTML page or a main page controlling a list of websites. The inputs for Release 0.1 of this tool is basically text files containing short stories with a title and paragraphs.

I create a class named HTMLFile to control all the functionalities of a single website. It reads the input from a text file, push back each paragraph of the text file into an element of vector. I use a string to control the HTML content. First index of the vector is the name of the story. I use it to create title and header h1 for the HTML page. Then, I loop through the vector to build paragraphs. All things are added up to a HTML string. Then I create a new html file, write the content to it. And I have a single HTML Page generating from a text file.

I create a class named MainPage when user inputs a folder. A main page will have a navigation bar directing to each HTML page. The MainPage class will loop through list of files in the folder and generate each HTML file itself.

In the pgprogram.cpp containing main function, I check for the input arguments of the users. Users can enter -v or --version to check which version of my program is. Users can enter -h or --help to see the instructions to run the program. Users can enter -i or --input to specify which file/folder for the program to process. Otherwise, program works with file/folder-name argument itself without -i or --input.

Also, I create a CSS stylesheet myself to make the beautiful webpage. The main color is light-pink. Black texts are printed on each white div. I also choose the text, which is so young and pretty.

To run the program, there are two ways:
1/ On CMD, enter command pgprogram fname. (Where fname is the name of a file/folder)
2/ Specifying arguments:

  • Version: pgprogram -v / pgprogram --version
  • Help: pgprogram -h / pgprogram --help
  • Input: pgprogram -i fName / pgprogram --input fName

For further details, please visit my Git Hub for clear instructions and images: https://github.com/kiennguyenchi/potato-generator

Otherwise, you can take a look in my generated websites from the tool at: https://gifted-brattain-2278d4.netlify.app/sherlock-holmes-selected-stories/sherlock-holmes-selected-stories

Discussion (0)