post2blog : Updating from postToBlog to post2blog.

15 Nov 2018

Installation

post2bolg is a shell script that posts a markdown file to a Github.pages hosted personal blog from terminal. The blog must be powered by the Jekyll. To use it, simply copy the shell script post2blog.sh into any directory you want and symlink the file to a directory that is included in your $PATH, for instance /usr/local/bin, then reopen the terminal. You should be good to go by then.

post2blog is a updated version of postToBlog. The main diffidence is that post2blog could handle linked files, such as images and documents, automatically. Please note that the script will only copy local files to your github.io. Hyper links that start with http or https will be left alone.

Setup

Open post2blog.sh and change the following as indicated. To see your defaults, use -h option.

  1. change the value of _my_repository_addresses to the directories of your blog’s repositories, which usually named like <YourGithubCount>.github.io. The script will use the first one by default.
    _my_repository_addresses=("Directory to your github.io" "Directory to your github.io")
    
  2. change values of _posts_address and _posts_sub_address to the relative directory of your posts’ directory with respect to their upper directories. Normally, the value of _posts_address is _posts/ and doesn’t need to be changed. Meanwhile, the _posts_sub_address is added to classify your files to a default folder.
    _posts_address="_posts/"
    _posts_sub_address=`date +"%Y-%m/"` #classify your files by yyyy-mm for instance
    
  3. change the value of _assets_address to the relative directory of your assets’ directory with respect to the directory of your github.io’s repository. Typically, the folder is named as following.
    _assets_address="assets/" #directory of your assets
    

    As for the classification of images and documents. The script will create folders named by yyyy-mm under your assets’ folder. That is to say, your files will be sorted by month. Moreover, all files will be renamed by using the hyper keys. For example, the output filename for a hyper link with the key value [This is a test name] is This-is-a-test-name.

  4. specify a default input filename by setting _mfile. This will save you some time I think.

  5. setup head information that is needed by the Jekyll for configuring your post. The value of _layout must be defined in the Jekyll’s styles.
    _layout='post' #using the layout named post
    _categories='Command Line Tools' #example category
    _tags='shell,git,jekyll' #example tags
    

Usage

postToBlog [-i<markdown-file>] [-l<layout>] [-T<title>] [-c<categories>] [-t<tags>] [-s<sub-directory>] [-S] [-V] [-r] [-h]

Options

With proper settings, no argument is needed to run the script most of the times. Use following options if it’s not one of those.

Example

To post the file your are reading now I used

post2blog -i README.md -c "Command Line Tools" -t "Shell,Git,Jekyll"