@Bios
2018-12-10T08:41:33.000000Z
字数 4480
阅读 1160
hexo
我自己在换了公司的电脑后发现按照“换了电脑之后怎么弄弄”没有跑通。
问题在于,如果新电脑上没有全局安装hexo-cli
GitHub官网。按照一般的网站注册登录执行就好了,不详细说。
安装很简单,一直下一步 git安装教程
很多教程里都说要配置环境变量,我本人安装过5次左右的git,一次都没有配过,但是要配置用户名和邮箱,就是和github注册的一样
安装成功你在桌面右键,就能看到 多了两个 git命令
安装nodejs主要是为了安装npm包管理工具
在Nodejs官网下载自己系统的版本安装就好了
安装也是极其简单,一直下一步就好了。
推荐Nodejs安装教程!

需要把Repository name 改成你自己的哦,例如我的:
finget.github.io

创建好了,来到Settings页面,开启gh-pages功能
在最后找到Github pages(我的是默认开启的,如果你不是就点击Launch automatic page generator按钮,一直下一步就行了)
完成之后,你可以在地址栏,打开yourname.github.io查看是否成功。
Hexo 是一个快速、简洁且高效的博客框架。Hexo 使用 Markdown(或其他渲染引擎)解析文章,在几秒内,即可利用靓丽的主题生成静态网页。
hexo官网:https://hexo.io/zh-cn/docs/
这个时候nodejs的npm就排上用场了
你可以用系统自带的命令面板(window下是cmd),也可以用git bash here(推荐)
以下的命令懂得就不说了,不懂得小伙伴可以自己去了解一下
检查一下npm是否安装成功
npm -v

npm install hexo-cli -g
如果npm安装很慢,被墙了,推荐使用淘宝镜像

hexo init [folder]
新建一个网站。如果没有设置 folder ,Hexo 默认在目前的文件夹建立网站。
hexo new [layout] <title>hexo new post <title>
新建一篇文章。如果没有设置 layout 的话,默认使用 _config.yml 中的 default_layout 参数代替。如果标题包含空格的话,请使用引号括起来。
hexo generate
生成静态文件。
hexo server
启动服务器。默认情况下,访问网址为: http://localhost:4000/。
hexo deploy
部署网站。
你可以在C、D、E、F盘任意一个地方,只要你喜欢,哪里都是可以的。新建一个文件夹来管理你的blog。
然后在这个文件夹内,右键打开git base here,就是这么神奇,哪里都有它。
hexo -v

hexo init
npm install 或者 cnpm install(如果你用了淘宝镜像)
npm install hexo-deployer-git
hexo g
hexo s
然后会提示你:
INFO Hexo is running at http://0.0.0.0:4000/. Press Ctrl+C to stop.
在浏览器中打开http://localhost:4000/,你将会看到:
到这里 恭喜你,你的本地blog已经搭建好了,把本地圈起来要考。哈哈哈[捂脸]
考虑到大家可能会存在的一种情况,就是换电脑,或者在家里和公司都想写blog,管理他,该怎么做呢!

这个分支就是用来装hexo的核心源文件的!慢慢往下看,一步一步来
在你的博客文件夹内,打开git base here。如果你的文件正确的话,现在是没有.git文件的,这是个隐藏文件夹,有的小伙伴没有设置怎么查看隐藏文件,不会的可以根据你的系统去百度一下,很简单的。
git init //初始化本地仓库 会生成一个.git文件git add source scaffolds themes .gitignore _config.yml package.json //将这6个文件提交到hexo分支,这就是源文件了, source里面就是装的你的博客文章git commit -m "Blog Source Hexo"git branch hexo //新建hexo分支git checkout hexo //切换到hexo分支上git remote add origin https://github.com/FinGet/finget.github.io.git(换成你自己的,如下图) //将本地与Github项目对接 很多教程说要用ssh,我这里用https也没有出错git push origin hexo //push到Github项目的hexo分支上

提交完成之后,你可以在github上的厂库里看到:

在你博客文件夹中找的F:\hexoBlog\_config.yml文件,修改以下几处 (文末附上其他配置信息介绍)
# Sitetitle: FinGet # 博客名subtitle: 前端 —— 我一直在路上 # 副标题description: # 描述author: FinGet # 作者language: zh-Hans # 语言,还是改成汉语吧timezone:
deploy:type: git// 这里可能需要密码repository: https://github.com/FinGet/finget.github.io.gitbranch: master
然后你就可以执行以下命令
hexo g
hexo d
现在可以再打开yourname.github.io看看了。不出意外,就成功了。
在新电脑上,nodejs,git,github这些都要有哦
git clone -b hexo https://github.com/FinGet/finget.github.io.git //将Github中hexo分支clone到本地cd yourname.github.io //切换到刚刚clone的文件夹内npm install //注意,这里一定要切换到刚刚clone的文件夹内执行,安装必要的所需组件,不用再initnpm install -g hexo-cli // 如果电脑上没有安装这个,需要先安装hexo new post "new blog name" //新建一个.md文件,并编辑完成自己的博客内容git add source //经测试每次只要更新sorcerer中的文件到Github中即可,因为只是新建了一篇新博客git commit -m "XX"git push origin hexo //更新分支hexo d -g //push更新完分支之后将自己写的博客对接到自己搭的博客网站上,同时同步了Github中的master
如果hexo d -g没有生效
可以再执行
hexo ghexo d
你如果有多个电脑在用,每次写了blog在其他电脑上执行一下:
git pull origin hexo
安装next主题:https://blog.csdn.net/zuoziji416/article/details/53204478
主题配置:https://segmentfault.com/a/1190000009544924
# Site #站点信息title: blog Name #标题subtitle: Subtitle #副标题description: my blog desc #描述author: me #作者language: zh-CN #语言timezone: Asia/Shanghai #时区# URLurl: http://yoururl.com #用于绑定域名, 其他的不需要配置root: /#permalink: :year/:month/:day/:title/permalink: posts/title.htmlpermalink_defaults:# Directory #目录source_dir: source #源文件public_dir: public #生成的网页文件tag_dir: tags #标签archive_dir: archives #归档category_dir: categories #分类code_dir: downloads/codei18n_dir: :lang #国际化skip_render:# Writing #写作new_post_name: :title.md #新文章标题default_layout: post #默认模板(post page photo draft)titlecase: false #标题转换成大写external_link: true #新标签页里打开连接filename_case: 0render_drafts: falsepost_asset_folder: falserelative_link: falsefuture: truehighlight: #语法高亮enable: trueline_number: true #显示行号auto_detect: truetab_replace:# Category & Tag #分类和标签default_category: uncategorized #默认分类category_map:tag_map:# Date / Time format #日期时间格式## http://momentjs.com/docs/#/displaying/format/date_format: YYYY-MM-DDtime_format: HH:mm:ss# Pagination #分页per_page: 10 #每页文章数, 设置成 0 禁用分页pagination_dir: page# Extensions #插件和主题## 插件: http://hexo.io/plugins/## 主题: http://hexo.io/themes/theme: next# Deployment #部署, 同时发布在 GitHub 和 GitCafe 上面deploy:- type: gitrepo: git@gitcafe.com:username/username.git,gitcafe-pages- type: gitrepo: git@github.com:username/username.github.io.git,master# Disqus #Disqus评论系统disqus_shortname:plugins: #插件,例如生成 RSS 和站点地图的- hexo-generator-feed- hexo-generator-sitemap