{"componentChunkName":"component---src-templates-best-practice-detail-tsx","path":"/best-practice/2019-12-13-Build-personal-album-website-with-serverless","result":{"data":{"currentBlog":{"id":"a5889900-617d-5aa4-ac8b-56b0aab7d572","frontmatter":{"thumbnail":"https://img.serverlesscloud.cn/202058/1588928638838-v2-b6f54fc4d2939af6f53a5e5592f9d19c_1200x500.jpg","authors":["alanoluo"],"categories":["best-practice"],"date":"2019-12-13T00:00:00.000Z","title":"用 Serverless 搭建个人静态相册网站","description":"通过 Serverless 组件，基于 ThumbsUp 快速搭建个人静态相册网站","authorslink":["https://github.com/alanoluo"],"translators":null,"translatorslink":null,"tags":["Wintersmith","ThumbsUp"],"keywords":"Serverless 组件,ThumbsUp相册,搭建个人静态相册网站,ThumbsUp搭建","outdated":null},"wordCount":{"words":107,"sentences":29,"paragraphs":29},"fileAbsolutePath":"/opt/build/repo/content/best-practice/2019-12-13-Build-personal-album-website-with-serverless.md","fields":{"slug":"/best-practice/2019-12-13-Build-personal-album-website-with-serverless/","keywords":["nodejs","serverless","website","website 组件","无服务器","serverless","website","Serverless","thumbsup","yml","photos","Framework","github"]},"html":"<p>日常生活中我们经常会拍摄一些视频、照片等，这些文件会占用比较多的存储空间。本文将介绍一种方法：利用 ThumbsUp 工具，结合 Serverless Framework 的 component 快速搭建个人相册网站，为存储空间减压。</p>\n<p><strong>工具介绍：</strong></p>\n<ul>\n<li><a href=\"https://github.com/serverless/serverless/blob/master/README_CN.md\">Serverless Framework</a>：Serverless Framework 是业界非常受欢迎的无服务器应用框架，开发者无需关心底层资源即可部署完整可用的 Serverless 应用架构。</li>\n<li><a href=\"https://thumbsup.github.io/\">ThumbsUp</a> 是一款让使用者方便检索及管理图片的看图软件，不但具有可以快速的操作图片切换预览的使用介面，而且对于图片的简单影像处理也有相当直接、便捷的操作方式。</li>\n</ul>\n<p>整个网站的搭建部署只需三步：安装与初始化 → 配置 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><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://exiftool.org/\">Exiftool</a></li>\n<li><a href=\"http://www.graphicsmagick.org/\">图形 Magick</a></li>\n</ul>\n<p>如未安装上述应用程序，可以参考<a href=\"https://thumbsup.github.io/docs/2-installation/npm/\">安装说明</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. 安装 ThumbsUp</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">$ npm install -g thumbsup</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\">$ mkdir photos\n$ thumbsup --input .\\photos\\ --output website</code></pre></div>\n<p>初始化成功后，可以看到项目目录结构：</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">.\n├── photos\n└── website\n    └── index.html</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\">touch serverless.yml</code></pre></div>\n<p>将以下内容写入上述的 yml 文件里：</p>\n<div\n              class=\"gatsby-code-button-container\"\n              data-toaster-id=\"70066732212904650000\"\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: mydemo # (必填) 该 website 组件创建的实例名称\n\ninputs:\n  src:\n    src: ./website # 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-bucket123121\n  protocol: https`, `70066732212904650000`)\"\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> mydemo <span class=\"token comment\"># (必填) 该 website 组件创建的实例名称</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> ./website <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>bucket123121\n  <span class=\"token key atrule\">protocol</span><span class=\"token punctuation\">:</span> https</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\n serverless ⚡ framework\nAction: &quot;deploy&quot; - Stage: &quot;dev&quot; - App: &quot;mydemo&quot; - Instance: &quot;mydemo&quot;\n\nregion:  ap-guangzhou\nwebsite: https://my-bucket123121-1256495918.cos-website.ap-guangzhou.myqcloud.com\n\n\n61s » mydemo » Success</code></pre></div>\n<p>访问命令行输出的 website url，即可查看即可查看使用 Serverless Framework 部署的照片墙网站。</p>\n<p><img src=\"https://img.serverlesscloud.cn/20191231/1577817573390-thumbsup.png\" alt=\"thumbsup\"></p>\n<blockquote>\n<p>注：如果希望更新网站中的照片或者视频等文件，可以在 photos 文件夹更新照片后，在本地重新运行 <code class=\"language-text\">thumbsup --input .\\photos\\ --output website</code> 更新本地页面，再运行 <code class=\"language-text\">sls</code> 即可更新网站。</p>\n</blockquote>\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-13-Build-personal-album-website-with-serverless/#%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-13-Build-personal-album-website-with-serverless/#%E9%85%8D%E7%BD%AE-yml-%E6%96%87%E4%BB%B6\">配置 yml 文件</a></li>\n<li><a href=\"/best-practice/2019-12-13-Build-personal-album-website-with-serverless/#%E9%83%A8%E7%BD%B2\">部署</a></li>\n</ul>"},"previousBlog":{"id":"c5d83479-32e7-5a99-acbe-5038f43cadc9","frontmatter":{"thumbnail":"https://img.serverlesscloud.cn/20191217/1576565954158-docsify.png","authors":["Aceyclee"],"categories":["best-practice"],"date":"2019-12-14T00:00:00.000Z","title":"三分钟入坑指北 🔜 Docsify + Serverless Framework 快速创建个人博客系统","description":"通过 Serverless Website 组件快速构建一个 Serverless docsify 个人博客系统。","authorslink":["https://www.zhihu.com/people/Aceyclee"],"translators":null,"translatorslink":null,"tags":["Wintersmith","Docsify"],"keywords":"Docsify,个人博客系统,Serverless Website,Serverless docsify","outdated":true},"wordCount":{"words":170,"sentences":39,"paragraphs":38},"fileAbsolutePath":"/opt/build/repo/content/best-practice/2019-12-14-docsify-with-serverless.md","fields":{"slug":"/best-practice/2019-12-14-docsify-with-serverless/","keywords":["nodejs","serverless","website","无服务器","docsify","serverless","Serverless","yml","html","Framework"]}},"nextBlog":{"id":"d2a60cba-0dfd-5c94-9848-dc29a897e81e","frontmatter":{"thumbnail":"https://img.serverlesscloud.cn/20191230/1577673977066-16ef85f25ee1af09.jpg","authors":["yugasun"],"categories":["best-practice"],"date":"2019-12-12T00:00:00.000Z","title":"如何开发自己的第一个 Serverless Component","description":"我们分享了不少基于 Component 的最佳实践案例，本文教你如何自己开发一个 Component！","authorslink":["https://yugasun.com"],"translators":null,"translatorslink":null,"tags":["Wintersmith","Component"],"keywords":"Serverless Component,最佳实践案例,开发Component,实践案例","outdated":null},"wordCount":{"words":399,"sentences":63,"paragraphs":63},"fileAbsolutePath":"/opt/build/repo/content/best-practice/2019-12-12-how-write-first-serverless-components.md","fields":{"slug":"/best-practice/2019-12-12-how-write-first-serverless-components/","keywords":["serverless","website","serverless","tencent","组件","Serverless","Component","cdn","npm"]}}},"pageContext":{"isCreatedByStatefulCreatePages":false,"blogId":"a5889900-617d-5aa4-ac8b-56b0aab7d572","previousBlogId":"c5d83479-32e7-5a99-acbe-5038f43cadc9","nextBlogId":"d2a60cba-0dfd-5c94-9848-dc29a897e81e"}}}