eox组合:heox+github pages自建博客(Markdown的另类玩法) 2024-04-24 13:49:36 0 0 文章目录heox+github pages自建博客1.自建博客2. heox 发布到github pages上3.保存源码4.hexo-theme-next主题5.使用hexo新建、编辑并预览文章 heox+github pages自建博客 heox官网: https://hexo.io/zh-cn/ 博客预览:https://suesoft.github.io/ 1.自建博客# 1.全局安装脚手架hexo-clinpm install hexo-cli -g# 2.创建 myBlog 项目hexo init myBlog # 此处失败的话需要挂梯子,解决1cd myBlognpm installhexo server 解决1: Step1: ping 一下 github.com。如果结果显示100%丢失,那么就是因为无法连接到GitHub导致。ping github.com Step2: 从以下网站里面去获取能访问的ip,ping一下看能ping通不 站长工具网站、ipaddress、ip.cn查询网、DNS查询在线工具 Step3: 配置本地hosts(hosts在C:\Windows\System32\drivers\etc下)# 13.114.40.48 是 Step2中获取的能 ping 通的ip地址13.114.40.48 github.com Step4: 刷新dnsipconfig /flushdns 2. heox 发布到github pages上创建github项目 登录github -> New -> Repository name(格式: 用户名.github.io) -> Description (填写描述) -> Public -> 创建 创建成功后,复制项目链接(git@github.com:xxx/xxx.github.io.git)github配置公私钥获取公私钥# 确保安装了git, 打开git bash here,执行以下操作获取公私钥ssh-keygen -t rsa -C "xx@xx.com"ls ~/.sshcat ~/.ssh/id_rsa.pub # copygithub添加ssh-key 个人中心,找到settings -> SSH and GPG keys -> New SSH key -> 粘贴公钥 验证是否配置成功: ssh -T git@github.com 安装hexo-deployer-git并推送 网站: https://github.com/hexojs/hexo-deployer-git# 安装hexo-deployer-gitnpm install hexo-deployer-git --save# hexo generatehexo g# hexo deployhexo d 3.保存源码更改仓库的默认分支 可以新建一个source分支来保存源码 在仓库的主页面,通过Settings -> Branchs,可以看到Default branch的Tab,显示的默认分支是master,可以勾选source,然后update即可将默认分支设置为source将本地hexo目录与远程仓库关联git remote add origin https://github.com/xxx/xxx.github.io.git 注:如果此处关联不成功,可以把source分支下载下来,然后复制里面的.git文件夹到blog下’推送博客源码 添加.gitignore文件.DS_StoreThumbs.dbdb.json*.lognode_modules/public/.deploy*/ 推送git add .git commit -m 'hexo blog source file'git push origin source 4.hexo-theme-next主题 配置文件:http://theme-next.iissnan.com/getting-started.html更改主题hexo-theme-nextcd myBlog# 之后的更新可以通过 git pull 来快速更新git clone https://github.com/next-theme/hexo-theme-next themes/next 修改_config.yml文件# Extensions## Plugins: https://hexo.io/plugins/## Themes: https://hexo.io/themes/theme: next 推送hexo cleanhexo serverhexo g # hexo generatehexo d # hexo deploy主题美化 参考: https://zhuanlan.zhihu.com/p/251383216 5.使用hexo新建、编辑并预览文章 参考: https://zhuanlan.zhihu.com/p/132823826新建文章 hexo支持三种布局(layout):post(默认)、draft、page# 默认使用post布局,然后自动在source\_posts目录生成一个text1.md文件hexo n text1# 指定布局hexo n [layout_name] text1 创建草稿布局并推送到_posts目录下。可以使用 hexo --draft 命令可以查看已有草稿。hexo n draft draft1hexo publish draft1 收藏(0)