1、在本地运行hexo博客正常后推送到GitHub
2、在主目录添加server.ts文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| #!/usr/bin/env -S deno run --allow-net --allow-read
import { serve } from "https://deno.land/[email protected]/http/server.ts"; import { serveDir } from "https://deno.land/[email protected]/http/file_server.ts";
const PORT = 8000;
// 静态文件服务 const handler = async (req: Request): Promise<Response> => { return serveDir(req, { fsRoot: "public", // 托管 public 目录中的文件 showDirListing: false, // 不显示目录列表 showDotfiles: false, // 不显示隐藏文件 }); };
console.log(`Server running at http://localhost:${PORT}`); serve(handler, { port: PORT });
|
3、登录deno部署博客,会提示失败
4、修改GitHub仓库.github/workflows 里面的deploy.yml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
| name: Deploy on: push: branches: main pull_request: branches: main
jobs: deploy: name: Deploy runs-on: ubuntu-latest
permissions: id-token: write contents: read
steps: - name: Checkout code uses: actions/checkout@v4
- name: Set up Node.js uses: actions/setup-node@v4 with: node-version: 22
- name: Cache Node.js modules uses: actions/cache@v3 with: path: ~/.npm key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} restore-keys: | ${{ runner.os }}-node-
- name: Install dependencies run: | npm install npm install -g hexo-cli
- name: Clean Hexo cache run: npx hexo clean
- name: Generate static files run: npx hexo generate --debug
- name: Verify static files run: ls -R public - name: Clone repository uses: actions/checkout@v4
- name: Install Deno uses: denoland/setup-deno@v2 with: deno-version: v2.x
- name: Install Node.js uses: actions/setup-node@v4 with: node-version: lts/*
- name: Install step run: "npm install"
- name: Build step run: "npx hexo generate"
- name: Upload to Deno Deploy uses: denoland/deployctl@v1 with: project: "blog-free" entrypoint: "server.ts" root: "" env: DENO_DEPLOY_TOKEN: ${{ secrets.DENO_DEPLOY_TOKEN }}
|