# Hexo 入門指南(二) - 安裝、初始化和配置
## 安裝和初始化 ##
linux下打開bash,win下面打開cmd,輸入:
```
$ npm install hexo -g
$ hexo init blog
$ cd blog
$ npm install
$ hexo server
```
訪問[http://localhost:4000](http://localhost:4000),會看到生成好的博客。
同時,在blog文件夾中,文件如下:
```
2014/11/01 19:45 <DIR> .
2014/11/01 19:45 <DIR> ..
2014/11/01 11:16 68 .gitignore
2014/11/01 17:33 13,767 db.json
2014/11/01 11:16 <DIR> node_modules
2014/11/01 11:17 186 package.json
2014/11/01 11:23 <DIR> public
2014/11/01 11:16 <DIR> scaffolds
2014/11/01 17:31 <DIR> source
2014/11/01 11:16 <DIR> themes
2014/11/01 11:38 1,844 _config.yml
```
## 配置 ##
站點的配置文件是_config.yml,如果你不小心改花了,這里提供了一份默認的:
```
# Hexo Configuration
## Docs: http://hexo.io/docs/configuration.html
## Source: https://github.com/hexojs/hexo/
# Site
title: Hexo
subtitle:
description:
author: John Doe
email:
language:
# URL
## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'
url: http://yoursite.com
root: /
permalink: :year/:month/:day/:title/
tag_dir: tags
archive_dir: archives
category_dir: categories
code_dir: downloads/code
permalink_defaults:
# Directory
source_dir: source
public_dir: public
# Writing
new_post_name: :title.md # File name of new posts
default_layout: post
titlecase: false # Transform title into titlecase
external_link: true # Open external links in new tab
filename_case: 0
render_drafts: false
post_asset_folder: false
relative_link: false
highlight:
enable: true
line_number: true
tab_replace:
# Category & Tag
default_category: uncategorized
category_map:
tag_map:
# Archives
## 2: Enable pagination
## 1: Disable pagination
## 0: Fully Disable
archive: 2
category: 2
tag: 2
# Server
## Hexo uses Connect as a server
## You can customize the logger format as defined in
## http://www.senchalabs.org/connect/logger.html
port: 4000
server_ip: localhost
logger: false
logger_format: dev
# Date / Time format
## Hexo uses Moment.js to parse and display date
## You can customize the date format as defined in
## http://momentjs.com/docs/#/displaying/format/
date_format: MMM D YYYY
time_format: H:mm:ss
# Pagination
## Set per_page to 0 to disable pagination
per_page: 10
pagination_dir: page
# Disqus
disqus_shortname:
# Extensions
## Plugins: https://github.com/hexojs/hexo/wiki/Plugins
## Themes: https://github.com/hexojs/hexo/wiki/Themes
theme: landscape
exclude_generator:
# Deployment
## Docs: http://hexo.io/docs/deployment.html
deploy:
type:
```
[官方的頁面](http://hexo.io/docs/configuration.html)上也提供了每一項詳細的解釋。
我們需要修改的只有Site部分,以及URL部分的url。Site部分每一項依次是標題、副標題、描述、作者、郵箱和語言(天朝大陸填zh-CN)。url改成網站的網址,如果你的網站放在某個子目錄下,比如http://yoursite.com/child,root改成/child。
Server部分,如果之前你的服務器沒有運行起來,則可能是端口被占了。把port改成別的數字,或者強行關掉占著端口的進程。
其它設置項先不用管,將會在接下來的文章中解釋。
## 注意 ##
**如果頁面中出現中文,應以UTF-8無BOM編碼格式,所以不要用win自帶的記事本,而是用notepad++這種支持編碼轉換的編輯器。**
由于google在天朝大陸被墻,進入themes\landscape\layout\_partial,打開head.ejs,刪掉第31行fonts.googleapis.com的鏈接。
下載下來jquery-2.0.3.min.js,放到themes\landscape\source\js文件夾中。之后進入themes\landscape\layout\_partial,打開after-footer.ejs,將第17行的路徑替換為/js/jquery-2.0.3.min.js。
至此大功告成。
- Markdown 簡介
- Markdown 編輯器推薦
- Markdown 基本語法
- Markdown 高級語法
- Markdown + Gitbook
- Markdown + R
- Markdown + Pandoc
- 用Markdown寫博客:Hexo + Gitcafe
- Hexo 入門指南(一) - 簡介 & 準備
- Hexo 入門指南(二) - 安裝、初始化和配置
- Hexo 入門指南(三) - 文章 & 草稿
- Hexo 入門指南(四) - 頁面、導航、邊欄、底欄
- Hexo 入門指南(五) - 搬家 & 備份
- Hexo 入門指南(六) - sitemap、rss 和部署
- Hexo 入門指南(七) - 評論 & 分享