Github page和Hexo搭配NEXT主题建站过程中的步骤和问题,机器用Mac,安装有homebrew, ssh -T git@github.com通,本文用的NEXT版本为8.23.0
安装部署
Hexo安装
安装nodejs
安装hexo cli
Hexo初始化和NEXT安装
1 2 3 4
| mkdir blog cd blog hexo init git clone https://github.com/theme-next/hexo-theme-next themes/next
|
连接到GitHub
新开一个repo,命名为username.github.io,复制ssh的url
1 2 3 4 5
| deploy: type: git repo: git@github.com:username/username.github.io.git branch: main message: autosave
|
初次上传
1 2
| # 在blog目录下 hexo clean && hexo g && hexo d
|
打开https://username.github.io查看博客
博客设置
CNAME设置
在根目录中
将域名添加到这个文件
Permalink设置
在根目录_config.yml中修改
urlname在新建文章中和title同级
新建页面(关于、标签、分类等)
1 2 3
| hexo new page about hexo new page tags hexo new page categoris
|
在根目录的source/xxx/index.md中分别加入
1 2 3
| type: "about" type: "tags" type: "categoris"
|
执行hexo s本地部署
新建空白页面,以star为例:
- 在
themes/next/_config.yml中的menu选项新增项目并且设置图标
1 2 3 4 5 6 7 8 9 10
| menu: home: / || fa fa-home about: /about/ || fa fa-user tags: /tags/ || fa fa-tags categories: /categories/ || fa fa-th archives: /archives/ || fa fa-archive star: /star/ || fa fa-star
|
- 新建页面并索引
在根目录的source/star/index.md中加入
- 在
themes/next/languages/zh-CN.yml中的menu加入star: 收藏夹
- 执行
hexo s本地部署
背景图片设置
- 创建用户的styl目录及相关文件,在根目录下
1 2
| mkdir source/_data touch source/_data/styles.styl
|
- 复制背景图片到
themes/next/source/images,例如themes/next/source/images/background.jpg
- 添加背景图片,在
source/_data/styles.styl中添加
1 2 3 4 5 6 7
| body { background:url(/images/background.jpg); background-repeat: no-repeat; background-attachment: fixed; background-size: cover; background-position: center; }
|
- 为header、sidebar和post设置半透明,在
source/_data/styles.styl中添加
1 2 3 4 5 6 7 8 9 10 11 12
| .post-block { background-color: rgba(255, 255, 255, 0.9); } .header.header { background-color: rgba(255, 255, 255, 0.9); } .sidebar { background-color: rgba(255, 255, 255, 0.9); } .popup { background-color: rgba(255, 255, 255, 0.9); }
|
- 在
themes/next/_config.yml中启用用户的style
1 2
| custom_file_path: style: source/_data/styles.styl
|
圆角矩形设置
在source/_data/styles.styl中添加
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| .main-inner .post-block { border-radius: 20px 20px 20px 20px; } .main-inner .post-block:not(:first-child):not(:first-child) { border-radius: 20px 20px 20px 20px; }
.header.header { border-radius: 20px 20px 20px 20px; }
.popup { border-radius: 20px 20px 20px 20px; }
.site-brand-container { border-radius: 20px 20px 0px 0px; }
.sidebar { border-radius: 20px 20px 20px 20px; } .sidebar-inner { border-radius: 20px 20px 20px 20px; }
.back-to-top { border-radius: 0px 0px 20px 20px; }
|
设置撑满页面
在source/_data/styles.styl中添加