[PYTHON] I made my own primitive static site generator

This article is also posted on My Blog, so please take a look if you like.

A major remodeling of my own something like a static site generator that I used on my blog for a long time. , I made a primitive static site generator "blogen.py". Click here for the repository: blogen.py

Why did you make it?

There are various static site generators in the world. Gatsby Yara Hexo Yara. There are several reasons why we did something like reinventing the wheel without using those sophisticated ones.

--I didn't understand how to use the existing static site generator ――I wanted to design the site myself ――I didn't like the fact that extra files were likely to be generated.

When I first started making this, I wasn't very motivated to learn, so I didn't like using new tools. ~~ It's still the case ~~ In the end, I was able to make something like that with my poor knowledge of Python. However, at that time, I didn't know the existence of HTML template engines such as Jinja2, and I didn't understand how to synthesize pieces of HTML files prepared in advance. After all, I rewrote it to use Jinja2, but I had a hard time because of such a rugged design. Knowledge is important.

function

At the time of writing this article, blogen.py has the following features:

--Article / top page generation function --Blog directory generation function --Notification Tweet function on Twitter

On the contrary, the functions that are not currently provided (I want to implement) are as follows.

--Writing an article by Markdown --Article categorization --Ability to divide the articles on the top page into n pages --Like button --Comment section

This is really the only feature I have implemented. There is also a feature that a link to share the article on Twitter is generated under the article (please check it out), but it is not a feature of blogen.py because it was just implemented in JavaScript. To put it the other way around, even with such a small number of functions, at least it can be established as a blog. This was a realization I couldn't get if I was using an existing tool.

merit

After creating and using blogen.py, I found some advantages of creating my own static site generator.

Easy to use

Well, this is natural because it is a self-made and ultra-low-performance tool.

You can design your own blog

Since I wrote the CSS completely myself, the design is almost completely free. I'm happy because this was one of my initial goals.

You can implement the features you want

Of course, it is a major premise that you have technical capabilities.

Technology improves

I think that it will increase the knowledge and implementation power because it will be messed up at the time of implementation. At the very least, it is possible to write quickly when you think "I want a little tool".

Demerit

Of course, it wasn't all good points.

Cumbersome to implement

You can't use it right away because you have to implement all the features yourself. It's a hassle. Well, that's fun too.

It will fail if not implemented properly

For example, if you do not allow you to adjust the number of articles displayed on the top page, it will theoretically be too large to load at some point. Besides, if you implement categorization, you will have to modify all articles. Even now that there are only a dozen articles, if there are hundreds of articles, the correction work will be very difficult.

Summary

When I googled with "Static site generator self-made", surprisingly everyone made their own static site generator. You are the only one who hasn't made it yourself. However, it is amazing that everyone has made it properly. Since blogen.py is made up of "I wish I could use it! W" -like glue ... But it's fun, I made my own static site generator. Would you like to try it once?

Recommended Posts

I made my own primitive static site generator
I made my own language. (1)
I made my own language (2)
I made my own AML
I made my own Python library
Lektor static site generator
I made my goimports
I made my own parallel link robot (software version)
I made my own parallel link robot (mechanical edition)
I made my own OSS because I wanted to contribute to it
I made a C ++ learning site
[Python] I made my own library that can be imported dynamically
Python> I made a test code for my own external file
I made my own filter plugin for text parsing of Ansible
Since I made my own smart lock, I will summarize the difficult points
I don't have the skills or strength, but I made my own compiler
I made a stamp generator with GAN
I made my dog "Monaka Bot" with LineBot
[I tried using Pythonista3] Importing my own module
I made my own Django Middleware so that I can access request information from anywhere