美文网首页
博客github迁移到gitee踩坑记录

博客github迁移到gitee踩坑记录

作者: 头大如牛 | 来源:发表于2020-05-02 21:30 被阅读0次

    博客github迁移到gitee踩坑记录

    前言

    鉴于github打开博客速度实在是太慢,我决定还是把博客迁移到gitee上面,打开速度会明显加快,起码不会被某某某说:我看国外小电影的网站都比你博客打开速度快(划掉),所以我创建了新的gitee仓库用于部署博客文件,并开通gitee page 服务。

    谈谈选型

    其实hexo和jekyll我都用过,两边各有不同,其实对我来说最大的不同就是,hexo主题有我喜欢的,好看啊,别的都是白扯。

    踩坑记录

    根据仓库地址和预览地址,对博客根目录配置文件_config.yml进行了如下配置

    # URL
    ## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'
    url: https://casperhan.gitee.io/casperblog  // 这个地址为预览地址,即为gitee page服务地址
    root: /
    
    
    # Deployment
    ## Docs: https://hexo.io/docs/deployment.html
    deploy:
      type: git
      repo: https://gitee.com/casperhan/casperblog.git
      branch: master
    

    这样之后 ,启用命令

    hexo clean
    hexo g
    hexo d
    

    成功将博客部署到gitee上面,gitee pages每次提交 都需要手动点击更新,部署过后,点击预览,神奇的事情发生了,css样式全部丢失,只有html结构,审查元素发现,css文件全部404,初步猜测应该是路径出了问题,我看了一下本地的博客预览 hexo s,发现样式没有问题,应该是与仓库相关的配置路径出了问题,我搜索了相关词条(hexo 部署gitee 丢失css),发现是这部分需要按照gitee官方说明,如下配置

     URL
    ## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'
    url: https://casperhan.gitee.io/casperblog  // 这个地址为预览地址,即为gitee page服务地址
    root: /casperblog      // 二级目录配置,用于解决css 404的BUG
    

    然后我重新进行部署,结果发现结果不尽如人意,又尝试好几种写法,也解决这个问题,那么我产生了一个想法,我能不能向github一样,建一个没有二级目录的仓库呢,果然我在码云官方找到了相关的方法。

    giteeProblem.png

    按照这个方法 ,建议一个仓库,使得仓库地址为 https://gitee.com/casperhan/casperhan.git, gitee pages地址却为https://casperhan.gitee.io,于是配置相关就不存在二级目录的问题,写作如下代码

    # URL
    ## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'
    url: https://casperhan.gitee.io  // 这个地址为预览地址,即为gitee page服务地址
    root: /
    
    
    # Deployment
    ## Docs: https://hexo.io/docs/deployment.html
    deploy:
      type: git
      repo: https://gitee.com/casperhan/casperhan.git
    

    再次重新部署,预览,成功解救这次css丢失的问题。

    相关文章

      网友评论

          本文标题:博客github迁移到gitee踩坑记录

          本文链接:https://www.haomeiwen.com/subject/spplghtx.html