[tools]hugo&github构建静态网站/百度统计

hugo/github构建网站基本原理

  • 1.hugo是一个静态化的工具,你写md,而后他把md转换成对应样式的html,
  • 2.并给html嵌入百度统计的script.而后你将html放到github上,github能够支持静态博客.你就拥有了本身的博客
  • 3.用户访问时,触发js统计代码,上报给百度统计.

安装配置hugo+githubpage站点

老宋专门写了一本关于这个的书html

参考 这个文档有个坑,里面访问的url改为https的.若是按照文档的http会致使发到github上后样式加载不成功.linux

官网下载hugo, 是一个二进制程序,无任何依赖git

- 将hugo放在可执行路径
$ hugo version
Hugo Static Site Generator v0.36 windows/amd64 BuildDate: 2018-02-05T15:23:01Z


- 新建站点
mkdir sites
cd sites
hugo new site quickstart

- 新建文章
hugo new posts/ansible经常使用知识点.md

- 下载主题
cd themes
git clone https://github.com/halogenica/beautifulhugo.git

- 构建
hugo server --theme=beautifulhugo --buildDrafts


- 本地run
hugo server

- 构建public静态文件,准备上传html
hugo --theme=beautifulhugo --baseUrl="https://lannyMa.github.io/"

- 新建github,上传代码到github
如今github新建仓库: <用户名>.github.io,如个人是lannyMa.github.io

- 来到本地,上传代码
cd public
echo "# lannyMa.github.io" >> README.md
git init
git add -A
git commit -m "first commit"
git remote add origin https://github.com/lannyMa/lannyMa.github.io.git
git push -u origin master

- 而后访问
https://lannyma.github.io/

hugo构建环境模板参考github

之后部署

每次写一遍md文档,都须要构建,手动推送,这个是很大疼的,有deploy.sh.
正确姿式是,直接执行sh deploy.sh "comment 一键部署
json

这里我是win7,cmd很差用,我改用第三方cmder,这个执行命令比较像linux.windows

deploy.sh也很简单bash

#/bin/bash
echo -e "\033[0;32mDeploying updates to GitHub...\033[0m"

msg="rebuilding site `date`"
if [ $# -eq 1  ]
    then msg="$1"
fi

git add -A
git commit -m "$msg"
git push origin master

# Build the project.
hugo # if using a theme, replace by `hugo -t <yourtheme>`
hugo-algolia

# Go To Public folder
cd public

# Add algolia search index
grep -v '"content":' algolia.json>maotai-blog.json
rm -f algolia.json

# Add changes to git.
git add -A

# Commit changes.

git commit -m "$msg"

# Push source and build repos.
git push origin master

cd ../

百度统计

这个玩意能够分析一些pv,uv等
服务器

申请免费域名(12个月)

参考: 免费的域名和证书
freenom.com工具

注: 域名的备案问题,若是在国内,若是域名指向了国内的服务器,则须要备案,若是域名cname到了github,则无须要.post

maotai.ml 这是个人站点,我cname到了 lannyma.github.io了.

todo:

  • 评论插件: giment
  • algolia 搜索插件.
  • cdn: cloudfare,须要执行域名cname配置才ok, freenom.com没办法搞

SEO

相关文章
相关标签/搜索