0%

hexo本地环境安装配置

准备

  • blog Git仓库
  • github page 仓库
  • centos6.5

执行

  1. 下载如下四个文件;

  2. 修改MY_BLOG_GIT_URL, MY_BLOG_THEME, MY_BLOG_THEME_NAME

  3. bash install_hexo.sh 1

    脚本入口view raw
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    #!/bin/bash

    ## 博客根目录
    HEXO_ROOT_DIR=/data/blog
    ## 博客源文件目录
    MY_BLOG_GIT_URL="git@git.coding.net:kingwen0302/kingwen0302.git"
    ## 博客主题
    MY_BLOG_THEME="https://github.com/tufu9441/maupassant-hexo.git"
    MY_BLOG_THEME_NAME=maupassant
    ## 当前目录
    CUR_DIR=$(cd $(dirname $0); pwd)

    function install_hexo(){
    yum remove nodejs npm -y
    curl --silent --location https://rpm.nodesource.com/setup_4.x | bash -
    yum install -y nodejs
    ## npm install -g cnpm --registry=https://registry.npm.taobao.org
    ## cnpm install hexo-cli -g
    }
    function install(){
    hexo init ${HEXO_ROOT_DIR}
    cd ${HEXO_ROOT_DIR}
    rm -rf source
    git clone ${MY_BLOG_GIT_URL} source
    rm -rf themes/landscape
    git clone ${MY_BLOG_THEME} themes/${MY_BLOG_THEME_NAME}
    ## HEXO配置替换
    source ${CUR_DIR}/maupassant_config.sh
    source ${CUR_DIR}/post.sh
    ## THEME配置替换
    source ${CUR_DIR}/maupassant_theme_config.sh
    npm install
    ## 安装deploy
    npm install hexo-deployer-git --save
    ## rss支持
    npm install hexo-generator-feed --save
    ## sitemap支持
    npm install hexo-generator-sitemap --save
    npm install hexo-generator-baidu-sitemap --save
    ## jade模版
    npm install hexo-renderer-jade --save
    npm install hexo-renderer-sass --save
    }

    function deploy(){
    cd ${HEXO_ROOT_DIR}/source
    git add .
    git commit -m "$(date) deploy"
    cd ${HEXO_ROOT_DIR}
    hexo g -d
    }

    function help(){
    echo "------------------------------"
    echo " 0 -- install_hexo"
    echo " 1 -- install"
    echo " 2 -- deploy"
    echo "------------------------------"

    }
    case $1 in
    [0]) install_hexo;;
    [1]) install;;
    [2]) deploy;;
    *) help;;
    esac
    hexo的配置文件view raw
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    # Hexo Configuration
    ## Docs: https://hexo.io/docs/configuration.html
    ## Source: https://github.com/hexojs/hexo/

    # Site
    title: 情文
    subtitle: 记录点点滴滴
    description:
    author: kingwen0302
    language: zh-CN
    timezone: Asia/Shanghai

    # URL
    ## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'
    url: http://www.mingilin.com
    root: /
    permalink: :year/:month/:day/:title/
    permalink_defaults:

    # Directory
    source_dir: source
    public_dir: public
    tag_dir: tags
    archive_dir: archives
    category_dir: categories
    code_dir: downloads/code
    i18n_dir: :lang
    skip_render:

    # 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
    future: true
    highlight:
    enable: true
    line_number: true
    auto_detect: true
    tab_replace:

    # Category & Tag
    default_category: uncategorized
    category_map:
    tag_map:

    sitemap:
    path: sitemap.xml
    baidusitemap:
    path: baidusitemap.xml

    # 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: YYYY-MM-DD
    time_format: HH:mm:ss

    # Pagination
    ## Set per_page to 0 to disable pagination
    per_page: 20
    pagination_dir: page

    # Extensions
    ## Plugins: https://hexo.io/plugins/
    ## Themes: https://hexo.io/themes/
    ## theme: landscape
    theme: maupassant

    # Deployment
    ## Docs: https://hexo.io/docs/deployment.html
    deploy:
    - type: git
    repository: git@git.coding.net:kingwen0302/kingwen0302.git
    branch: coding-pages
    maupassant主题配置文件view raw
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    fancybox: true ## If you want to use fancybox please set the value to true.
    duoshuo: kingwen0302 ## 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: UA-74683107-1 ## Your Google Analytics tracking id, e.g. UA-42425684-2
    baidu_analytics: e340a0928b11036ca5deeaf890942c4b ## Your Baidu Analytics tracking id, e.g. 8006843039519956000
    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.

    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: hexo
    url: https://hexo.io/
    - title: 屠夫9441的博客
    url: https://www.haomwei.com/

    # Static files
    js: js
    css: css

    # Theme version
    version: 0.0.0
    post.shview raw
    1
    2
    3
    4
    5
    6
    7
    ---
    title: {{ title }}
    date: {{ date }}
    tags:
    toc: true
    categories:
    ---

主动推送百度

  1. 插件安装

    1
    2
    3
    4
    yum -y install python-setuptools
    easy_install beautifulsoup4
    easy_install requests
    yum -y install python-lxml
  2. 推送脚本

    push.pyview raw
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    # -*- coding: utf-8 -*-
    # @Author: LoveNight
    # @Date: 2015-11-16 20:45:59
    # @Last Modified by: LoveNight
    # @Last Modified time: 2015-11-18 18:07:19
    import os
    import sys
    import json
    from bs4 import BeautifulSoup as BS
    import requests

    """
    hexo 博客专用,向百度站长平台提交所有网址

    本脚本必须放在hexo博客的根目录下执行!需要已安装生成百度站点地图的插件。
    百度站长平台提交链接:http://zhanzhang.baidu.com/linksubmit/index
    主动推送:最为快速的提交方式,推荐您将站点当天新产出链接立即通过此方式推送给百度,以保证新链接可以及时被百度收录。
    从中找到自己的接口调用地址
    """

    ## url = 去上面的链接找自己的推送接口
    url = "http://data.zz.baidu.com/urls?site=www.aaaa.com&token=aaaa"
    baidu_sitemap = os.path.join(sys.path[0], 'public', 'baidusitemap.xml')
    google_sitemap = os.path.join(sys.path[0], 'public', 'sitemap.xml')
    sitemap = [baidu_sitemap, google_sitemap]

    assert (os.path.exists(baidu_sitemap) or os.path.exists(
    google_sitemap)), "没找到任何网站地图,请检查!"


    # 从站点地图中读取网址列表
    def getUrls():
    urls = []
    for _ in sitemap:
    if os.path.exists(_):
    # with open(_, "r", encoding="utf-8") as f:
    with open(_, "r") as f:
    xml = f.read()
    soup = BS(xml, "xml")
    tags = soup.find_all("loc")
    urls += [x.string for x in tags]
    if _ == baidu_sitemap:
    tags = soup.find_all("breadCrumb", url=True)
    urls += [x["url"] for x in tags]
    return urls


    # POST提交网址列表
    def postUrls(urls):
    urls = set(urls) # 先去重
    print("一共提取出 %s 个网址" % len(urls))
    data = "\n".join(urls)
    for u in urls:
    print u
    return requests.post(url, data=data).text


    if __name__ == '__main__':

    urls = getUrls()
    result = postUrls(urls)
    print("提交结果:")
    print(result)
    ## msvcrt.getch()

参考文档

  1. 参考文档1