溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

使用Gitee和Hexo創(chuàng)建自己的博客

發(fā)布時(shí)間:2020-10-21 18:19:36 來(lái)源:網(wǎng)絡(luò) 閱讀:1966 作者:BlueMiaomiao 欄目:編程語(yǔ)言

一、安裝Git與Node

(一) 安裝Git

  • 在Windows下安裝Git:

    在Windows上安裝Git較為簡(jiǎn)單,因此不過(guò)多敘述。

  • 在Linux下安裝Git:

    使用Linux包管理工具進(jìn)行安裝,例如Yum,sudo yum install git。

  • 在Mac下安裝Git:

    Git在Mac下既可以通過(guò)GUI的方式來(lái)安裝也可以通過(guò)Command的方式來(lái)安裝,使用Homebrew進(jìn)行安裝:sudo brew install git。如果沒(méi)有安裝HomBrew,可以參考 https://brew.sh/index_zh-cn

  • Git代理相關(guān):

    • 查看當(dāng)前的代理設(shè)置:

      git config --global http.proxy
      git config --global https.proxy
    • 設(shè)置當(dāng)前代理:

      git config --global http.proxy 'http://127.0.0.1:1080'
      git config --global https.proxy 'http://127.0.0.1:1080'

      或者:

      git config --global http.proxy 'socks5://127.0.0.1:1080'
      git config --global https.proxy 'socks5://127.0.0.1:1080'
    • 刪除代理:

      git config --global --unset http.proxy
      git config --global --unset https.proxy

(二) 安裝Node

  • 在Windows下安裝Node:

    在Windows上安裝Node較為簡(jiǎn)單,因此不過(guò)多敘述。

  • 在Linux上安裝Node:

    • 到NodeJs官方網(wǎng)站下載Linux系統(tǒng)的tar.gz壓縮文件

    • 將文件解壓到指定的目錄, 這里以/home/blue/applications目錄為例

      tar -xvf node-v10.16.0-linux-x64.tar.xz
      mv node-v10.16.0 /home/blue/applications
      ln -s /home/blue/applications/node /home/blue/applications/node
    • 修改可執(zhí)行文件的權(quán)限:

      chmod -R 755 /home/blue/applications/node-v10.16.0
      chmod -R 755 /home/blue/applications/node
    • 執(zhí)行測(cè)試

      node -v
      npm -v
  • 在Mac上安裝Node:

    Node為Mac提供了GUI方式, 但是我們還可以通過(guò)HomeBrew來(lái)安裝:

    sudo brew install node
  • Node相關(guān)設(shè)置:

    • 設(shè)置使用阿里NPM源:

      npm config set registry https://registry.npm.taobao.org --global
      npm config set disturl https://npm.taobao.org/dist --global

      下面是Yarn的配置(必須安裝Yarn以后):

      yarn config set registry 'https://registry.npm.taobao.org'
    • 設(shè)置NPM緩存:

      npm config set prefix "/home/blue/applications/cache/node/prefix"
      npm config set cache "/home/blue/applications/cache/node/cache"

      還需要將/home/blue/applications/cache/node/prefix添加到PATH環(huán)境變量

    • 使用Yarn:

      npm install -g yarn

二、創(chuàng)建遠(yuǎn)程倉(cāng)庫(kù)與安裝Hexo

  • 安裝Hexo:sudo npm install -g hexo

  • 安裝必要的插件:npm install hexo-renderer-jade hexo-renderer-stylus --save

  • 創(chuàng)建本地倉(cāng)庫(kù)

    cd ~/Code
    mkdir bluemiaomiao
    cd bluemiaomiao
    hexo init
    git init
  • 創(chuàng)建遠(yuǎn)程倉(cāng)庫(kù)

    git add remote origin <YOUR_GIT_REPO_ADDRESS>
  • 安裝主題

    git clone -b master https://github.com/jerryc127/hexo-theme-butterfly.git themes/Butterfly
    rm -rf /themes/landscape
  • Hexo的配置 _config.yml

    # 配置網(wǎng)站的標(biāo)題
    title: 愛(ài)吃糖的藍(lán)胖子de官方博客
    # 配置網(wǎng)站的子標(biāo)題
    subtitle: bluemiaomiao.github.io
    # 配置網(wǎng)站的表述信息
    description: 一個(gè)Sre攻城獅的奮斗歷程
    keywords:
    # 配置網(wǎng)站的作者名稱
    author: BlueMiaomiao
    # 配置網(wǎng)站的語(yǔ)言為中文
    language: zh-CN
    # 配置網(wǎng)站的時(shí)區(qū)為中國(guó)北京時(shí)間
    timezone: Asia/Shanghai
    
    # 配置站點(diǎn)發(fā)布的URL地址
    url: http://bluemiaomiao.github.io
    root: /
    permalink: :year/:month/:day/:title/
    permalink_defaults:
    
    source_dir: source
    # 配置靜態(tài)文件的生成目錄,在Gitee部署時(shí)需要使用
    public_dir: docs
    tag_dir: tags
    archive_dir: archives
    category_dir: categories
    code_dir: downloads/code
    i18n_dir: :lang
    skip_render:
    
    new_post_name: :title.md
    default_layout: post
    titlecase: false
    external_link: true
    filename_case: 0
    render_drafts: false
    post_asset_folder: false
    relative_link: false
    future: true
    highlight:
    enable: true
    line_number: true
    auto_detect: false
    tab_replace:
    
    index_generator:
    path: ''
    per_page: 10
    order_by: -date
    
    default_category: uncategorized
    category_map:
    tag_map:
    
    date_format: YYYY-MM-DD
    time_format: HH:mm:ss
    
    per_page: 10
    pagination_dir: page
    
    # 配置使用的主題
    theme: Butterfly
    
    deploy:
    type:
  • 主題的配置

    mkdir source/_data
    cp themes/Butterfly/_config.yml source/_data/_butterfly.yml
    menu:
    主頁(yè): /||fa fa-home
    時(shí)間軸: /archives/||fa fa-archive
    標(biāo)簽: /tags/||fa fa-tags
    分類(lèi): /categories/||fa fa-folder-open
    友鏈: /link/||fa fa-link
    關(guān)于: /about/||fa fa-heart
    
    favicon: /img/favicon.ico
    
    highlight_theme: pale night
    highlight_copy: true
    
    code_word_wrap: true
    
    social:
    fa fa-home: https://bluemiaomiao.gitee.io/
    fa fa-github: https://github.com/bluemiaomiao
    fa fa-gitlab: https://gitee.com/bluemiaomiao
    fa fa-plane: https://blog.51cto.com/xvjunjie
    fa fa-rocket: https://www.cnblogs.com/bluemiaomiao
    fa fa-rss: https://blog.nowcoder.net/bluemiaomiao
    
    algolia_search:
    enable: false
    hits:
        per_page: 6
    
    labels:
        input_placeholder: Search for Posts
        hits_empty: "We didn't find any results for the search: ${query}" # if there are no result
        hits_stats: "${hits} results found in ${time} ms"
    
    local_search:
    enable: false
    labels:
        input_placeholder: Search for Posts
        hits_empty: "We didn't find any results for the search: ${query}" # if there are no result
    
    mathjax:
    enable: false
    cdn: https://cdn.jsdelivr.net/npm/mathjax/MathJax.js?config=TeX-AMS-MML_HTMLorMML
    
    katex:
    enable: false
    cdn:
        css: https://cdn.jsdelivr.net/npm/katex@latest/dist/katex.min.css  
    hide_scrollbar: true
    
    google_analytics:
    
    stylesheets:
    - /css/index.css
    
    scripts:
    - /js/utils.js
    - /js/main.js
    
    cdn:
    css:
        fontawesome: https://cdn.jsdelivr.net/npm/font-awesome@latest/css/font-awesome.min.css
        googlefont: https://fonts.googleapis.com/css?family=Titillium+Web
        fancybox: https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.css
    js:
        jquery: https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js
        fancybox: https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.js
        js-cookies: https://cdn.jsdelivr.net/npm/js-cookie@2/src/js.cookie.min.js
        lozy: https://cdn.jsdelivr.net/npm/lozad/dist/lozad.min.js
    
    avatar: /img/avatar.png
    
    top_img: /img/year-28.jpg
    
    post_img: https://cache.yisu.com/upload/information/20200311/58/228214.jpg
    
    default_cover: https://cache.yisu.com/upload/information/20200311/58/228218.jpg
    
    archive_img: https://cache.yisu.com/upload/information/20200311/58/228219.jpg
    
    lodding_bg:
    flink: /img/friend_404.gif
    post_page: /img/404.jpg
    
    post_meta:
    date_type: both 
    categories: true 
    tags: true
    
    wordcount:
    enable: true
    
    toc:
    enable: true
    number: false
    
    auto_open_sidebar:
    enable: false
    
    post_copyright:
    enable: true
    license: CC BY-NC-SA 4.0
    license_url: https://creativecommons.org/licenses/by-nc-sa/4.0/
    
    auto_excerpt:
    enable: true
    length: 150
    
    addThis:
    enable: false
    pubid:
    
    sharejs:
    enable: true
    sites: facebook,twitter,wechat,weibo,qq
    
    addtoany:
    enable: false
    item:
        - facebook
        - twitter
        - wechat
        - sina_weibo
        - facebook_messenger
        - email
        - copy_link
    
    disqus:
    enable: false
    shortname: 
    
    valine:
    enable: false
    appId:   
    appKey:   
    notify: false 
    verify: false 
    pageSize: 10 
    avatar: monsterid 
    lang: en # i18n: zh-cn/en/tw
    placeholder: Please leave your footprints
    guest_info: nick,mail,link
    
    since: 2016
    
    footer_custom_text: 技術(shù)成就夢(mèng)想, 實(shí)力鑄就輝煌
    
    footer_copyright:
    enable: true
    
    ICP:
    enable: false
    url: 
    text:
    
    # 關(guān)閉數(shù)據(jù)統(tǒng)計(jì)功能
    busuanzi:
    site_uv: false
    site_pv: false
    page_pv: false
    
    google_site_verification:
    
    bing_site_verification:
    
    baidu_site_verification:
    
    qihu_site_verification:
    
    # 友情鏈接基礎(chǔ)信息
    Flink:
    headline: 友情鏈接
    info_headline: 開(kāi)始認(rèn)識(shí)博主
    name: BlueMiaomiao
    address: bluemiaomiao.gitee.io
    avatar: https://cache.yisu.com/upload/information/20200311/58/228222.jpg
    info: 技術(shù)成就夢(mèng)想, 實(shí)力鑄就輝煌
    comment: 添加友鏈請(qǐng)留言
    
    # 是否顯示整站運(yùn)行的時(shí)間
    runtimeshow:
    enable: true
    start_date: 12/02/2016 12:30:00
    
    # 是否支持夜間模式
    nightshift:
    enable: true
    
    activate_power_mode:
    enable: false
    
    # 網(wǎng)站公告
    announcement:
    content: 博主郵箱:18254382067@163.com/xv2017@outlook.com
    
    # 是否打開(kāi)文章贊賞功能
    reward:
    enable: true
    QR_code:
        - itemlist:
            img: /img/wechat-me.jpg
            text: 微信
        - itemlist:
            img: /img/alipay-me.jpg
            text: 支付寶
    
    # 文章自動(dòng)推薦功能
    related_post:
    enable: false
    limit: 6
    
    canvas_ribbon:
    enable: false
    size: 150
    alpha: 0.6
    zIndex: -1
    click_to_change: false
    
    # 開(kāi)啟背景飄帶功能
    canvas_ribbon_piao:
    enable: true
    
    # 避免網(wǎng)址重復(fù)SEO
    canonical: true
    
    # 禁止百度轉(zhuǎn)碼
    disable_baidu_transformation: true
    
    twitter_meta: true
    Open_Graph_meta: true
    
    # 閱讀模式
    readmode:
    enable: true
    
    # 開(kāi)啟字體支持
    font:
    enable: false
    font-family: Lato, Helvetica Neue For Number, -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, PingFang SC, Hiragino Sans GB,"Microsoft JhengHei", "MicrMicrosoft YaHei", Helvetica Neue, Helvetica, Arial, sans-serif
    code-font: consolas, Menlo, "PingFang SC", "Microsoft JhengHei","Microsoft YaHei", monospace, Helvetica Neue For Number
    
    # 水平分割線
    hr:
    enable: true
    icon: '\f21c'
    icon-top: -20px
    
    # 主頁(yè)子標(biāo)題
    subtitle: 
    enable: true
    sub1: 技術(shù)成就夢(mèng)想, 實(shí)力鑄就輝煌
    sub2: bluemiaomiao.gitee.io
    
    # 側(cè)邊功能模塊設(shè)置
    aside:
    card_author: true
    card_announcement: true
    card_recent_post: true
    card_categories: true
    card_tags: true
    card_archives: true
    card_webinfo: false
    
    # 中文繁體假體自動(dòng)轉(zhuǎn)換
    translate:
    enable: true
    # 默認(rèn)顯示的語(yǔ)言
    default: 簡(jiǎn)
    #網(wǎng)站默認(rèn)語(yǔ)言,1: 繁體中文, 2: 簡(jiǎn)體中文
    defaultEncoding: 2
    #延遲時(shí)間,若不在前, 要設(shè)定延遲翻譯時(shí)間, 如100表示100ms,默認(rèn)為0
    translateDelay: 0
    #博客網(wǎng)址
    cookieDomain: "https://bluemiaomiao.gitee.io/"
    #當(dāng)文字是簡(jiǎn)體時(shí),按鈕的文本
    msgToTraditionalChinese: "繁"
    #當(dāng)文字是繁體時(shí),按鈕的文本
    msgToSimplifiedChinese: "簡(jiǎn)"
    
    # 鼠標(biāo)點(diǎn)擊效果
    fireworks:
    enable: true
    
    #百度推送
    baidu_push:
    enable: false
  • 主題安裝配置文檔:https://jerryc.me/posts/21cfbf15/

  • 生成靜態(tài)頁(yè)面:hexo g

  • 預(yù)覽靜態(tài)頁(yè)面:hexo s

  • 發(fā)布靜態(tài)頁(yè)面:

    git add .
    git commit -m "init"
    git push origin masters
  • 創(chuàng)建與gitee用戶名相同的代碼倉(cāng)庫(kù),啟用Gitee Pages服務(wù),發(fā)布master分支的docs目錄

  • 使用瀏覽器訪問(wèn):https://<YOUR_USERNAME>.gitee.io

Gitee的Pages服務(wù)是一個(gè)近實(shí)時(shí)的Httpd服務(wù),Hexo生成的文章即使發(fā)布到代碼倉(cāng)庫(kù),也不一定通過(guò)瀏覽器進(jìn)行顯示,一般會(huì)有30分鐘的延遲。

三、常用Hexo命令

(一)常用命令

  • hexo new "postName" #新建文章
  • hexo new page "pageName" #新建頁(yè)面
  • hexo generate #生成靜態(tài)頁(yè)面至public目錄
  • hexo server #開(kāi)啟預(yù)覽訪問(wèn)端口(默認(rèn)端口4000,'ctrl + c'關(guān)閉server)
  • hexo deploy #部署到GitHub
  • hexo help # 查看幫助
  • hexo version #查看Hexo的版本

(二)簡(jiǎn)化命令

  • hexo n == hexo new
  • hexo g == hexo generate
  • hexo s == hexo server
  • hexo d == hexo deploy

(三)組合命令

  • hexo s -g #生成并本地預(yù)覽
  • hexo d -g #生成并上傳
向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI