0%

安装NodeJS以及hexo

安装nodeJS以及hexo框架的踩坑笔记

详细入门网站

  • 版本问题:
    一开始使用的是最新版本的NodeJS然后安装完成Hexo之后发现不能在控制台使用hexo init blog,显示hexo不是命令。
    然后使用HodeJS12.0.0,自带npm,安装完成(注意不要使用13等版本,npm不是支持每个nodeJS版本)
  • 假如直接git clonehexo的仓库报错的话可能是换设备之后 无法通用 ,还是需要在 原设备 上才能打的开image-20211214003223898
  • 假如重装hexo失败的话,删除图中文件夹下的hexo有关的所有内容image-20211208201712068
  • 安装完成之后在控制台输入以下代码,假如没有报错而且能够正确显示版本号的话说明安装成功
    node -vnpm -v
  • 另注意,假如安装完nodeJS之后,输入node -v得到的版本和安装的 不同 ,此时需要将NodeJS卸载然后安装在 默认的安装位置 。注意,AMD CPU的计算机下载x86的,Intel的下载x64的msi安装文件
  • 插入图片问题
    有时候插入的图片会加载失败比如显示为 2,此时可以通过以下几步解决问题

  • 首先,在source目录下新建一个文件夹比如imgs

    image-20211208204226807

    然后把typora的根目录设置为source

    image-20211208204322540

    然后设置将图片复制到imgs下

    image-20211208204358165

    配置好上述功能之后,直接把用到的图片从剪贴板复制到typora即可

    不要安装网上博客说的插件,安装之后可能无法启动网站

    不需要在config中开启每新建一篇博客就新建一个文件夹之类的选项,反而更麻烦

  • 修改主题
    从github将主题项目 git clone到blogs的 \themes\<主题名称>文件夹,然后将总目录下的 _config.yml中的 theme更换为<主题名称>
    假如无法clone的话,可以将项目打包下载然后解压到同样的文件夹中即可

  • 设置个人信息如下图
    3

  • 此外,在主题的配置文件中(也是 _config.yml)也有一些可以修改的地方,可以自己动手改一改

  • 在推送网站之前需要安装一个git配合插件
    npm install hexo-deployer-git --save

hexo部署的踩坑

  • 部署的时候不能在/sources下执行hexo clean, hexo g等脚本,需要在博客的根目录下执行脚本,否则会导致博客部分内容不更新(比如tags),引起新创建的tags不读取和无法打开含有对应tags的文章的问题
  • 一键部署的脚本
    • 此脚本运行的时候将自己的位置切换到了自己所在位置的上一级目录
    • 执行结束后会自动切回去
      # Set the error preference to stop the script on any command failure
      $ErrorActionPreference = 'Stop'

      # Save the current working directory
      $originalLocation = Get-Location

      # Change directory to the parent directory of the script's directory
      Set-Location (Join-Path $PSScriptRoot "..")

      try {
      # Define a function to execute a command and check if it was successful
      function Invoke-HexoCommand {
      param(
      [string]$Command
      )
      Write-Host "Executing command: $Command" -ForegroundColor Cyan
      Invoke-Expression $Command
      }

      # Execute Hexo commands
      Invoke-HexoCommand "hexo clean"
      Invoke-HexoCommand "hexo g"
      Invoke-HexoCommand "hexo d"

      # Print the new working directory to confirm
      Write-Host "Current working directory is now: $(Get-Location)"
      # Command execution completed message
      Write-Host "Hexo site cleaning, generation, and deployment completed." -ForegroundColor Green -BackgroundColor White
      } catch {
      # Handle exceptions here if needed
      Write-Host "An error occurred: $_" -ForegroundColor Red
      } finally {
      # Restore the original working directory
      Set-Location $originalLocation
      Write-Host "Returned to the original directory: $originalLocation"
      }

更换设备

  • 注意更换设备的时候不能简单的git clone,这样的话是无法打开的。只能自己在本地新建一个博客,然后将sourcethemes以及config文件和文件夹都 复制进去

部署的地址

  • 部署的时候 不能使用 网页上的教程repo地址如图

image-20211209101305939

需要直接写成自己的仓库地址+.git,比如

image-20211209101336927

  • 此外,相关的 url和root 配置如下;

image-20211209101427432

即可正常显示

向服务器提交过程

hexo clean

hexo g

hexo d

gitee网站教程

https://gitee.com/help/articles/4136#article-header0

vscode markdown插件(相对方便,但是不支持图片复制,建议还是用typora)

office viewer

4


使用next主题

  • 教程
  • 添加字数统计
  • 注意博客的语言(也就是根目录下_config.yml的language)要写成zh-CNpicture 0
    否则语言会出错
  • 删除页面底部由…强力驱动
    • picture 1
    • 将如图的45-53行删除
  • 有时候文章底部会不显示访问人数等,只有一条竖线,此时是因为开了代理导致的,关闭即可正常显示picture 2
  • 如何不显示非常好! 目前共计 *** 篇日志。 继续努力。picture 3
    • 按Ctrl+P搜索archive.swig
    • 注释掉第31行picture 4
    • 使用<!---->
  • 更换网站图标
    • next主题的_config.yml中搜索favicon:
    • picture 5
    • 配置为themes/next/source/images下的图片即可