Please enable Javascript to view the contents

Hugo

 ·  ☕ 1 分钟  ·  🎅 qqnv

本地博客

安装Hugo

brew install hugo

建立新站点

hugo new site blog

添加主题

  1. cd blog
  2. git init
  3. git submodule add https://github.com/budparr/gohugo-theme-<YOURTHEME>.git themes/<YOURTHEME>

新建文章

hugo new posts/article.md

开启本地服务

hugo server

GitHub部署Hugo

创建GitHub项目

项目名称为xxx.github.io(xxx为你想要的项目名)

关联Github

  1. hugo --theme=主题名称 --baseUrl="https://xxx.github.io"(xxx表示你的github..) --buildDrafts
  2. cd public
  3. git init
  4. git init .
  5. git commit -m "xxx"
  6. git remote add origin https://github.com/xxx/xxx.github.io.git
  7. git push -u origin master
  8. github为该项目配置page及域名,输入域名即可访问

博客修改更新

  1. 博客根目录创建deploy.sh并输入以下内容:

     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
    
    #!/bin/sh
    
    # If a command fails then the deploy stops
    set -e
    
    # Print out commands before executing them
    set -x
    
    printf "\033[0;32mDeploying updates to GitHub...\033[0m\n"
    
    # Build the project.
    hugo -t 主题文件夹名称 --buildDrafts
    
    # Go To Public folder
    cd public
    
    # Add changes to git.
    git add .
    
    # Commit changes.
    msg="rebuilding site $(date)"
    if [ -n "$*" ]; then
        msg="$*"
    fi
    git commit -m "$msg"
    
    git pull 
    
    # Push source and build repos.
    git push -u origin master
    
    # Back to the origin folder
    # cd ..
    
    # rm -rf public
    
  2. 博客根目录命令行执行./deploy.sh "网站更改的内容"

分享

qqnv
作者
qqnv
Android Developer