使用hexo搭建自己的blog


  1. 全局安装hexo工具, 国内使用cnpm速度会更快.

    $ npm install hexo-cli -g
  2. 新建项目文件夹hexo-demo, 进入文件夹中

    $ mkdir hexo-demo
    
    $ cd hexo-demo
  3. 初始化项目, 并安装依赖

    $ hexo init .
    
    $ cnpm install
    ✔ Installed 9 packages
    ✔ Linked 0 latest versions
    ✔ Run 0 scripts
    ✔ All packages installed (used 49ms, speed 0B/s, json 0(0B), tarball 0B)
  4. 运行项目

    $ hexo server
    INFO  Start processing
    INFO  Hexo is running at http://localhost:4000/. Press Ctrl+C to stop.

    hexo demo

    使用-p可以 指定端口, 或者使用hexo server -i 192.168.1.1指定IP

    $ hexo server -p 5000                                                     2 ↵
    INFO  Start processing
    INFO  Hexo is running at http://localhost:5000/. Press Ctrl+C to stop.\    

    发布生成静态文件

    $ hexo clean  # 清理旧的静态文件
    $ hexo generate # 生成静态页面至public目录
  5. 使用git clone hexo主题

    $ git clone https://github.com/tufu9441/maupassant-hexo.git themes/maupassant
  6. 安装主题依赖 ^1

    $ npm install hexo-renderer-jade --save
    $ npm npm install hexo-renderer-sass --save
  7. 修改_config.yml, 追加到原配置之后 ^1

    fancybox: true ## If you want to use fancybox please set the value to true.
    duoshuo: ## Your duoshuo_shortname, e.g. username
    disqus: ## Your disqus_shortname, e.g. username
    google_search: true ## Use Google search, true/false.
    baidu_search: ## Use Baidu search, true/false.
    swiftype: ## Your swiftype_key, e.g. m7b11ZrsT8Me7gzApciT
    tinysou: ## Your tinysou_key, e.g. 4ac092ad8d749fdc6293
    self_search: ## Use a jQuery-based local search engine, true/false.
    google_analytics: ## Your Google Analytics tracking id, e.g. UA-42425684-2
    baidu_analytics: ## Your Baidu Analytics tracking id, e.g. 8006843039519956000
    show_category_count: false ## If you want to show the count of categories in the sidebar widget please set the value to true.
    shareto: true ## If you want to use the share button please set the value to true.
    busuanzi: true ## If you want to use Busuanzi page views please set the value to true.
    widgets_on_small_screens: false ## Set to true to enable widgets on small screens.
    menu:
      - page: home
        directory: .
        icon: fa-home
      - page: archive
        directory: archives/
        icon: fa-archive
      - page: about
        directory: about/
        icon: fa-user
      - page: rss
        directory: atom.xml
        icon: fa-rss
    widgets: ## Six widgets in sidebar provided: search, category, tag, recent_posts, rencent_comments and links.
      - search
      - category
      - tag
      - recent_posts
      - recent_comments
      - links
    links:
      - title: site-name1
        url: http://www.example1.com/
      - title: site-name2
        url: http://www.example2.com/
      - title: site-name3
        url: http://www.example3.com/
    
    timeline:
      - num: 1
        word: 2014/06/12-Start
      - num: 2
        word: 2014/11/29-XXX
      - num: 3
        word: 2015/02/18-DDD
      - num: 4
        word: More
    
    # Static files
    js: js
    css: css
  8. 再次运行项目,效果如下:

    hexo blog


需要安装hexo, 否则无法运行

$ hexo server
ERROR Local hexo not found in /path/to/hexo-demo
ERROR Try running: 'npm install hexo --save'

$ cnpm install hexo --save                                                1 ↵
⠦ [0/1] Installing cssom@0.3.xplatform unsupported hexo@3.3.8 › hexo-fs@0.2.1 › chokidar@1.7.0 › fsevents@^1.0.0 Package require os(darwin) not compatible with your platform(linux)
...
✔ All packages installed (255 packages installed from npm registry, used 8s, speed 549.1kB/s, json 277(458.47kB), tarball 3.76MB)

参考文档


Author: Itaken
Reprint policy: All articles in this blog are used except for special statements CC BY 4.0 reprint polocy. If reproduced, please indicate source Itaken !
  TOC目录