{"id":21823496,"url":"https://github.com/limedroid/hexolearning","last_synced_at":"2025-04-06T17:12:35.203Z","repository":{"id":217140445,"uuid":"74243165","full_name":"limedroid/HexoLearning","owner":"limedroid","description":"Hexo博客搭建全攻略","archived":false,"fork":false,"pushed_at":"2017-07-04T23:54:21.000Z","size":187,"stargazers_count":467,"open_issues_count":5,"forks_count":91,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-03-30T15:12:22.109Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/limedroid.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2016-11-20T00:07:00.000Z","updated_at":"2025-03-23T08:41:37.000Z","dependencies_parsed_at":"2024-01-14T20:29:28.415Z","dependency_job_id":"6305b6bc-6d7b-47c5-9313-9774b1157d42","html_url":"https://github.com/limedroid/HexoLearning","commit_stats":null,"previous_names":["limedroid/hexolearning"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/limedroid%2FHexoLearning","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/limedroid%2FHexoLearning/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/limedroid%2FHexoLearning/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/limedroid%2FHexoLearning/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/limedroid","download_url":"https://codeload.github.com/limedroid/HexoLearning/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247517915,"owners_count":20951719,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-27T17:32:40.868Z","updated_at":"2025-04-06T17:12:35.155Z","avatar_url":"https://github.com/limedroid.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Hexo 博客搭建指南\n\nHexo的简洁、神秘让我跃跃欲试，在使用过程中遇到了很多问题，整理此文，一是方便其他技术人搭建自己的博客，二是给自己的学习之旅做个总结。本文**未完结**，欢迎`star`、`fork`，如果有错误，请不吝指出。\n我搭建的博客地址：[**limedroid.github.io**](https://limedroid.github.io)\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"art/snapshot_1.png\" alt=\"Hexo_Learning\" /\u003e\n\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"art/snapshot_2.png\" alt=\"Hexo_Learning\" /\u003e\n\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"art/snapshot_3.png\" alt=\"Hexo_Learning\" /\u003e\n\u003c/p\u003e\n\n## 1 Hexo介绍\n\n[Hexo](https://hexo.io/zh-cn/)是基于`NodeJs`的静态博客框架，简单、轻量，其生成的静态网页可以托管在`Github`和`Heroku`上。\n\n* 超快速度\n* 支持MarkDown\n* 一键部署\n* 丰富的插件\n\n\u003e 下面以我的博客为例，limedroid.github.io\n\n## 2 环境准备\n\n### 2.1 安装node.js\n\n去[nodejs官网](https://nodejs.org/en/download/)下载对应系统的安装包，按提示安装。\n\n检验安装成功：\n```\n$ node -v\n```\n\n### 2.2 安装hexo\n\n```\n$ npm install hexo-cli -g\n```\n\n注意：Mac系统，则需要  \n```\n$ sudo npm install hexo-cli -g\n```\n\n## 3 利用Hexo搭建一个博客\n\n### 3.1 创建博客目录`limedroid.github.io`\n\n```\n$ hexo init limedroid.github.io\n$ cd limedroid.github.io\n$ npm install\n```\n\n### 3.2 生成静态页面\n\n```\n$ hexo clean\n$ hexo g\n```\n\u003e g 即generate\n\n### 3.3 运行\n\n```\n$ hexo s\n```\n\n\u003e s 即server\n\n然后打开浏览器，输入地址 **localhost:4000** 即可看到效果\n\n## 4 发一篇文章试试\n\n### 4.1 命令方式\n\n```\n$ hexo new test\n```\n\n此时会在`source/_posts`目录下生成`test.md`文件，输入些许内容，然后保存.\n\n生成下，看看效果\n\n```\n$ hexo clean\n$ hexo g\n$ hexo s\n```\n\n访问 **localhost:4000** 即可\n\n### 4.2 直接方式\n\n在 **source/_posts/**下新建一个`.md`文件也可\n\n## 5 配置\n\n网站的设置大部分都在**_config.yml**文件中，详细配置可以查看[官方文档](https://hexo.io/zh-cn/docs/configuration.html)\n\n下面只列出简单常用配置\n\n* **title** -\u003e 网站标题\n* **subtitle** -\u003e 网站副标题\n* **description** -\u003e 网站描述\n* **author** -\u003e 您的名字\n* **language** -\u003e 网站使用的语言\n\n坑：**进行配置时，需要在冒号:后加一个英文空格**\n\n```\ntitle: Droidlover\n```\n\n## 6 换一个好看的主题\n\nHexo 中有很多主题，可以在[官网](https://hexo.io/themes/)查看。\n这里我推荐[hexo-theme-next](https://github.com/iissnan/hexo-theme-next)，下面列举更换主题的一般套路：\n\n### 6.1 下载主题资源\n\n```\n$ git clone https://github.com/iissnan/hexo-theme-next themes/next\n```\n\n### 6.2 应用下载的主题\n\n在网站配置文件**_config.yml**中，配置**theme**\n\n```\ntheme: next\n```\n\n\u003e next是主题名称，具体的可查看主题的文档\n\n### 6.3 主题其他配置\n\n可在`/theme/{theme}/_config.yml` 主题的配置文件下进行主题的配置。\n\n接下来，可以执行万能的调试命令看看效果\n\n```\n$ hexo clean\n$ hexo g\n$ hexo s\n```\n\n## 7 部署到Github\n\n### 7.1 有个github账号xxx\n\n### 7.2 创建一个xxx.github.io的public仓库\n如果您的账户名是limedroid,则需要创建一个limedroid.github.io的public仓库.\n\n### 7.3 安装 [hexo-deployer-git](https://github.com/hexojs/hexo-deployer-git)\n\n```\n$ npm install hexo-deployer-git --save\n```\n\n### 7.4 网站配置git\n在网站的`_config.yml`中配置deploy\n\n```\ndeploy:\n  type: git\n  repo: \u003crepository url\u003e\n  branch: [branch]\n```\n\n\u003e `branch`为分支，默认为`master`,可以不配置\n\u003e `repo`为仓库地址，在github上新建仓库后，可复制此地址\n\n### 7.5 部署\n\n```\n$ hexo d\n```\n\n\u003e d 即deploy\n\n\n## 8 贴标签，方便搜索\n\n### 8.1 两个确认\n\n* 确认站点配置文件有 \n```\ntag_dir: tags\n```\n* 确认主题配置文件有\n```\ntags: tags\n```\n\n### 8.2 新建tags页面\n\n```\n$ hexo new page tags\n```\n此时会在`source/`下生成`tags/index.md`文件\n\n### 8.3 修改source/tags/index.md\n\n```\ntitle: tags\ndate: 2015-10-20 06:49:50\ntype: \"tags\"\ncomments: false\n```\n\n\u003e date 可保持系统生成的时间，\n```\ntype: \"tags\"\ncomments: false\n```\n很重要\n\n### 8.4 在文章中添加tags\n\n在文章`xx.md`中添加：\n\n```\ntags: \n\t- Tag1\n\t- Tag2\n\t- Tag3\n```\n\n多个Tag可按上面的格式添加。\n\n其文件头部类似：\n\n```\ntitle: TagEditText\ndate: 2016-11-19 10:44:25\ntags: \n\t- Tag1\n\t- Tag2\n\t- Tag3\n```\n\n\n\n## 9 分类，给文章归档\n\n### 9.1 两个确认\n\n* 确认站点配置文件打开了\n```\ncategory_dir: categories\n```\n* 确认主题配置文件打开了\n```\ncategories: /categories\n```\n\n### 9.2 新建categories文件\n\n```\n$ hexo new page categories\n```\n\n此时会在`source`目录下生成`categories/index.md`文件\n\n### 9.3 修改categories/index.md\n\n```\ntitle: categories\ndate: 2015-10-20 06:49:50\ntype: \"categories\"\ncomments: false\n```\n\n\u003e date 可保持系统生成的时间，\n```\ntype: \"categories\"\ncomments: false\n```\n很重要\n\n### 9.4 在文章中添加categories\n\n在文章xx.md中添加：\n\n```\ncategories: \n\t- cate\n```\n\n其文件头部类似：\n\n```\ntitle: TagEditText\ndate: 2016-11-19 10:44:25\ncategories: \n\t- cate\n```\n\n## 10 添加评论功能\n\n评论功能在国内一般使用[多说](http://duoshuo.com/)。\n\n### 10.1 注册[多说](http://duoshuo.com/)账号\n\n### 10.2 创建站点\n\n需要注意的是，填写的**多说域名**不能更改，会在后面使用，在这里我配置成droidlover\n\n### 10.3 配置\n\n在hexo主题配置文件中搜索：\n```\nduoshuo_shortname\n```\n，然后打开开关，配置成前面设置的多说域名，如下：\n```\nduoshuo_shortname: droidlover\n```\n\n有时，可能需要一段js\n\n```\n\u003c!-- 多说评论框 start --\u003e\n\t\u003cdiv class=\"ds-thread\" data-thread-key=\"请将此处替换成文章在你的站点中的ID\" data-title=\"请替换成文章的标题\" data-url=\"请替换成文章的网址\"\u003e\u003c/div\u003e\n\u003c!-- 多说评论框 end --\u003e\n\u003c!-- 多说公共JS代码 start (一个网页只需插入一次) --\u003e\n\u003cscript type=\"text/javascript\"\u003e\nvar duoshuoQuery = {short_name:\"droidlover\"};\n\t(function() {\n\t\tvar ds = document.createElement('script');\n\t\tds.type = 'text/javascript';ds.async = true;\n\t\tds.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//static.duoshuo.com/embed.js';\n\t\tds.charset = 'UTF-8';\n\t\t(document.getElementsByTagName('head')[0] \n\t\t || document.getElementsByTagName('body')[0]).appendChild(ds);\n\t})();\n\t\u003c/script\u003e\n\u003c!-- 多说公共JS代码 end --\u003e\n```\n\n现在，你可以运行看下效果了:)\n\n\n## 11 加介绍页面，让全世界认识你\n\n\n\n\n\n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flimedroid%2Fhexolearning","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flimedroid%2Fhexolearning","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flimedroid%2Fhexolearning/lists"}