通常我们可以使用github pages 来搭建静态博客,建立一个username.github.io的项目就可以了,如果要将其他项目也作为页面展示,可以将代码推送到gh-pages分支。
GitHub pages木有默认样式,所以如果你不会自己写css,博客很难看的,所以我们需要hexo.
准备
先安装好git node hexo
初始化
$ hexo init blogINFO Cloning hexo-starter to D:\code\hexo\blogCloning into 'D:\code\hexo\blog'...remote: Enumerating objects: 68, done.remote: Total 68 (delta 0), reused 0 (delta 0), pack-reused 68Unpacking objects: 100% (68/68), done.Submodule 'themes/landscape' (https://github.com/hexojs/hexo-theme-landscape.git) registered for path 'themes/landscape'Cloning into 'D:/code/hexo/blog/themes/landscape'...remote: Enumerating objects: 5, done.remote: Counting objects: 100% (5/5), done.remote: Compressing objects: 100% (5/5), done.remote: Total 846 (delta 0), reused 1 (delta 0), pack-reused 841Receiving objects: 100% (846/846), 2.55 MiB | 16.00 KiB/s, done.Resolving deltas: 100% (445/445), done.Submodule path 'themes/landscape': checked out '73a23c51f8487cfcd7c6deec96ccc7543960d350'INFO Install dependenciesyarn install v1.9.4info No lockfile found.[1/4] Resolving packages...warning hexo > titlecase@1.1.2: no longer maintainedwarning hexo > nunjucks > postinstall-build@5.0.3: postinstall-build's behavior is now built into npm! You should migrate off of postinstall-build and use the new `prepare` lifecycle script with npm 5.0.0 or greater.[2/4] Fetching packages...info fsevents@1.2.4: The platform "win32" is incompatible with this module.info "fsevents@1.2.4" is an optional dependency and failed compatibility check. Excluding it from installation.[3/4] Linking dependencies...[4/4] Building fresh packages...success Saved lockfile.Done in 18.06s.INFO Start blogging with Hexo!$ cd blog$ npm installnpm WARN deprecated titlecase@1.1.2: no longer maintainednpm WARN deprecated postinstall-build@5.0.3: postinstall-build's behavior is now built into npm! You should migrate off of postinstall-build and use the new `prepare` lifecycle script with npm 5.0.0 or greater.> nunjucks@3.1.4 postinstall D:\code\hexo\blog\node_modules\nunjucks> node postinstall-build.js srcnpm WARN rollback Rolling back node-pre-gyp@0.10.0 failed (this is probably harmless): EPERM: operation not permitted, rmdir 'D:\code\hexo\blog\node_modules\fsevents\node_modules'npm notice created a lockfile as package-lock.json. You should commit this file.npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modules\fsevents):npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})added 101 packages, removed 40 packages and updated 321 packages in 23.882s$ ls_config.yml package.json scaffolds/ themes/node_modules/ package-lock.json source/ yarn.lock$ hexo gINFO Start processingINFO Files loaded in 655 msINFO Generated: index.htmlINFO Generated: archives/index.htmlINFO Generated: fancybox/jquery.fancybox.cssINFO Generated: fancybox/blank.gifINFO Generated: fancybox/fancybox_loading@2x.gifINFO Generated: fancybox/fancybox_sprite@2x.pngINFO Generated: fancybox/jquery.fancybox.jsINFO Generated: fancybox/jquery.fancybox.pack.jsINFO Generated: fancybox/fancybox_sprite.pngINFO Generated: fancybox/fancybox_overlay.pngINFO Generated: archives/2018/11/index.htmlINFO Generated: fancybox/fancybox_loading.gifINFO Generated: css/fonts/FontAwesome.otfINFO Generated: fancybox/helpers/jquery.fancybox-thumbs.cssINFO Generated: js/script.jsINFO Generated: fancybox/helpers/jquery.fancybox-buttons.jsINFO Generated: fancybox/helpers/jquery.fancybox-media.jsINFO Generated: fancybox/helpers/jquery.fancybox-buttons.cssINFO Generated: css/fonts/fontawesome-webfont.eotINFO Generated: css/fonts/fontawesome-webfont.woffINFO Generated: fancybox/helpers/fancybox_buttons.pngINFO Generated: fancybox/helpers/jquery.fancybox-thumbs.jsINFO Generated: css/style.cssINFO Generated: css/fonts/fontawesome-webfont.ttfINFO Generated: archives/2018/index.htmlINFO Generated: css/images/banner.jpgINFO Generated: css/fonts/fontawesome-webfont.svgINFO Generated: 2018/11/20/hello-world/index.htmlINFO 28 files generated in 1.26 s$ hexo sINFO Start processingINFO Hexo is running at http://localhost:4000 . Press Ctrl+C to stop$ hexo dERROR Deployer not found: git
GitHub key 配置
1.生成指定名字的密钥 ssh-keygen -t rsa -C "xx@sina.com" -f ~/.ssh/github_sushengbuhuo 会生成 github_sushengbuhuo 和 github_sushengbuhuo.pub 这两个文件2.密钥复制到托管平台上 vim ~/.ssh/github_sushengbuhuo.pub ,把内容复制至代码托管平台上3.修改config文件 vim ~/.ssh/config #修改config文件,如果没有创建 configHost sushengbuhuo.github.comHostName github.comUser gitIdentityFile ~/.ssh/github_sushengbuhuoHost abc.github.comHostName github.comUser gitIdentityFile ~/.ssh/github_abc4.测试验证$ ssh -T git@github.com:ssh: Could not resolve hostname github.com:: Name or service not known$ ssh -T git@github.comgit@github.com: Permission denied (publickey).$ ssh -T git@sushengbuhuo.github.comHi sushengbuhuo! You've successfully authenticated, but GitHub does not provide shell access.
配置config.yml
deploy: type: git repository: git@sushengbuhuo.github.com:sushengbuhuo/sushengbuhuo.github.io.git branch: master theme: next
推送到GitHub
$ hexo clean && hexo gINFO Deleted database.INFO Deleted public folder.INFO Start processingINFO Files loaded in 545 msINFO Generated: index.htmlINFO Generated: archives/index.htmlINFO Generated: fancybox/fancybox_loading.gifINFO Generated: fancybox/fancybox_sprite@2x.pngINFO Generated: fancybox/jquery.fancybox.jsINFO Generated: fancybox/fancybox_overlay.pngINFO Generated: fancybox/jquery.fancybox.cssINFO Generated: fancybox/jquery.fancybox.pack.jsINFO Generated: fancybox/blank.gifINFO Generated: fancybox/fancybox_loading@2x.gifINFO Generated: fancybox/fancybox_sprite.pngINFO Generated: css/fonts/FontAwesome.otfINFO Generated: archives/2018/11/index.htmlINFO Generated: css/fonts/fontawesome-webfont.eotINFO Generated: archives/2018/index.htmlINFO Generated: fancybox/helpers/fancybox_buttons.pngINFO Generated: fancybox/helpers/jquery.fancybox-thumbs.jsINFO Generated: css/fonts/fontawesome-webfont.woffINFO Generated: fancybox/helpers/jquery.fancybox-buttons.cssINFO Generated: js/script.jsINFO Generated: fancybox/helpers/jquery.fancybox-buttons.jsINFO Generated: css/style.cssINFO Generated: fancybox/helpers/jquery.fancybox-thumbs.cssINFO Generated: 2018/11/20/hello-world/index.htmlINFO Generated: css/fonts/fontawesome-webfont.ttfINFO Generated: css/fonts/fontawesome-webfont.svgINFO Generated: css/images/banner.jpgINFO Generated: fancybox/helpers/jquery.fancybox-media.jsINFO 28 files generated in 1.13 s$ hexo dERROR Deployer not found: git$ npm install hexo-deployer-git --savenpm WARN deprecated swig@1.4.2: This package is no longer maintainednpm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modules\fsevents):npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})+ hexo-deployer-git@0.3.1added 31 packages in 17.866s$ hexo dINFO Deploying: gitINFO Setting up Git deployment...Initialized empty Git repository in D:/code/hexo/blog/.deploy_git/.git/[master (root-commit) 9c86786] First commit Committer: unknownYour name and email address were configured automatically basedon your username and hostname. Please check that they are accurate.You can suppress this message by setting them explicitly: git config --global user.name "Your Name" git config --global user.email you@example.comAfter doing this, you may fix the identity used for this commit with: git commit --amend --reset-author 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 placeholderINFO Clearing .deploy_git folder...INFO Copying files from public folder...INFO Copying files from extend dirs...warning: LF will be replaced by CRLF in 2018/11/20/hello-world/index.html.The file will have its original line endings in your working directory.warning: LF will be replaced by CRLF in archives/2018/11/index.html.The file will have its original line endings in your working directory.warning: LF will be replaced by CRLF in archives/2018/index.html.The file will have its original line endings in your working directory.warning: LF will be replaced by CRLF in archives/index.html.The file will have its original line endings in your working directory.warning: LF will be replaced by CRLF in css/style.css.The file will have its original line endings in your working directory.warning: LF will be replaced by CRLF in fancybox/helpers/jquery.fancybox-buttons.css.The file will have its original line endings in your working directory.warning: LF will be replaced by CRLF in fancybox/helpers/jquery.fancybox-buttons.js.The file will have its original line endings in your working directory.warning: LF will be replaced by CRLF in fancybox/helpers/jquery.fancybox-media.js.The file will have its original line endings in your working directory.warning: LF will be replaced by CRLF in fancybox/helpers/jquery.fancybox-thumbs.css.The file will have its original line endings in your working directory.warning: LF will be replaced by CRLF in fancybox/helpers/jquery.fancybox-thumbs.js.The file will have its original line endings in your working directory.warning: LF will be replaced by CRLF in fancybox/jquery.fancybox.css.The file will have its original line endings in your working directory.warning: LF will be replaced by CRLF in fancybox/jquery.fancybox.js.The file will have its original line endings in your working directory.warning: LF will be replaced by CRLF in fancybox/jquery.fancybox.pack.js.The file will have its original line endings in your working directory.warning: LF will be replaced by CRLF in index.html.The file will have its original line endings in your working directory.warning: LF will be replaced by CRLF in js/script.js.The file will have its original line endings in your working directory.[master b7f7580] Site updated: 2018-11-20 11:51:50 Committer: unknown Your name and email address were configured automatically basedon your username and hostname. Please check that they are accurate.You can suppress this message by setting them explicitly: git config --global user.name "Your Name" git config --global user.email you@example.comAfter doing this, you may fix the identity used for this commit with: git commit --amend --reset-author 29 files changed, 5777 insertions(+) create mode 100644 2018/11/20/hello-world/index.html create mode 100644 archives/2018/11/index.html create mode 100644 archives/2018/index.html create mode 100644 archives/index.html create mode 100644 css/fonts/FontAwesome.otf create mode 100644 css/fonts/fontawesome-webfont.eot create mode 100644 css/fonts/fontawesome-webfont.svg create mode 100644 css/fonts/fontawesome-webfont.ttf create mode 100644 css/fonts/fontawesome-webfont.woff create mode 100644 css/images/banner.jpg create mode 100644 css/style.css create mode 100644 fancybox/blank.gif create mode 100644 fancybox/fancybox_loading.gif create mode 100644 fancybox/fancybox_loading@2x.gif create mode 100644 fancybox/fancybox_overlay.png create mode 100644 fancybox/fancybox_sprite.png create mode 100644 fancybox/fancybox_sprite@2x.png create mode 100644 fancybox/helpers/fancybox_buttons.png create mode 100644 fancybox/helpers/jquery.fancybox-buttons.css create mode 100644 fancybox/helpers/jquery.fancybox-buttons.js create mode 100644 fancybox/helpers/jquery.fancybox-media.js create mode 100644 fancybox/helpers/jquery.fancybox-thumbs.css create mode 100644 fancybox/helpers/jquery.fancybox-thumbs.js create mode 100644 fancybox/jquery.fancybox.css create mode 100644 fancybox/jquery.fancybox.js create mode 100644 fancybox/jquery.fancybox.pack.js create mode 100644 index.html create mode 100644 js/script.js delete mode 100644 placeholdergit@github.com: Permission denied (publickey).fatal: Could not read from remote repository.Please make sure you have the correct access rightsand the repository exists.FATAL Something's wrong. Maybe you can find the solution here: http://hexo.io/docs/troubleshooting.htmlError: git@github.com: Permission denied (publickey).fatal: Could not read from remote repository.Please make sure you have the correct access rightsand the repository exists. at ChildProcess. (D:\code\hexo\blog\node_modules\hexo-util\lib\spawn.js:37:17) at emitTwo (events.js:126:13) at ChildProcess.emit (events.js:214:7) at ChildProcess.cp.emit (D:\code\hexo\blog\node_modules\cross-spawn\lib\enoent.js:40:29) at maybeClose (internal/child_process.js:925:16) at Socket.stream.socket.on (internal/child_process.js:346:11) at emitOne (events.js:116:13) at Socket.emit (events.js:211:7) at Pipe._handle.close [as _onclose] (net.js:557:12)$ hexo dINFO Deploying: gitINFO Clearing .deploy_git folder...INFO Copying files from public folder...INFO Copying files from extend dirs...warning: LF will be replaced by CRLF in 2018/11/20/hello-world/index.html.The file will have its original line endings in your working directory.warning: LF will be replaced by CRLF in archives/2018/11/index.html.The file will have its original line endings in your working directory.warning: LF will be replaced by CRLF in archives/2018/index.html.The file will have its original line endings in your working directory.warning: LF will be replaced by CRLF in archives/index.html.The file will have its original line endings in your working directory.warning: LF will be replaced by CRLF in css/style.css.The file will have its original line endings in your working directory.warning: LF will be replaced by CRLF in fancybox/helpers/jquery.fancybox-buttons.css.The file will have its original line endings in your working directory.warning: LF will be replaced by CRLF in fancybox/helpers/jquery.fancybox-buttons.js.The file will have its original line endings in your working directory.warning: LF will be replaced by CRLF in fancybox/helpers/jquery.fancybox-media.js.The file will have its original line endings in your working directory.warning: LF will be replaced by CRLF in fancybox/helpers/jquery.fancybox-thumbs.css.The file will have its original line endings in your working directory.warning: LF will be replaced by CRLF in fancybox/helpers/jquery.fancybox-thumbs.js.The file will have its original line endings in your working directory.warning: LF will be replaced by CRLF in fancybox/jquery.fancybox.css.The file will have its original line endings in your working directory.warning: LF will be replaced by CRLF in fancybox/jquery.fancybox.js.The file will have its original line endings in your working directory.warning: LF will be replaced by CRLF in fancybox/jquery.fancybox.pack.js.The file will have its original line endings in your working directory.warning: LF will be replaced by CRLF in js/script.js.The file will have its original line endings in your working directory.On branch masternothing to commit, working tree cleanBranch 'master' set up to track remote branch 'master' from 'git@sushengbuhuo.github.com:sushengbuhuo/sushengbuhuo.github.io.git'.To sushengbuhuo.github.com:sushengbuhuo/sushengbuhuo.github.io.git + 3037877...b7f7580 HEAD -> master (forced update)INFO Deploy done: git$ git clone https://github.com/iissnan/hexo-theme-next themes/nextCloning into 'themes/next'...remote: Enumerating objects: 12033, done.remote: Total 12033 (delta 0), reused 0 (delta 0), pack-reused 12033Receiving objects: 100% (12033/12033), 12.95 MiB | 79.00 KiB/s, done.Resolving deltas: 100% (6966/6966), done.$ hexo clean && hexo gINFO Deleted database.INFO Deleted public folder.INFO Start processing$ hexo d$ hexo sINFO Start processingWARN ===============================================================WARN ========================= ATTENTION! ==========================WARN ===============================================================WARN NexT repository is moving here: https://github.com/theme-nextWARN ===============================================================WARN It's rebase to v6.0.0 and future maintenance will resume thereWARN ===============================================================INFO Hexo is running at http://localhost:4000 . Press Ctrl+C to stop
安装插件
登录 即可看到我们所有的文章内容
λ npm i hexo-admin --savenpm WARN deprecated minimatch@2.0.10: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issuenpm WARN deprecated connect@2.7.11: connect 2.x series is deprecatednpm WARN deprecated cryptiles@2.0.5: This version is no longer maintained. Please upgrade to the latest version.npm WARN deprecated boom@2.10.1: This version is no longer maintained. Please upgrade to the latest version.npm WARN deprecated hoek@2.16.3: This version is no longer maintained. Please upgrade to the latest version.npm WARN acorn-dynamic-import@4.0.0 requires a peer of acorn@^6.0.0 but none is installed. You must install peer dependencies yourself.npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modules\fsevents):npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})+ hexo-admin@2.3.0added 251 packages in 23.975s ╭─────────────────────────────────────╮ │ │ │ Update available 5.6.0 → 6.4.1 │ │ Run npm i npm to update │ │ │ ╰─────────────────────────────────────╯#网站底部字数统计d:\code\hexo\blogλ npm install hexo-wordcount --savenpm WARN rollback Rolling back node-pre-gyp@0.10.0 failed (this is probably harmless): EPERM: operation not permitted, scandir 'd:\code\hexo\blog\node_modules\fsevents\node_modules'npm WARN acorn-dynamic-import@4.0.0 requires a peer of acorn@^6.0.0 but none is installed. You must install peer dependencies yourself.npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modules\fsevents):npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})+ hexo-wordcount@6.0.1added 1 package in 10.289s
中文乱码问题
将config.yml 和md文件编码转为utf-8
修改config.yml language: zh-Hans
新建文章
$ hexo new "PHP依赖注入"
Hexo 默认以标题为文件名称,可编辑_config.yml new_post_name
参数来改变默认的文件名称,设为 :year-:month-:day-:title.md 可更方便的通过日期来管理文章。
结尾
资源