Hexo Encounter Travis-ci: Probably the most understandable automatic publishing blog text tutorial

Source: Internet
Author: User

I believe many students have their own blog, if not, you can see the "Hexo Station: Deployment to GitHub", using Hexo and GitHub pages services to build a beautiful and convenient blog, hexo You can write the MD document parsing into HTML pages, Finally, a Web site can be formed with git pushed to GitHub. Hexo Publish Blog Process build Hexo Environment (a series of software installation, configuration) Hexo new post "article name" to write MD document HEXO clean Hexo generate Hexo

The above first step generally only in the first time to build the need to do, follow up as long as the implementation of 2~6 step. But there are situations where you need to post blogs on different computers. What if you reload the system. Does it need to be a new one? To know the most tedious step is the first step, which can be divided into a lot of steps to do, read the above blog or you are using HEXO+GH Manual publishing Blog students know how painful.

Today I would like to introduce the use of TRAVIS-CI this continuous integration platform to simplify the release process, simplify the process: the preparation of the MD document GIT push

The use of Travis greatly improves the efficiency. is not very attractive. Travis-ci Introduction

Travis CI is an open source continuous integration build project that is used to build code that is hosted on GitHub. It provides support for a variety of programming languages, including Javascript,java,scala,ruby,php,haskell and Erlang.

Every time we do a git push, Travis CI automatically detects our submission and then according to the configuration file. TRAVIS.YML helps us automatically generate and deploy static Web pages. Prior Preparation Push Hexo Blog Source to GitHub CD into your local Hexo blog folder, which is the folder that you enter when you want to publish your blog. Push all your local Hexo blog source files to GitHub.
Push Tutorial: How to submit code to GitHub

Note: Not hexo deploy Update blog repo. Instead, the local blog is hosted directly into the GitHub.

The author directly hosted the local Hexo blog source to the Xiong-it.github.io hexo Branch, the blog site is in the default master branch. If you don't want to take branch management, you can also host a local Hexo blog to a standalone warehouse, but it will be different when configuring Travis synchronization. This article adopts the branch management method. Configure GitHub Token

Now that you need to use Travis Automation to update your blog, Travis naturally needs to read and write repo on your github. GitHub provides a token mechanism for external access to your warehouse.

Enter the Https://github.com/settings/tokens, generate a Travis to read and write your GitHub used token, as for the token permissions, the author directly selected, but do not recommend this, the risk is relatively large, token pay attention to secrecy, We'll use that later.
Configure Travis-ci

Use GitHub account login Travis, if there is no GitHub account of the students, you can refer to the "How to submit code to GitHub" register a GitHub account. Travis into warehouse synchronization management

Enter Https://travis-ci.org/profile, Open just managed Hexo blog Source Warehouse Sync switch, not necessarily blog site repo. As the author directly to the local Hexo blog source to host the Hexo branch of the Xiong-it.github.io, so it is to open the site repo. If you are not taking the branch management, but will Hexo blog Source Trust channel Independent repo, open the corresponding github repo switch can.
As shown in figure:
Travis Settings

Click on the red circle in the picture above, enter the Setup page, set the automatic compile time, and automate the variables to be used in the compilation process.

The meaning of the above setting is that only if the. travis.yml file exists, it must be selected. When the warehouse/branch update is compiled, that is, after the push to compile the meaning of the general will need to choose to facilitate automated construction. With gh_toekn variables, value values are written for the token string prepared in the preliminary work . travis.yml file

. TRAVIS.YML is a configuration file that is automatically built by the Travis Platform, Travis generates a shell automation script based on the configuration file.

Enter Hexo Blog Source local repo

CD Hexo Touch
. Travis.yml
vim. travis.yml

. TRAVIS.YML examples are as follows:

# Specifies the locale
language:node_js
# Specifies that sudo permission
sudo:required # is required to
specify NODE_JS version
node_js: 
  -7.9.0
# Specifies the caching module, optional. Caching can speed up compilation.
cache:
  Directories:
    -node_modules

# Designated blog Source branch, varies from person to person. Hexo Blog Source Hosting in an independent repo you do not have to set this
branches: only
  :
    -Hexo 

before_install:
  -NPM install-g hexo-cli

# Start:build Lifecycle
Install:
  -npm Install
  -npm install hexo-deployer-git

# perform clear cache , generate Web Operations
script:
  -Hexo Clean
  -Hexo generate

# set git submit name, mailbox, replace real token to _config.yml file, finally DePoy deployment
after_script:
  -git config user.name "yourName"
  -git config user.email "youremail"
  # replaces the same directory with _ The Gh_token string in the Config.yml file is the variable that was just configured in the Travis background, note that the SED command uses double quotes here. Single quotation marks are not valid.
  -Sed-i "s/gh_token/${gh_token}/g"./_config.yml
  -Hexo Deploy
# End:build lifecycle

Modify the Deploy node for the following _config.yml file:

# Modified before
deploy:
  -type:git
    repo:git@github.com:xiong-it/xiong-it.github.io.git
    branch:master
# modified
Deploy:
-type:git
  below Gh_token will be replaced by the. travis.yml sed command
  repo:https://gh_token@github.com/ Xiong-it/xiong-it.github.io.git
  Branch:master

YML Sample Portal

Finally, two yml file push update to HEXO blog Source branch or independent repo, will be successful in the Travis background to see the first build.

Welcome to visit my personal Hexo blog: Http://xiong-it.github.io is done

After each update blog, only need to write MD files, put into the hexo/source/_post/folder, Git Add,commit,push, push operations can also directly use the token just requested, without the need to configure SSH on different computers with a common key.

git push https://<your_token> @github. Com/xiong-it/xiong-it.github.io.git Hexo:hexo

Travis will read the Hexo blog Source branch of the. travis.yml file, automatically help us build and deploy the Web site.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.