Overview
This document describes how to use the Serverless Website component to quickly construct a serverless Hexo website.
Prerequisites
Node.js has been installed (starting from September 1, 2020, Serverless components no longer support Node.js versions below 10.0. Please upgrade if needed). If the applications above are not installed, please install them as instructed in the Hexo documentation. Directions
1. Install
Install Serverless Framework through npm:
$ npm install -g serverless
Install Hexo through npm:
$ npm install -g hexo-cli
After installing Hexo, please run the following command to make Hexo create required files in the specified folder:
$ hexo init hexo
$ cd hexo
$ npm install
After the specified folder is created, its structure is as follows:
.
├── _config.yml
├── package.json
├── scaffolds
├── source
| ├── _drafts
| └── _posts
└── themes
After the installation is completed, run the hexo g
command to generate a static webpage:
Note:
If you want to view the result locally, you can run the following command to access localhost:4000
and view the webpage in a browser:
Create a serverless.yml
file in the hexo
directory:
Configure the serverless.yml
file as follows:
component: website
name: hexodemo
app: websiteApp
stage: dev
inputs:
src:
src: ./public
index: index.html
region: ap-guangzhou
bucketName: my-bucket
protocol: https
After the configuration is completed, the directory structure is as follows:
.
├── .serverless
└── hexo
├── public
├── ...
├── serverless.yml
├── ...
└── source
3. Deploy
Deploy by running the sls deploy
command, and you can add the --debug
parameter to view the information during the deployment process:
$ sls deploy
serverless ⚡ framework
Action: "deploy" - Stage: "dev" - App: "websiteApp" - Instance: "hexodemo"
region: ap-guangzhou
website: https://my-bucket-1258834142.cos-website.ap-guangzhou.myqcloud.com
25s › hexodemo › Success
You can view your serverless Hexo website by accessing the website URL output by the command line.
Note:
If you want to update an article in your Hexo website, you need to run hexo g
locally again to generate a static webpage and run serverless
to update the webpage.
4. Remove
You can run the following command to remove the Hexo website:
$ sls remove --debug
DEBUG ─ Flushing template state and removing all components.
DEBUG ─ Starting Website Removal.
DEBUG ─ Removing Website bucket.
DEBUG ─ Removing files from the "my-bucket-1250000000" bucket.
DEBUG ─ Removing "my-bucket-1250000000" bucket from the "ap-guangzhou" region.
DEBUG ─ "my-bucket-1250000000" bucket was successfully removed from the "ap-guangzhou" region.
DEBUG ─ Finished Website Removal.
6s » myWebsite » done
Account configuration (optional)
Currently, you can scan a QR code to log in to the CLI by default. If you want to configure persistent environment variables/key information, you can also create a local .env
file:
Configure Tencent Cloud's SecretId
and SecretKey
information in the .env
file and save it:
TENCENT_SECRET_ID=123
TENCENT_SECRET_KEY=123
Note:
If you don't have a Tencent Cloud account yet, please sign up first. If you already have a Tencent Cloud account, you can get SecretId
and SecretKey
in API Key Management.
Was this page helpful?