Hakyll for beginners

  • Tutorial
Once you, like me some time ago, decide to create your personal blog page (with or without). There are many ways to achieve your plan, depending on your programming experience, laziness level, and degree of stoop. But personally, it seems to me that starting a hosting and a domain and creating a serious “adult” website is just to show itself somehow too redundant. Therefore, to achieve this goal, you can go the simpler way - to make a static site.

Static sites are fast, secure, easy to publish, and can be managed through a version control system. Jasper van der jeugt


I hope that it is not necessary to provide evidence for what Jesper said, since everything is already quite clear.

That day, when I decided to make my personal page, I discovered that it is possible to post it on github. To publish, it will be enough to call git push -u origin master from your repository, so everything should be quite simple. But for starters, we need to find some kind of builder of static sites to use it once to set everything up, start it up, and then from time to time add our new posts, project information, so what would you like there. Setting up the most popular Jekyll solution on my Windows machine was somehow too problematic, because I climbed the Internet a bit and I found a great alternative -Hakyll . And since my hands itched for a long time to try something at Haskell, I decided it was worth a try. If you are interested in following in my footsteps, welcome.



Step 1. Installation.



A good start for us is to get hold of the Haskell Platform . After installation we will receive:
  • The Glasgow compiler is one of the most famous, if I'm not mistaken.
  • Interactive environment - both in console form and wrapped in WinGHC application.
  • Cabal is the package manager for Haskell. (Here I would like to note that in my humble view it is still a package manager, although other opinions on this subject can be read on the Internet ).


It seems to me that if you had no experience with Haskell for this, you just need to run ghci and try what it is. An alternative way would be to try for the first time on tryhaskell .
If you want to study Haskell in more detail, I can just recommend the wonderful book Teach Yourself to Haskell in the Name of Good"But I will tell you a little secret. You do not need to know Haskell in order to create your own blog on Hackell. If you already have some programming experience and you even know what a version control system is (and I’m sure it is and you know) this will be more than enough to finish reading all of the following.I would even say that you most likely would need html and css skills to customize the look of the default site to your preferences, but more on that later.

Step 2. Get Hakyll



We are already ready to be even closer to our goal, and cabal will help us in this. And a great idea would be to upgrade it.

> cabal update
> cabal install cabal-install


It will take some time for the package information to be updated and we are ready for the second magic command:

> cabal install hakyll


Done! Or not. We actually had to get the hackill after calling the mentioned command, but I personally got an error saying that there were no directories, and other horrors. Unfortunately, I did not waste time trying to find out what the matter was in detail, and simply asked the all-knowing Google. He proposed to execute the last command in a slightly different form:

> cabal install --flags="-unixFilter" --constraint="directory installed" hakyll-X.X.X.X 


Instead of XXXX, there should naturally be a version of the package, see which last one you can here : I dare only assume that the error could only happen because we use Windows with you, and some things are slightly less designed for us than for other OSs.

Step 3. Initialize the site.



Despite the fact that these steps are well described on the official page of the project, I will repeat here for integrity. The previous step was to reward us with the hakyll package, and therefore we open with you in the console the location of our future magnificent personal page and do the following:

> hakyll-init our_amazing_personal_site
> cd our_amazing_personal_site


Let's see what happened with us. And we got the following things:

  • site.hs contains a Haskell code that will later be compiled into an executable file to give us the opportunity to build a site and run, for example, a local server to see this site
  • index.html contains the content of our homepage
  • contact.markdown will be compiled to the “contacts” page
  • about.rst will be compiled to the “about us” page
  • templates daddy contains templates that later will help to build various pages of the site
  • images obviously contains pictures
  • posts contains sample posts in .markdown format
  • css contains styles for our site


Of course, you can change everything you want here, but before you do this, still make sure that you know the Haskell and have studied the contents of the site.hs. And of course, now is the time to go around and see what is contained in other files.

Now we will compile the executable file:

> ghc --make site.hs
> site build


You probably noticed that even more files appeared in our folder. Take a look at them:

  • site.o , site.hi and site.exe compilation product site.hs file
  • _site contains a compiled site ready to be open in your favorite browser. Hurrah! :)
  • _cache will contain caches as we walk around our site locally


If you installed a hackill with a preview server, call:

> site preview


and rush to the local host to see what happened with us. If your 8000 port is busy, then call:

> site server --port=5050


and try again to look at the result .

Step 4. Publish.



I hope that you already have your own account on github, well, or if not, then it's time to get one. In any case, after registration (or login), we create a repository with the following name: [your github username] .github.com

Now run gitBush, go to the _site folder created by the hackill and do the following:

$ git init
$ git add .
$ git commit -m "my amazing personal page with hakyll init"
$ git remote add origin [repository address github gently provided you with]
$ git push -u origin master


Phew ... We did it :) Now visit your repository and make sure that the push went perfectly. Well, finally visit your new wonderful page by simply typing [your github username] .github.com in the browser !

Epilogue.



If you think that the article is at least a little fit, write in a personal well or leave comments. Thanks :)

Also popular now: