hiko
Diary:(·-·)Hoping I Keep On, Hanging In Kinda Okay---

Blogify

利用 hexogithub 搭建个人博客(之不知道第几次重来版

一、配置环境

  1. 打开终端

    • 通过 Spotlight 搜索:

      • 按下 Command (⌘) + Space,打开 Spotlight 搜索框。

      • 输入 Terminal(终端),然后按 Enter,就可以打开终端了。

    • 通过 Finder 打开:

      • 打开 Finder,点击菜单栏的 前往,然后选择 实用工具
      • 在实用工具文件夹中找到 Terminal,双击打开。
    • 通过 Dock 打开:

      • 在 Dock 中找到 Finder(通常是最左边的笑脸图标)。
      • 打开 Finder,然后按照上面的步骤进入 前往 > 实用工具,找到 Terminal 打开。
  2. 安装Homebrew

    1
    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

    帮助

    1
    brew help

    验证

    1
    brew --version
  3. 安装Node.js

    1
    brew install node

    验证

    1
    2
    node -v
    npm -v
  4. 安装Git

    1
    brew install git

    验证

    1
    git --version

    如果已经安装,想更新到最新版本,运行

    1
    2
    brew update
    brew upgrade git
  5. 安装Hexo

    1
    npm install -g hexo-cli

    验证

    1
    hexo -v

二、搭建博客(本地)

  1. 初始化一个新的 Hexo 博客项目

    1
    2
    3
    hexo init hiblog
    cd hiblog
    npm install
    • _config.yml:博客的配置文件,设置博客名称、作者、URL 等全局参数。
    • package.json:项目的依赖配置文件,默认安装 EJS、Stylus 和 Markdown 渲染工具。
    • source 文件夹:存放原始文件(如 Markdown 文章),生成器会解析它们并复制到 public 文件夹。
    • themes 文件夹:存放主题文件,默认主题为 landscape,可更改或定制主题。
  2. 启动 Hexo 本地服务器

    1
    hexo s

    访问 http://localhost:4000/ 查看博客,然后回终端 Ctrl+C 退出(会和你说 Good bye 喔)

  3. 创建新文章

    1
    hexo n 文章标题

    这样会在 source/_posts 文件夹中创建一个新的md(文件名为 hexo n 后面的 文章标题.md),你可以在其中编写你的内容。

  4. 完成内容编写后,生成静态文件

    1
    2
    3
    hexo clean
    hexo g
    hexo s

    再次访问链接 http://localhost:4000/,即可看到更新

三、Github Page 部署

  1. 登录githubhttps://github.com

  2. 创建 New repository:名字必须为:username.github.io

  3. 安装部署插件

    1
    npm install hexo-deployer-git --save 
  4. 更改本地文件夹下 _config.yml 文件的配置

    1
    2
    3
    4
    5
    6
    # Deployment
    ## Docs: https://hexo.io/docs/deployment.html
    deploy:
    type: git
    repo: https://github.com/username/username.github.io.git
    branch: main
  5. 回到终端部署到 github

    1
    hexo d
  6. 主题更换

    • https://github.com/chanwj/hexo-theme-meow 主题(https://chanwj.github.io)为例(超级可爱的一个小主题!!!)

    • 在博客根目录下执行以下指令,获取最新版主题。

      1
      git clone -b master https://github.com/chanwj/hexo-theme-meow.git themes/meow
    • 修改博客根目录下的_config.yml配置文件,将主题更换为meow

      1
      theme: meow
    • 本主题使用pug进行渲染,请提前安装pug渲染器。

      1
      npm install hexo-renderer-pug --save
  7. 手动提交本地更改

    1
    2
    3
    git status
    git add .
    git commit -m "Your commit message"
    1
    2
    git push origin main
    hexo d
  8. 添加自己的域名

    访问 https://github.com/username/username.github.io/settings/pages ,在 Custom domain 空格处输入域名即可

If you liked this article, how about grabbing me a coffee? Thanks a bunch!💗

WechatWechat
AlipayAlipay
Search
Matching results:
No matching articles were found.