From b3e2e79c3141cac986c72a4b825deae07df9beea Mon Sep 17 00:00:00 2001 From: xugaoyi <894072666@qq.com> Date: Sun, 29 Dec 2019 12:04:38 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/baiduPush.yml | 1 + .github/workflows/ci.yml | 3 +- README.MD | 42 +++++++++---------- baiduPush.sh | 3 +- deploy.sh | 10 +++-- docs/.vuepress/config.js | 17 +++++--- docs/.vuepress/config/nav.js | 2 +- .../02.GitHub Actions 实现自动部署静态博客.md | 12 +++--- ....解决百度无法收录搭建在GitHub上的个人博客的问题.md | 10 ++--- docs/index.md | 4 +- utils/baiduPush.js | 2 +- 11 files changed, 59 insertions(+), 47 deletions(-) diff --git a/.github/workflows/baiduPush.yml b/.github/workflows/baiduPush.yml index 35581e7..65109f8 100644 --- a/.github/workflows/baiduPush.yml +++ b/.github/workflows/baiduPush.yml @@ -7,6 +7,7 @@ on: push: schedule: - cron: '0 23 * * *' # https://help.github.com/en/actions/automating-your-workflow-with-github-actions/events-that-trigger-workflows#scheduled-events-schedule + # on: # schedule: # - cron: '*/5 * * * *' # 每5分钟一次,测试用 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d31a781..fd1ba8b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,6 +27,7 @@ jobs: # 工作流 env: # 设置环境变量 GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }} # toKen私密变量 CODING_TOKEN: ${{ secrets.CODING_TOKEN }} # 腾讯云开发者平台(coding)私密token + BAIDU_TONGJI: ${{ secrets.BAIDU_TONGJI}} # 百度统计 run: npm install && npm run deploy # - name: Build and Deploy # 步骤3 (只提交到github可以使用这个步骤) @@ -36,4 +37,4 @@ jobs: # 工作流 # BASE_BRANCH: master # 要部署的文件夹所在的分支. # BRANCH: gh-pages # 部署到的分支 # FOLDER: docs/.vuepress/dist # 要部署的文件夹. - # BUILD_SCRIPT: npm install && npm run build && cd docs/.vuepress/dist && echo 'b.evanblogweb.com' > CNAME && cd - # 部署前要执行的命令(记得cd进入某个目录后,后面要cd -退回开始的目录) \ No newline at end of file + # BUILD_SCRIPT: npm install && npm run build && cd docs/.vuepress/dist && echo 'xugaoyi.com' > CNAME && cd - # 部署前要执行的命令(记得cd进入某个目录后,后面要cd -退回开始的目录) \ No newline at end of file diff --git a/README.MD b/README.MD index c4afc7b..1c37279 100644 --- a/README.MD +++ b/README.MD @@ -45,7 +45,7 @@ npm run dev # or yarn dev ```bash # 如果是发布到自定义域名 -echo 'evanblogweb.com' > CNAME +echo 'xugaoyi.com' > CNAME # 如果发布到 https://.github.io # git push -f git@github.com:/.github.io.git master @@ -79,17 +79,17 @@ npm run deploy # 运行部署脚本deploy.sh,并发布到仓库的gh-pages分支 -> 注意:如果您有自定义域名,需要在`.github/workflows/ci.yml`中修改`evanblogweb.com`为你的域名。 +> 注意:如果您有自定义域名,需要在`.github/workflows/ci.yml`中修改`xugaoyi.com`为你的域名。 > -> 如没有自定义域名,需要在`.github/workflows/ci.yml`中去掉`cd docs/.vuepress/dist && echo 'evanblogweb.com' > CNAME && cd -`命令 +> 如没有自定义域名,需要在`.github/workflows/ci.yml`中去掉`cd docs/.vuepress/dist && echo 'xugaoyi.com' > CNAME && cd -`命令 > -> 参考 [GitHub Action教程](http://www.ruanyifeng.com/blog/2019/09/getting-started-with-github-actions.html) +> 参考 [GitHub Action实现自动部署静态博客](http://xugaoyi.com/pages/6b9d359ec5aa5019/) #### 4.1、部署升级:同时部署到github和[coding](https://dev.tencent.com/) -为了让博客站能够让百度收录,因此我把博客部署到了coding(腾讯云开发者平台),相关[文章](https://evanblogweb.com/other/baidushoulu.html)。 +为了让博客站能够让百度收录,因此我把博客部署到了coding相关[文章](https://xugaoyi.com/pages/41f87d890d0a02af/)。 在原有部署方式上做了升级,实现同时部署到github和coding。 @@ -104,7 +104,7 @@ npm run build # 生成静态文件 cd docs/.vuepress/dist # 进入生成的文件夹 # deploy to github -echo 'b.evanblogweb.com' > CNAME +echo 'blog.xugaoyi.com' > CNAME if [ -z "$GITHUB_TOKEN" ]; then msg='deploy' githubUrl=git@github.com:xugaoyi/blog.git @@ -120,7 +120,7 @@ git commit -m "${msg}" git push -f $githubUrl master:gh-pages # 推送到github # deploy to coding -echo 'www.evanblogweb.com\nevanblogweb.com' > CNAME # 自定义域名 +echo 'www.xugaoyi.com\nxugaoyi.com' > CNAME # 自定义域名 if [ -z "$CODING_TOKEN" ]; then # -z 字符串 长度为0则为true;$CODING_TOKEN来自于github仓库`Settings/Secrets`设置的私密环境变量 codingUrl=git@git.dev.tencent.com:xugaoyi/xugaoyi.git else @@ -138,7 +138,7 @@ rm -rf docs/.vuepress/dist `ci.yml`文件: -> 看不懂yaml代码? 参考: +> 看不懂yaml代码? 参考: ```yaml name: CI @@ -176,7 +176,7 @@ jobs: # 工作流 # BASE_BRANCH: master # 要部署的文件夹所在的分支. # BRANCH: gh-pages # 部署到的分支 # FOLDER: docs/.vuepress/dist # 要部署的文件夹. - # BUILD_SCRIPT: npm install && npm run build && cd docs/.vuepress/dist && echo 'b.evanblogweb.com' > CNAME && cd - # 部署前要执行的命令(记得cd进入某个目录后,后面要cd -退回开始的目录) + # BUILD_SCRIPT: npm install && npm run build && cd docs/.vuepress/dist && echo 'xugaoyi.com' > CNAME && cd - # 部署前要执行的命令(记得cd进入某个目录后,后面要cd -退回开始的目录) ``` 使用前先将[github token (令牌) ](https://help.github.com/en/articles/creating-a-personal-access-token-for-the-command-line)和[coding token (令牌)](https://dev.tencent.com/help/doc/account/access-token) 同时设置到github仓库的`Settings/Secrets`位置。 @@ -195,7 +195,7 @@ npm run deploy 只需要push提交代码到github仓库master分支即可。 -> 参考 [GitHub Action教程](http://www.ruanyifeng.com/blog/2019/09/getting-started-with-github-actions.html) +> 参考 [GitHub Action实现自动部署静态博客](http://xugaoyi.com/pages/6b9d359ec5aa5019/) @@ -205,38 +205,38 @@ npm run deploy #### 1、申请域名 -申请域名当然去哪都行。 国内的[阿里云](https://link.zhihu.com/?target=https%3A//wanwang.aliyun.com/domain/),腾讯云,国外的[freenom](https://link.zhihu.com/?target=http%3A//www.freenom.com/),namecheap什么的 。 操作大同小异,都是 +申请域名当然去哪都行。 国内的[阿里云](https://link.zhihu.com/?target=https%3A//wanwang.aliyun.com/domain/),[腾讯云](https://cloud.tencent.com/),国外的[freenom](https://link.zhihu.com/?target=http%3A//www.freenom.com/),namecheap什么的 。 操作大同小异,都是 * 注册账号,登录 -* 搜索并找到可用的域名,买下来。比如我在阿里云买的一个域名:`evanblogweb.com` +* 搜索并找到可用的域名,买下来。比如我在腾讯云买的一个域名:`xugaoyi.com` #### 2、DNS解析 -想要在浏览器里面输入`evanblogweb.com`就能跳到博客页面。我们首先需要做的就是将`evanblogweb.com` 与固定的ip地址绑定起来(A),或者是与某已有域名绑定起来(CNAME)。 +想要在浏览器里面输入`xugaoyi.com`就能跳到博客页面。我们首先需要做的就是通过DNS解析将`xugaoyi.com` 与某已有域名绑定起来(CNAME),或者是固定的ip地址绑定起来(A)。 -这里以阿里云操作为例,步骤如下: +这里以腾讯云操作为例,步骤如下: * 域名列表中点击`解析` -![dns1](https://raw.githubusercontent.com/xugaoyi/image_store/master/blog/dns1.png) +![解析](https://raw.githubusercontent.com/xugaoyi/image_store/master/blog/20191228212829.png) -* 进入解析页面后,点击`添加记录`。填入,记录类型:`CNAME`,主机记录:`www`,解析线路:默认,记录值:你的github pages地址`.github.io`,TTL:默认的10分钟,确定。 +* 进入解析页面后,点击`添加记录`。填入,记录类型:`CNAME`,主机记录:`www`或`@`,解析线路:默认,记录值:你的github pages地址`.github.io`,TTL:默认的10分钟,确定。 -![dns2](https://raw.githubusercontent.com/xugaoyi/image_store/master/blog/dns2.png) +![解析2](https://raw.githubusercontent.com/xugaoyi/image_store/master/blog/20191228213125.png) #### 3、使github pages与域名关联 deploy.sh添加如下脚本 ```bash -echo 'evanblogweb.com' > CNAME # // 域名替换成你的 +echo 'xugaoyi.com' > CNAME # // 域名替换成你的 ``` 在自动部署配置文件ci.yml的jobs.build.steps..env.BUILD_SCRIPT中添加脚本 ```sh -"cd docs/.vuepress/dist && echo 'evanblogweb.com' > CNAME" && cd - +"cd docs/.vuepress/dist && echo 'xugaoyi.com' > CNAME" && cd - # 域名替换成你的 ``` @@ -256,9 +256,9 @@ echo 'evanblogweb.com' > CNAME # // 域名替换成你的 [ 'vuepress-plugin-baidu-tongji', // 百度统计,https://tongji.baidu.com { - hm: '8a59017a97d9fc47d607481723b7815d' + hm: '8a5**************47d607481723b7815d' } ] ``` -> 如果你也需要百度统计功能,请把hm参数该为你自己的,请到https://tongji.baidu.com获取你自己的hm参数 \ No newline at end of file +> 如果你也需要百度统计功能,请把hm参数该为你自己的,请到获取你自己的hm参数 \ No newline at end of file diff --git a/baiduPush.sh b/baiduPush.sh index 8cff6b8..b085004 100644 --- a/baiduPush.sh +++ b/baiduPush.sh @@ -6,6 +6,7 @@ set -e node utils/baiduPush.js # 生成所有链接文件 # 百度链接推送 -curl -H 'Content-Type:text/plain' --data-binary @urls.txt "http://data.zz.baidu.com/urls?site=evanblogweb.com&token=T5PEAzhGaPNbjQ2X" +# curl -H 'Content-Type:text/plain' --data-binary @urls.txt "http://data.zz.baidu.com/urls?site=evanblogweb.com&token=T5PEAzhGaPNbjQ2X" +curl -H 'Content-Type:text/plain' --data-binary @urls.txt "http://data.zz.baidu.com/urls?site=https://xugaoyi.com&token=T5PEAzhGaPNbjQ2X" rm -rf urls.txt # 灭迹 \ No newline at end of file diff --git a/deploy.sh b/deploy.sh index 82a58fc..c08f79a 100644 --- a/deploy.sh +++ b/deploy.sh @@ -10,7 +10,7 @@ npm run build cd docs/.vuepress/dist # deploy to github -echo 'b.evanblogweb.com' > CNAME +echo 'b.xugaoyi.com' > CNAME if [ -z "$GITHUB_TOKEN" ]; then msg='deploy' githubUrl=git@github.com:xugaoyi/blog.git @@ -26,11 +26,13 @@ git commit -m "${msg}" git push -f $githubUrl master:gh-pages # 推送到github # deploy to coding -echo 'www.evanblogweb.com\nevanblogweb.com' > CNAME # 自定义域名 +echo 'www.xugaoyi.com\nxugaoyi.com' > CNAME # 自定义域名 if [ -z "$CODING_TOKEN" ]; then # -z 字符串 长度为0则为true;$CODING_TOKEN来自于github仓库`Settings/Secrets`设置的私密环境变量 - codingUrl=git@git.dev.tencent.com:xugaoyi/xugaoyi.git + #codingUrl=git@git.dev.tencent.com:xugaoyi/xugaoyi.git + codingUrl=git@e.coding.net:xgy/xgy.git else - codingUrl=https://xugaoyi:${CODING_TOKEN}@git.dev.tencent.com/xugaoyi/xugaoyi.git + # codingUrl=https://xugaoyi:${CODING_TOKEN}@git.dev.tencent.com/xugaoyi/xugaoyi.git + condingUrl=https://xgy:${CODING_TOKEN}@e.coding.net/xgy/xgy.git fi git add -A git commit -m "${msg}" diff --git a/docs/.vuepress/config.js b/docs/.vuepress/config.js index 59dbd2b..5946874 100644 --- a/docs/.vuepress/config.js +++ b/docs/.vuepress/config.js @@ -1,16 +1,21 @@ const nav = require('./config/nav.js'); // const sidebar = require('./config/sidebar.js'); const sidebar = require('./config/sidebar-auto.js'); +const logger = require('tracer').colorConsole(); + +const BAIDU_TONGJI = process.env.BAIDU_TONGJI || ''; +if (!BAIDU_TONGJI) { + logger.warn('未配置百度统计参数,将无法使用百度统计'); +} module.exports = { title: 'Evan Blog', // 标题 description: 'web前端技术博客,基于vuepress构建,专注web前端学习与总结。JavaScript,js,ES6,TypeScript,vue,python,css3,html5,Node,git,github等技术文章。', // 描述,以 标签渲染到当前页面的 HTML 中 - // process.env.VUEPRESS_BASE 在package.json生成 - // base: process.env.VUEPRESS_BASE || '/', // 基础路径,默认'/',如果放到github pages要改成仓库名 + // base: '/blog/', //默认'/' || github仓库名'/<仓库名>/', head: [ // 注入到当前页面 中的标签,格式[tagName, { attrName: attrValue }, innerHTML?] ['link', { rel: 'icon', href: '/img/logo2.png' }], //favicons,资源放在public文件夹 ['meta', { name: 'keywords', content: '个人博客,技术博客,前端,前端开发,前端框架,web前端,前端面试题,技术文档,学习,面试,JavaScript,js,ES6,TypeScript,vue,python,css3,html5,Node,git,github,markdown'}], - ['meta', { name: 'baidu-site-verification', content: 'YwUALncFiI'}], + ['meta', { name: 'baidu-site-verification', content: '7F55weZDDc'}], // ['script', { src: 'https://hm.baidu.com/hm.js?837775213e724293b4af2b9526e238b4'}] ], markdown: { @@ -20,7 +25,7 @@ module.exports = { nav, sidebar, // 侧边栏 'auto' | 自定义 logo: '/img/logo2.png', // 导航栏logo - repo: 'xugaoyi/evanblog', // 导航栏右侧生成Github链接 + repo: 'xugaoyi/blog', // 导航栏右侧生成Github链接 lastUpdated: '更新于', // 更新的时间,及前缀文字 string | boolean // editLinks: true, // 编辑链接 // editLinkText: '在 Github 上编辑此页', @@ -40,7 +45,7 @@ module.exports = { [ 'vuepress-plugin-baidu-tongji', // 百度统计,https://tongji.baidu.com { - hm: '837775213e724293b4af2b9526e238b4' + hm: BAIDU_TONGJI } ], [ @@ -54,7 +59,7 @@ module.exports = { owner: 'xugaoyi', // GitHub仓库所有者 admin: ['xugaoyi'], // 对仓库有写权限的人 distractionFreeMode: false, - id: "<%- frontmatter.permalink.slice(-16) %>", // 页面的唯一标识,长度不能超过50 + id: "<%- (frontmatter.permalink || frontmatter.to.path).slice(-16) %>", // 页面的唯一标识,长度不能超过50 title: "「评论」<%- frontmatter.title %>", // GitHub issue 的标题 // id: "<%- (window.location.origin + (frontmatter.to.path || window.location.pathname)).slice(-50) %>", // title: "「评论」<%- window.location.origin + (frontmatter.to.path || window.location.pathname) %>", diff --git a/docs/.vuepress/config/nav.js b/docs/.vuepress/config/nav.js index da402b5..93e493f 100644 --- a/docs/.vuepress/config/nav.js +++ b/docs/.vuepress/config/nav.js @@ -50,7 +50,7 @@ module.exports = [ // ]}, // {text: '其他',items:[ // {text: '在线工具', link: '/other/utils'}, - // {text: '关于本博客搭建', link: 'https://github.com/xugaoyi/evanblog'}, + // {text: '关于本博客搭建', link: 'https://github.com/xugaoyi/blog'}, // {text: '解决百度无法收录搭建在GitHub上的个人博客的问题', link: '/other/baidushoulu'} // ]}, // ]}, diff --git a/docs/03.技术杂谈/02.GitHub/02.GitHub Actions 实现自动部署静态博客.md b/docs/03.技术杂谈/02.GitHub/02.GitHub Actions 实现自动部署静态博客.md index 60e6deb..5337e64 100644 --- a/docs/03.技术杂谈/02.GitHub/02.GitHub Actions 实现自动部署静态博客.md +++ b/docs/03.技术杂谈/02.GitHub/02.GitHub Actions 实现自动部署静态博客.md @@ -29,7 +29,7 @@ coding pages在国内的访问速度比github pages要快很多,而且还可 GitHub Actions 的配置文件叫做 workflow 文件,存放在代码仓库的`.github/workflows`目录。 -workflow 文件采用 [YAML 格式](https://evanblogweb.com/pages/4e8444e2d534d14f/),文件名可以任意取,但是后缀名统一为`.yml`,比如`ci.yml`。一个库可以有多个 workflow 文件。GitHub 只要发现`.github/workflows`目录里面有`.yml`文件,就会自动运行该文件。 +workflow 文件采用 [YAML 格式](https://xugaoyi.com/pages/4e8444e2d534d14f/),文件名可以任意取,但是后缀名统一为`.yml`,比如`ci.yml`。一个库可以有多个 workflow 文件。GitHub 只要发现`.github/workflows`目录里面有`.yml`文件,就会自动运行该文件。 我的`ci.yml`文件: @@ -85,7 +85,7 @@ npm run build # 生成静态文件 cd docs/.vuepress/dist # 进入生成的文件夹 # deploy to github -echo 'b.evanblogweb.com' > CNAME +echo 'blog.xugaoyi.com' > CNAME if [ -z "$GITHUB_TOKEN" ]; then msg='deploy' githubUrl=git@github.com:xugaoyi/blog.git @@ -101,7 +101,7 @@ git commit -m "${msg}" git push -f $githubUrl master:gh-pages # 推送到github # deploy to coding -echo 'www.evanblogweb.com\nevanblogweb.com' > CNAME # 自定义域名 +echo 'www.xugaoyi.com\nxugaoyi.com' > CNAME # 自定义域名 if [ -z "$CODING_TOKEN" ]; then # -z 字符串 长度为0则为true;$CODING_TOKEN来自于github仓库`Settings/Secrets`设置的私密环境变量 codingUrl=git@git.dev.tencent.com:xugaoyi/xugaoyi.git else @@ -117,9 +117,11 @@ rm -rf docs/.vuepress/dist 这个文件使用[Shell命令](https://ipcmen.com/)写的,它会先运行打包命令,进入打包好的文件,创建一个自定义域名的CNAME文件(如果你没有自定义域名可去掉这个命令),判断是否有token环境变量,如果没有说明是在本地自己的电脑上运行的部署,使用ssh代码仓库地址,如果有token环境变量,说明是GitHub Actions自动触发的部署,此时使用的是可以通过toKen开获取代码提交权限的提交地址。最后通过git命令提交到各自的仓库,完成部署。 -> Shell 可以获取到环境变量。 +> 提示: > -> 我想给两个平台上部署的博客不一样的自定义域名,因此做了分开创建CNAME文件,分开提交。 +> * Shell 可以获取到环境变量。 +> +> * 我想给两个平台上部署的博客不一样的自定义域名,因此做了分开创建CNAME文件,分开提交。 diff --git a/docs/03.技术杂谈/04.博客搭建/01.解决百度无法收录搭建在GitHub上的个人博客的问题.md b/docs/03.技术杂谈/04.博客搭建/01.解决百度无法收录搭建在GitHub上的个人博客的问题.md index a27ec71..90b83ba 100644 --- a/docs/03.技术杂谈/04.博客搭建/01.解决百度无法收录搭建在GitHub上的个人博客的问题.md +++ b/docs/03.技术杂谈/04.博客搭建/01.解决百度无法收录搭建在GitHub上的个人博客的问题.md @@ -15,7 +15,7 @@ permalink: /pages/41f87d890d0a02af 同时将博客同时同步托管到GitHub Pages和[coding pages](https://dev.tencent.com/)上,解决百度不收录问题。最后发现在国内使用coding pages打开速度特别快,而且还会被百度收录,因此我把coding pages的站点作为主站点,原本在github pages的作为分站点。 -> 注意:我使用的是coding个人版,即腾讯云开发者平台。 + 步骤: @@ -38,14 +38,14 @@ npm run build cd docs/.vuepress/dist # github -echo 'b.evanblogweb.com' > CNAME +echo 'b.xugaoyi.com' > CNAME git init git add -A git commit -m 'deploy' -git push -f git@github.com:xugaoyi/evanblog.git master:gh-pages # 发布到github +git push -f git@github.com:xugaoyi/blog.git master:gh-pages # 发布到github # coding -echo 'evanblogweb.com' > CNAME +echo 'xugaoyi.com' > CNAME git add -A git commit -m 'deploy' git push -f git@git.dev.tencent.com:xugaoyi/xugaoyi.git master # 发布到coding @@ -69,6 +69,6 @@ rm -rf docs/.vuepress/dist 在百度搜索框中使用site:<链接地址\>,如: ``` -site:evanblogweb.com +site:xugaoyi.com ``` diff --git a/docs/index.md b/docs/index.md index c5719d0..7696381 100644 --- a/docs/index.md +++ b/docs/index.md @@ -17,7 +17,7 @@ features: details: 技术文档、教程、技巧、学习笔记等 url: /pages/9a7ee40fc232253e/ imgname: /img/other.png -footer: Copyright © 2019-present evanblog +footer: Copyright © 2019-present xugaoyi --- ## :earth_americas:前端 @@ -53,7 +53,7 @@ footer: Copyright © 2019-present evanblog * [面试问题集锦](/pages/aea6571b7a8bae86/) * 其他 * [在线工具](/pages/9c2232288caaa8ec/) - * [关于本博客搭建](https://github.com/xugaoyi/evanblog) + * [关于本博客搭建](https://github.com/xugaoyi/blog) ## :email: 联系 diff --git a/utils/baiduPush.js b/utils/baiduPush.js index 2871ef1..f2b1712 100644 --- a/utils/baiduPush.js +++ b/utils/baiduPush.js @@ -7,7 +7,7 @@ const path = require('path'); const readFileList = require('./modules/readFileList'); const urlsRoot = path.join(__dirname, '..', 'urls.txt'); // 百度链接推送文件 -const DOMAIN = 'https://evanblogweb.com' +const DOMAIN = 'https://xugaoyi.com' main();