基于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/

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

扫描二维码关注公众号,回复: 6378088 查看本文章

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还能方便粘图片的网站。。。

猜你喜欢

转载自www.cnblogs.com/Q1143316492/p/10991485.html