{"componentChunkName":"component---src-templates-best-practice-detail-tsx","path":"/best-practice/2019-12-4-Quickly-build-personal-blog","result":{"data":{"currentBlog":{"id":"74a25989-4611-5393-85ef-698f2c988635","frontmatter":{"thumbnail":"https://img.serverlesscloud.cn/20191226/1577353111488-website.png","authors":["liujiang"],"categories":["best-practice"],"date":"2019-12-04T00:00:00.000Z","title":"Hexo + Serverless Framework，简单三步搭建你的个人博客","description":"简单三步，即可通过 Serverless Website 组件快速构建一个 Serverless Hexo 站点。","authorslink":["https://github.com/jiangliu5267"],"translators":null,"translatorslink":null,"tags":["Serverless","Hexo"],"keywords":"Hexo Serverless,Serverless Website,Serverless Hexo 站点","outdated":true},"wordCount":{"words":146,"sentences":34,"paragraphs":34},"fileAbsolutePath":"/opt/build/repo/content/best-practice/2019-12-4-Quickly-build-personal-blog.md","fields":{"slug":"/best-practice/2019-12-4-Quickly-build-personal-blog/","keywords":["nodejs","serverless","website","website 组件","无服务器","hexo","serverless","Serverless","yml","Hexo","website","tencent"]},"html":"<p>很多人都想拥有自己的个人博客，还得看起来漂亮、酷酷的。尤其对开发者来说，不仅可以分享技术（装）心得（逼），面试的时候还能成为加分。这里介绍两款好用的神器，不用忙前（前端）忙后（后端），简单3min即可搞定，本文免费分享给大家。</p>\n<blockquote>\n<p>PS：不会写代码？没有备案的域名？没有服务器？在这里，这些都不是事儿！</p>\n</blockquote>\n<p><strong>工具介绍</strong></p>\n<ul>\n<li><a href=\"https://cloud.tencent.com/product/sf\"><strong>Serverless Framework</strong></a>：Serverless Framework 是业界非常受欢迎的无服务器应用框架，开发者无需关心底层资源即可部署完整可用的 Serverless 应用架构。</li>\n<li><a href=\"https://hexo.io/zh-cn/\"><strong>Hexo</strong></a>：Hexo 是一个快速、简洁且高效的博客框架。Hexo 使用 Markdown（或其他渲染引擎）解析文章，在几秒内，即可利用靓丽的主题生成静态网页。</li>\n</ul>\n<p>使用 Serverless Framework 部署一个 Hexo 网站只需三步：：安装与初始化 → 配置 yml 文件 → 部署</p>\n<h2 id=\"安装与初始化\"><a href=\"#%E5%AE%89%E8%A3%85%E4%B8%8E%E5%88%9D%E5%A7%8B%E5%8C%96\" aria-label=\"安装与初始化 permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>安装与初始化</h2>\n<p>简单三步，即可通过 Serverless Website 组件快速构建一个 Serverless Hexo 站点。</p>\n<p><strong>首先确保系统包含以下环境：</strong></p>\n<ul>\n<li><a href=\"https://nodejs.org/en/\">Node.js</a> (Node.js 版本需不低于 8.6，建议使用 Node.js 10.0 及以上版本)</li>\n<li><a href=\"https://git-scm.com/\">Git</a></li>\n</ul>\n<p>如未安装上述应用程序，可以参考<a href=\"https://hexo.io/zh-cn/docs/\">安装说明</a>。</p>\n<p><strong>1. 安装 Serverless Framework</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">$ npm install -g serverless</code></pre></div>\n<p><strong>2. 安装 Hexo</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">$ npm install -g hexo-cli</code></pre></div>\n<p><strong>3. 初始化项目</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">$ hexo init hexo   # 生成hexo目录\n$ cd hexo\n$ npm install</code></pre></div>\n<p>初始化完成后，hexo 文件夹的目录如下：</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">.\n├── _config.yml\n├── package.json\n├── scaffolds\n├── source\n|   ├── _drafts\n|   └── _posts\n└── themes</code></pre></div>\n<p><strong>4. 生成本地博客页面</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">hexo g   # generate</code></pre></div>\n<p>可以通过 <code class=\"language-text\">hexo g</code> 命令生成静态页面，如果希望在本地查看效果，也可以运行下列命令，通过浏览器访问 <a href=\"http://localhost:4000\">http://localhost:4000</a> 查看页面效果。</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">hexo s   # server</code></pre></div>\n<h2 id=\"配置-yml-文件\"><a href=\"#%E9%85%8D%E7%BD%AE-yml-%E6%96%87%E4%BB%B6\" aria-label=\"配置 yml 文件 permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>配置 yml 文件</h2>\n<p>项目目录下，创建 <code class=\"language-text\">serverless.yml</code> 文件</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">cd.&gt; serverless.yml</code></pre></div>\n<p>将以下内容写入上述的 yml 文件里：</p>\n<div\n              class=\"gatsby-code-button-container\"\n              data-toaster-id=\"46051154912828380000\"\n              data-toaster-class=\"gatsby-code-button-toaster\"\n              data-toaster-text-class=\"gatsby-code-button-toaster-text\"\n              data-toaster-text=\"代码复制成功\"\n              data-toaster-duration=\"3500\"\n              onClick=\"copyToClipboard(`# serverless.yml\n\ncomponent: website # (必填) 引用 component 的名称，当前用到的是 tencent-website 组件\nname: hexodemo # (必填) 该 website 组件创建的实例名称\norg: test # (可选) 用于记录组织信息，默认值为您的腾讯云账号 APPID\napp: websiteApp # (可选) 该 website 应用名称\nstage: dev # (可选) 用于区分环境信息，默认值是 dev\n\ninputs:\n  src:\n    src: ./public # Upload static files generated by HEXO\n    index: index.html\n    # dist: ./dist\n    # hook: npm run build\n    # websitePath: ./\n  region: ap-guangzhou\n  bucketName: my-bucket\n  protocol: https`, `46051154912828380000`)\"\n            >\n              <div\n                class=\"gatsby-code-button\"\n                data-tooltip=\"\"\n              >\n                复制代码<svg class=\"gatsby-code-button-icon\" xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\"><path fill=\"none\" d=\"M0 0h24v24H0V0z\"/><path d=\"M16 1H2v16h2V3h12V1zm-1 4l6 6v12H6V5h9zm-1 7h5.5L14 6.5V12z\"/></svg>\n              </div>\n            </div>\n<div class=\"gatsby-highlight\" data-language=\"yaml\"><pre class=\"language-yaml\"><code class=\"language-yaml\"><span class=\"token comment\"># serverless.yml</span>\n\n<span class=\"token key atrule\">component</span><span class=\"token punctuation\">:</span> website <span class=\"token comment\"># (必填) 引用 component 的名称，当前用到的是 tencent-website 组件</span>\n<span class=\"token key atrule\">name</span><span class=\"token punctuation\">:</span> hexodemo <span class=\"token comment\"># (必填) 该 website 组件创建的实例名称</span>\n<span class=\"token key atrule\">org</span><span class=\"token punctuation\">:</span> test <span class=\"token comment\"># (可选) 用于记录组织信息，默认值为您的腾讯云账号 APPID</span>\n<span class=\"token key atrule\">app</span><span class=\"token punctuation\">:</span> websiteApp <span class=\"token comment\"># (可选) 该 website 应用名称</span>\n<span class=\"token key atrule\">stage</span><span class=\"token punctuation\">:</span> dev <span class=\"token comment\"># (可选) 用于区分环境信息，默认值是 dev</span>\n\n<span class=\"token key atrule\">inputs</span><span class=\"token punctuation\">:</span>\n  <span class=\"token key atrule\">src</span><span class=\"token punctuation\">:</span>\n    <span class=\"token key atrule\">src</span><span class=\"token punctuation\">:</span> ./public <span class=\"token comment\"># Upload static files generated by HEXO</span>\n    <span class=\"token key atrule\">index</span><span class=\"token punctuation\">:</span> index.html\n    <span class=\"token comment\"># dist: ./dist</span>\n    <span class=\"token comment\"># hook: npm run build</span>\n    <span class=\"token comment\"># websitePath: ./</span>\n  <span class=\"token key atrule\">region</span><span class=\"token punctuation\">:</span> ap<span class=\"token punctuation\">-</span>guangzhou\n  <span class=\"token key atrule\">bucketName</span><span class=\"token punctuation\">:</span> my<span class=\"token punctuation\">-</span>bucket\n  <span class=\"token key atrule\">protocol</span><span class=\"token punctuation\">:</span> https</code></pre></div>\n<p>配置完成后，文件目录如下：</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">.\n├── .serverless\n└── hexo\n    ├── public\n    ├── ...\n    ├── serverless.yml\n    ├── ...\n    └── source</code></pre></div>\n<h2 id=\"部署\"><a href=\"#%E9%83%A8%E7%BD%B2\" aria-label=\"部署 permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>部署</h2>\n<p>通过<code class=\"language-text\">sls deploy</code>命令进行部署，并可以添加<code class=\"language-text\">--debug</code>参数查看部署过程中的信息。</p>\n<p>如您的账号未<a href=\"https://cloud.tencent.com/login\">登陆</a>或<a href=\"https://cloud.tencent.com/register\">注册</a>腾讯云，您可以直接通过微信扫描命令行中的二维码进行授权登陆和注册。</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">$ sls deploy\n\nserverless ⚡ framework\nAction: &quot;deploy&quot; - Stage: &quot;dev&quot; - App: &quot;websiteApp&quot; - Instance: &quot;hexodemo&quot;\n\nregion:  ap-guangzhou\nwebsite: https://my-bucket-1258834142.cos-website.ap-guangzhou.myqcloud.com\n\n\n25s › hexodemo › Success</code></pre></div>\n<p>访问命令行输出的 website url，即可查看属于自己的 Serverless Hexo 站点。</p>\n<p><img src=\"https://uploader.shimo.im/f/P9h0rlMANRw2R5OA.png\" alt=\"image\"></p>\n<p>如果需要更新 hexo 站点中的文章，只需要在本地重新运行 <code class=\"language-text\">hexo g</code>  更新本地页面，再运行 <code class=\"language-text\">sls</code>  就可以直接更新到 Hexo 网站啦~</p>\n<ul>\n<li><a href=\"https://cloud.tencent.com/document/product/1154/40217\">具体可参考官方最佳实践文档</a></li>\n</ul>\n<hr>\n<div id='scf-deploy-iframe-or-md'></div>\n<hr>\n<blockquote>\n<p><strong>传送门：</strong></p>\n<ul>\n<li>GitHub: <a href=\"https://github.com/serverless/serverless/blob/master/README_CN.md\">github.com/serverless</a></li>\n<li>官网：<a href=\"https://serverless.com/\">serverless.com</a></li>\n</ul>\n</blockquote>\n<p>欢迎访问：<a href=\"https://serverlesscloud.cn/\">Serverless 中文网</a>，您可以在 <a href=\"https://serverlesscloud.cn/best-practice\">最佳实践</a> 里体验更多关于 Serverless 应用的开发！</p>","tableOfContents":"<ul>\n<li><a href=\"/best-practice/2019-12-4-Quickly-build-personal-blog/#%E5%AE%89%E8%A3%85%E4%B8%8E%E5%88%9D%E5%A7%8B%E5%8C%96\">安装与初始化</a></li>\n<li><a href=\"/best-practice/2019-12-4-Quickly-build-personal-blog/#%E9%85%8D%E7%BD%AE-yml-%E6%96%87%E4%BB%B6\">配置 yml 文件</a></li>\n<li><a href=\"/best-practice/2019-12-4-Quickly-build-personal-blog/#%E9%83%A8%E7%BD%B2\">部署</a></li>\n</ul>"},"previousBlog":{"id":"70178fa6-74b6-5606-9467-7c4fa830b240","frontmatter":{"thumbnail":"https://img.serverlesscloud.cn/20191226/1577353101878-vue.js.png","authors":["yugasun"],"categories":["best-practice"],"date":"2019-12-05T00:00:00.000Z","title":"基于 Serverless Component 全栈解决方案","description":"本文将介绍如何借助 Serverless Component 快速开发全栈 Web 应用。","authorslink":["https://github.com/yugasun"],"translators":null,"translatorslink":null,"tags":["Serverless","全栈应用"],"keywords":"Serverless Component,全栈 Web 应用,全栈解决方案","outdated":null},"wordCount":{"words":278,"sentences":57,"paragraphs":57},"fileAbsolutePath":"/opt/build/repo/content/best-practice/2019-12-5-Full-stack-solution-based-on-serverless-component.md","fields":{"slug":"/best-practice/2019-12-5-Full-stack-solution-based-on-serverless-component/","keywords":["serverless","spa","vue","vuejs","website","website 组件","云函数","serverless","express","tencent","res"]}},"nextBlog":{"id":"1a6791e1-0295-546d-ac0c-c19730a4bac2","frontmatter":{"thumbnail":"https://img.serverlesscloud.cn/2020115/1579074115778-1577347088399-website_fang.png","authors":["liujiang"],"categories":["best-practice"],"date":"2019-12-03T00:00:00.000Z","title":"通过 SCF Component 轻松构建 REST API，再也不用熬夜加班了","description":"本教程将分享如何通过 Serverless SCF Component 、云函数 SCF 及 API 网关组件，快速构建一个 REST API 并实现 GET/PUT 操作。","authorslink":["https://github.com/jiangliu5267"],"translators":null,"translatorslink":null,"tags":["Serverless","Restful"],"keywords":"SCF Component,REST API,构建 REST API,Serverless SCF Component","outdated":null},"wordCount":{"words":99,"sentences":25,"paragraphs":25},"fileAbsolutePath":"/opt/build/repo/content/best-practice/2019-12-3-Easy-to-build-REST-API.md","fields":{"slug":"/best-practice/2019-12-3-Easy-to-build-REST-API/","keywords":["go","python","serverless","spa","serverless","action","student","teacher","Serverless","event"]}}},"pageContext":{"isCreatedByStatefulCreatePages":false,"blogId":"74a25989-4611-5393-85ef-698f2c988635","previousBlogId":"70178fa6-74b6-5606-9467-7c4fa830b240","nextBlogId":"1a6791e1-0295-546d-ac0c-c19730a4bac2"}}}