基于hugo + github 创建我的博客

基于hugo + github 创建我的博客

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

1.本地测试

1.1安装

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

咱们去github上的官网找下载连接https://github.com/gohugoio/hugo/releasesgit

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

安装完成~bash

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

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

初始化博客post

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

相关文章
相关标签/搜索