It wasn’t really supposed for the New Year, but I’ve had plenty of free time on my hands during the holiday break, so here it is already: a brand new version of my blog 🥳
Where to start? I got increasingly annoyed by the old version. The design started seeming boring and blunt. The code started growing unstable. It was using the Micrus framework, which I stopped supporting a year ago. It was using Micrus Assetic – an outdated method of asset management, which highly depended on the server configuration and binaries installed. The deployments were “iffy”, to say the least. I was afraid of sending even small changes to the server, for fear something might blow up again. Some small things I didn’t even notice were wrong: like still warning about Google Analytics tracking, even though I migrated to Matomo ages ago.
I decided to keep it simple. To go with a “less is more” approach. I’ve removed soooo many features that just weren’t useful enough.
I used to have an admin panel: except I didn’t need any fancy editor, the main content was written in an (enhanced) Markdown anyway. So for this version, I’ve decided for a filesystem-based approach: I’ve ditched the database completely, I don’t need any ORM, I don’t need an admin panel. I just have a bunch of SUML files tracked by GIT. Using Esse CMS.
I used to have three language versions of the UI – but why? I don’t think anyone really cared about not seeing the names of the categories in Polish, when most of recent my posts were in English anyway. So now the posts are still available in the language(s) they were written in, but I’m no longer maintaining the multiple versions of the UI, or the features to filter content by language. What a relief!
I used to have a “random post” box. I used to have tag clouds. I used to have an embedded Twitter timeline. I used to have the latest posts on the “about me” page (really?). I used to have a link shortening feature (”avris.it/l/<whatever>”) that I’ve never used, not a single time. I used to have a separate controller and database fields to support redirects for legacy URLs from the even earlier version. I used to have database fixtures. I used to have a console command to export legacy comments to Disqus. I used to have tooltips and popovers. All gone now! 😍
I replaced the infinite scroll with... just loading the whole page at once 🤷 It’s not that big for today’s standards anyway – the heaviest list of posts is 113 KB of compressed HTML. Instead, I now lazy load images using the IntersectionObserver
API. Way simpler than infinite scroll or pagination – which aren’t really necessary with this amount of data.
Oh, and the website is now using a fast an sleek Symfony setup with an HTTP cache 🥰
Design-wise, I use the default Bootstrap theme, with only minor changes of variables and minimal additional styling. The main feature, obviously, are the tilted elements. That’s enough to add some personality to the website, without making it overcomplicated. Compared to the previous version, it’s way more contrasting, better tailored for wider screens and clearer.
Overall, 41090 (!) lines of code were removed:
There’s nothing else in the (programming) world I love more than removing useless code!
Deployments are now stable, simple, reproducible and revertible, thanks to Symfony, Webpack, lack of database (no db = no migrations), and most importantly my recent child: Avris Deployer.
So, to finish this post, let me just quickly show you the four versions I’ve been through so far:
My first blog was called “Silva Idearum” (Latin for “Forest of ideas”). It was anonymous, spirituality-oriented, Polish-speaking, Joomla-running and with a “too much” design.
After coming out and becoming independent from my parents, I was finally able to put my name on my posts. New domain and a redesign was also in place.
As announced in Brand new blog…
A framework doesn’t have to be overly complex! Micrus provides you with a quick, easy and comfortable way of creating neatly structured, modular MVC websites, which can be easily extended and configured.
Our goal is to keep the framework as simple as possible, while offering all the most important features.
]]>Well, I did expect that. But I’ve recently realised I can only put some emojis (like “❤️”) in by blog posts. Most of them were just lost or replaced with “?” by MySQL... Oh, those damn encodings again!
But fortunately the solution is quite simple.
Instead of the utf8
charset, you need to use its superset, utf8mb4
. This one handles 4-byte characters and that’s exactly what we need. We just have to make both the database and Doctrine use it.
phpMyAdmin or Adminer let you change the charset easily. Just go to edit table schema and switch the collation of relevant columns and tables to utf8mb4_unicode_ci
. Since you’re going from utf8
to its superset, no data should become corrupted in the process. But just to play it safe, better create a backup before you start.
You might encounter an error: “Specified key was too long; max key length is 767 bytes”. That’s because of some limitations of InnoDB regarding indices length. To make an index into mb4
, you’ll have to shorten the max length of a column to 191 (instead of max 255 for simple utf8
).
When it comes to Doctrine, you have to specify the collation and charset on the level of an entity/table and on the level of the connection.
For an entity, if you’re using annotations:
/**
* @ORM\Entity
* @ORM\Table(options={"collate"="utf8mb4_unicode_ci", "charset"="utf8mb4"})
*/
Or if you’re using XML:
<entity name="Acme\DemoBundle\Entity\User">
<options>
<option name="charset">utf8mb4</option>
<option name="collate">utf8mb4_unicode_ci</option>
</options>
</entity>
As for the connection, go with:
$conn = \Doctrine\DBAL\DriverManager::getConnection(
[
'driver' => 'pdo_mysql',
'host' => 'localhost',
'user' => 'user',
'password' => 'password',
'dbname' => 'database',
'charset' => 'utf8mb4',
],
new \Doctrine\DBAL\Configuration()
);
Or in Symfony:
# app/config/config.yml
doctrine:
dbal:
charset: utf8mb4
Or in Micrus:
# app/Config/parameters.yml
database:
driver: pdo_mysql
host: 127.0.0.1
dbname: database
user: user
password: password
charset: utf8mb4
And that would be it (hopefully). Enjoy your new emoji support! 😊
]]>