
In the
first part, I described how it is relatively easy for a programmer to launch his personal website from scratch using Github, Heroku and Twitter Bootstrap.
But run the site a little. Most likely, you will want to periodically upload something to it. For example, new projects in the portfolio, or blog entries.
In this part, I’ll tell you how easy it is to create a publishing mechanism for your site, which will not solve anything for you (like most existing services), but will allow you to do everything as you like, allowing you to automate what you can automate.
')
Database - github
We will not use the DBMS. Site content will be stored in files, which, in turn, will be stored on github.
Thus, you do not need to take care of the backup, import and export of data. It is easy and convenient to work with files.
To add a page to the site or publish an article, you just need to create a file and save it in the repository. There is simply no place.
If you read the
first part of the article , then you already have a repository on github and you don’t need to do anything else yet.
Publishing System - docpad
Writing a blog in html-format is not the greatest pleasure. In addition, each page and article should at least specify a URL and wrap it in a common template.
Fortunately, there is a magic
docpad library that will take on all these boring tasks. I will not describe in detail what she can do, it is easier to follow the link and read there.
Those who know about jekyll or other static site generators may ask why docpad? I chose it because:
- It does not impose a method of its use. It can be used as a site generator, as an engine, as part of an engine, as a template engine after all. It has a convenient API that allows you to take exactly those functions that you lack, if necessary, implementing the rest yourself.
- It allows you to create dynamic pages, and not only statically generate them.
- Site content is organized into a convenient in-memory database with which you can do whatever you want.
If you want to discuss the pros and cons - welcome to the comments.
For now we will try all this in business.
We start the site framework
In the
first part of the article, I already described how to clone the repository on github and upload it to heroku, I will not repeat it. This time the code is here:
http://github.com/daeq/docpad-sample . Fork, clone, lay out on Heroku.
For the lazy, the simplest set of commands, provided the heroku-toolbelt is already installed.
git clone git@github.com: daeq / docpad-sample
cd docpad-sample
heroku apps: create docpad-sample
git push heroku master
After running this code, you will see the following site:
http://blog.programmer-site.tk .
Publish
Note the three folders:
- src / layouts - here are the page templates. They can be inherited from each other (see the index and post templates)
- src / public - files are located here that will be accessible from the root of your site (i.e. the src / public / favicon.ico file will be available at http: // <your domain> /favicon.ico)
- src / documents - here are the actual pages and texts.
Any folder can be configured. The configuration is in the app.js file.
Pages and texts docpad organizes into convenient collections. How to work with the collection, you can see in
src/documents/posts.html.eco
.
To add a new post to your blog, just create a new file in the src / documents / posts folder. Depending on the file extension, it will be processed differently. .html - for html-files, .md - for markdown-markup. Other formats are supported. If you don’t have enough of them, you can write your own plugin.
I personally prefer writing in
Markdown format. It is easy to write, easy to read, easy to convert to other formats, there are a lot of tools to work with it.
Now add the new file to the src / documents / posts folder, reload / restart the application, and see how the new one appears in the list of posts.
You may have noticed at the beginning of the file a block bounded by the characters
---
. This is the document metadata. A document usually has at least one metadata field - layout. You can add your own arbitrary fields, which are then used wherever you deal with this document. For example:
- Override the date field and sort the blog posts by it (and not by the date the file was created, as is done by default)
- Add the tags field, display the tags in the post layout and filter pages / posts by tags.
- Add a field series and in each of the posts of the series (for example, how this series of two posts about the programmer's site) display links to the other posts of the series.
Comments
We will not write our own implementation of comments. All done long ago for us. A short list of services that will allow you to add comments to your site:
I chose the third option, because it allows commenting not only the whole page, but also individual phrases in the text. Very cool for technical articles.
It looks like this:

Sharing
You probably want people to tell each other about your site. There are even more services that allow you to add a sharing widget than comment services. I chose
http://addthis.com . Simple, beautiful, and with good analytics.
The widget looks like this:

Collaboration
Your site will certainly have errors and inaccuracies. In addition, information becomes obsolete with time. It would be very convenient to give your readers the opportunity to correct something in your texts.
Fortunately, for this you do not need to do anything extra. Github gives you great functionality for this task. Just give a link to the file with the page in the githaba and anyone can suggest changes to your files, and you can view them and accept or reject them.
This is a
pull request mechanism. You can use it directly from the web interface.
You can try to
suggest changes to this article.
It seems that now we have a minimum set of functions for publishing on our site. It can be complemented and honed to suit your needs. Good luck!