快速用hexo + github搭建网站

300 阅读1分钟

快速搭建hexo博客

Hexo 是一个快速、简洁且高效的博客框架。Hexo 使用 Markdown(或其他渲染引擎)解析文章,在几秒内,即可利用靓丽的主题生成静态网页。

前提:电脑需要安装node和git

1.安装hexo,搭建项目

npm install -g hexo-cli
hexo init <folder>
cd <folder>
npm install

搭建完成后自动生成一篇默认博客md文件

image.png

2.本地运行项目

hexo server

如下,一篇hello-world 博客新鲜出炉 image.png

3.新建博客

hexo new [layout] <title>

新建一篇文章。如果没有设置 layout 的话,默认使用 _config.yml 文件中的 default_layout 参数代替。如果标题包含空格的话,请使用引号括起来。

hexo new "post title with whitespace"

4.部署

安装 hexo-deployer-git

npm install hexo-deployer-git --save

修改配置

deploy:
  type: git
  repo: <repository url> #https://github.com/linsmallsail/myBlog.git
  branch: [branch] #设为gitlab上的默认分支
  message: [message] #自定义提交信息

生成站点并推送到远程仓库

hexo clean && hexo deploy

hexo clean: 清除缓存文件 (db.json) 和已生成的静态文件 (public)。 在某些情况(尤其是更换主题后),如果发现您对站点的更改无论如何也不生效,您可能需要运行该命令。

更换hexo主题

打开官网,在themes主题下面找到喜欢的主题,点击名称进行gitlab代码库

image.png

复制主题的仓库地址

image.png

到博客根目录执行下面命令,修改theme,再次hexo server,即修改成功

git clone github.com/sharvarides… themes/edinburgh image.png