zoukankan      html  css  js  c++  java
  • 基于hugo + github 建立个人博客

    基于hugo + github 建立个人博客

    ps: 以后的博客可能就丢github了,记录博客搬迁,博客园对于一些图片添加又想用markdown的时候就不太方便了

    1.本地测试

    1.1安装

    先在本地搭建试一试吧!我使用的是deepin版的linux

    我们去github上的官网找下载链接https://github.com/gohugoio/hugo/releases

    我下载了64bit的deb包,然后安装sudo dpkg -i hugo_0.55.6_Linux-64bit.deb

    安装完成~

    我在文档中建立一个文件夹,在这里面进行hugo的测试

    cwl@cwl-PC:~/Documents/blogtest$ pwd
    /home/cwl/Documents/blogtest
    

    初始化博客

    cwl@cwl-PC:hugo new site [myblog] "后面的myblog是可选的"
    
    ...
    
    cwl@cwl-PC:~/Documents/blogtest$ tree
    .
    └── myblog
        ├── archetypes
        │   └── default.md
        ├── config.toml
        ├── content
        ├── data
        ├── layouts
        ├── static
        └── themes
    
    

    这样其实博客已经起来了,我们需要设置个主题

    我们来到了官方主题库https://themes.gohugo.io/

    我们随便进入一个主题,其实怎么用已经很清楚了

    Getting started

    Installation

    Create a new Hugo site:

    $ hugo new site [path]
    

    Clone this repository into themes/ directory:(注意这里是在博客根目录敲clone)

    $ cd [path]
    $ git clone https://github.com/vaga/hugo-theme-m10c.git themes/m10c
    

    Add this line in the config.toml file:

    theme = "m10c"
    

    然后我们去启动下试一试

    hugo server -t m10c --buildDrafts
    

    然后就起来了。

    1.2 写文章

    hugo new [path/xxx.md] "简单使用
    

    2.部署到github的仓库

    首先创建新仓库,注意仓库名必须是 [ 你的名字.github.io ] . 例如github名叫abc。那么就写abc.github.io

    剩下常规建仓库就不讲了。

    然后敲命令

    hugo --theme=m10c --baseUrl="Q1143316492.github.io" --buildDrafts
    

    敲完后可以看到我们多了一个public文件夹

    cwl@cwl-PC:~/Documents/blogtest/myblog$ hugo --theme=m10c --baseUrl="Q1143316492.github.io" --buildDrafts
    
                       | EN  
    +------------------+----+
      Pages            |  7  
      Paginator pages  |  0  
      Non-page files   |  0  
      Static files     |  1  
      Processed images |  0  
      Aliases          |  3  
      Sitemaps         |  1  
      Cleaned          |  0  
    
    Total in 10 ms
    cwl@cwl-PC:~/Documents/blogtest/myblog$ ls
    archetypes  config.toml  content  data  layouts  public  resources  static  themes
    cwl@cwl-PC:~/Documents/blogtest/myblog$ ls -l
    总用量 36
    drwxr-xr-x 2 cwl cwl 4096 6月   8 18:24 archetypes
    -rw-r--r-- 1 cwl cwl   82 6月   8 18:24 config.toml
    drwxr-xr-x 2 cwl cwl 4096 6月   8 18:24 content
    drwxr-xr-x 2 cwl cwl 4096 6月   8 18:24 data
    drwxr-xr-x 2 cwl cwl 4096 6月   8 18:24 layouts
    drwxr-xr-x 6 cwl cwl 4096 6月   8 18:47 public
    drwxr-xr-x 3 cwl cwl 4096 6月   8 18:26 resources
    drwxr-xr-x 2 cwl cwl 4096 6月   8 18:24 static
    drwxr-xr-x 3 cwl cwl 4096 6月   8 18:26 themes
    

    下面我们需要吧这个public文件夹传到我们的git上面即可

    
    cwl@cwl-PC:~/Documents/blogtest/myblog$ cd public/
    cwl@cwl-PC:~/Documents/blogtest/myblog/public$ ls
    404.html  avatar.jpg  categories  css  index.html  index.xml  page  sitemap.xml  tags
    
    cwl@cwl-PC:~/Documents/blogtest/myblog/public$ git init
    已初始化空的 Git 仓库于 /home/cwl/Documents/blogtest/myblog/public/.git/
    
    cwl@cwl-PC:~/Documents/blogtest/myblog/public$ git add *
    
    cwl@cwl-PC:~/Documents/blogtest/myblog/public$ git commit -m "hugo first submit"
    
    
    "直接push发现不可以,那就push到master
    cwl@cwl-PC:~/Documents/blogtest/myblog/public$ git push
    fatal: 当前分支 master 没有对应的上游分支。
    为推送当前分支并建立与远程上游的跟踪,使用
    
        git push --set-upstream origin master
    
    cwl@cwl-PC:~/Documents/blogtest/myblog/public$ git push -u origin master 
    
    

    到这里就可以用 "abc.github.io"访问了,abc是你的名字

    总结

    • hugo new site [myblog] "后面的myblog是可选的"初始化博客

    • 然后我们可以下载主题,怎么安装在主题的网站写的很清楚,也可以看我上面的get start

    • hugo server -t m10c --buildDrafts 这样是在本地开仓库

    • hugo new post/first.md 写博客, 创建了一个md在context目录下

    • hugo --theme=m10c --baseUrl="Q1143316492.github.io" --buildDrafts 这个可以开启远程仓库

      这个命令在本地博客目录加了一个public目录。我们只要把他同步到远程git仓库即可。

      这一步只是利用了github为每一个用户提供的免费仓库提供的个人网站

    emmmmmmmmm,博客能用了,但是好像不咋好看呢。。。

    我缺一个能写markdown还能方便粘图片的网站。。。

  • 相关阅读:
    js上传文件
    IOS怎么实现一个UITableView的下拉刷新
    Android的事件处理-android学习之旅(四十四)
    NIO框架之MINA源代码解析(二):mina核心引擎
    每日五题
    Joda-Time 简介
    用websocket实现后台推送消息
    websoclet简单示例 my 改
    struts2拦截器interceptor的配置方法及使用
    activiti复盘重推的一种简单实现方式:
  • 原文地址:https://www.cnblogs.com/Q1143316492/p/10991485.html
Copyright © 2011-2022 走看看