溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Hexo + Serverless Framework怎樣搭建你的個人博客

發布時間:2021-12-10 17:00:52 來源:億速云 閱讀:195 作者:柒染 欄目:云計算

Hexo + Serverless Framework怎樣搭建你的個人博客,相信很多沒有經驗的人對此束手無策,為此本文總結了問題出現的原因和解決方法,通過這篇文章希望你能解決這個問題。

很多人都想擁有自己的個人博客,還得看起來漂亮、酷酷的。下面里介紹兩款好用的神器搭建個人博客。

工具介紹

  • Serverless Framework:Serverless Framework 是業界非常受歡迎的無服務器應用框架,開發者無需關心底層資源即可部署完整可用的 Serverless 應用架構。

  • Hexo:Hexo 是一個快速、簡潔且高效的博客框架。Hexo 使用 Markdown(或其他渲染引擎)解析文章,在幾秒內,即可利用靚麗的主題生成靜態網頁。

使用 Serverless Framework 部署一個 Hexo 網站只需三步::安裝與初始化 → 配置 yml 文件 → 部署

安裝與初始化

簡單三步,即可通過 Serverless Website 組件快速構建一個 Serverless Hexo 站點。

首先確保系統包含以下環境:

  • Node.js (Node.js 版本需不低于 8.6,建議使用 Node.js 10.0 及以上版本)

  • Git

如未安裝上述應用程序,可以參考安裝說明。

1. 安裝 Serverless Framework

$ npm install -g serverless

2. 安裝 Hexo

$ npm install -g hexo-cli

3. 初始化項目

$ hexo init hexo   # 生成hexo目錄
$ cd hexo
$ npm install

初始化完成后,hexo 文件夾的目錄如下:

.
├── _config.yml
├── package.json
├── scaffolds
├── source
|   ├── _drafts
|   └── _posts
└── themes

4. 生成本地博客頁面

hexo g   # generate

可以通過 hexo g 命令生成靜態頁面,如果希望在本地查看效果,也可以運行下列命令,通過瀏覽器訪問 http://localhost:4000 查看頁面效果。

hexo s   # server

配置 yml 文件

項目目錄下,創建 serverless.yml 文件

cd.> serverless.yml

將以下內容寫入上述的 yml 文件里:

# serverless.yml

myWebsite:
  component: '@serverless/tencent-website'
  inputs:
    code:
      src: ./localhexo/public # Upload static files generated by HEXO
      index: index.html
      error: index.html
    region: ap-guangzhou
    bucketName: my-bucket-hexo

配置完成后,文件目錄如下:

.
├── .serverless
├── hexo
|   ├── public
|   ├── ...
|   ├── _config.yml
|   ├── ...
|   └── source
└── serverless.yml

部署

通過 sls 命令進行部署,并可以添加 --debug 參數查看部署過程中的信息

如您的賬號未登陸或注冊騰訊云,您可以直接通過微信掃描命令行中的二維碼進行授權登陸和注冊。

PS serverless --debug

  DEBUG ─ Resolving the template's static variables.
  DEBUG ─ Collecting components from the template.
  DEBUG ─ Downloading any NPM components found in the template.
  DEBUG ─ Analyzing the template's components dependencies.
  DEBUG ─ Creating the template's components graph.
  DEBUG ─ Syncing template state.
  DEBUG ─ Executing the template's components graph.
  DEBUG ─ Starting Website Component.

Please scan QR code login from wechat
Wait login...
Login successful for TencentCloud
  DEBUG ─ Preparing website Tencent COS bucket my-bucket-1250000000.
  DEBUG ─ Deploying "my-bucket-1250000000" bucket in the "ap-guangzhou" region.
  DEBUG ─ "my-bucket-1250000000" bucket was successfully deployed to the "ap-guangzhou" region.
  DEBUG ─ Setting ACL for "my-bucket-1250000000" bucket in the "ap-guangzhou" region.
  DEBUG ─ Ensuring no CORS are set for "my-bucket-1250000000" bucket in the "ap-guangzhou" region.
  DEBUG ─ Ensuring no Tags are set for "my-bucket-1250000000" bucket in the "ap-guangzhou" region.
  DEBUG ─ Configuring bucket my-bucket-1250000000 for website hosting.
  DEBUG ─ Uploading website files from D:\hexotina\localhexo\public to bucket my-bucket-1250000000.
  DEBUG ─ Starting upload to bucket my-bucket-1250000000 in region ap-guangzhou
  DEBUG ─ Uploading directory D:\hexotina\localhexo\public to bucket my-bucket-1250000000
  DEBUG ─ Website deployed successfully to URL: https://my-bucket-1250000000.cos-website.ap-guangzhou.myqcloud.com.

  myWebsite:
    url: https://my-bucket-1250000000.cos-website.ap-guangzhou.myqcloud.com
    env:

  13s ? myWebsite ? done

訪問命令行輸出的 website url,即可查看屬于自己的 Serverless Hexo 站點。

如果需要更新 hexo 站點中的文章,只需要在本地重新運行 hexo g 更新本地頁面,再運行 sls 就可以直接更新到 Hexo 網站啦

看完上述內容,你們掌握Hexo + Serverless Framework怎樣搭建你的個人博客的方法了嗎?如果還想學到更多技能或想了解更多相關內容,歡迎關注億速云行業資訊頻道,感謝各位的閱讀!

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女