logo 个人代码分享
Snippets

代码片段

常用的代码片段,点击右侧图标按钮直接复制使用。

Shell 部署脚本

服务器自动部署脚本

#!/usr/bin/env bash
set -euo pipefail

cd /www/wwwroot/hefei.space
git fetch origin main
git reset --hard origin/main

Nginx 静态站点配置

基本的 Nginx 静态站点配置

server {
    listen 80;
    server_name hefei.space www.hefei.space;
    root /www/wwwroot/hefei.space;
    index index.html;

    access_log /var/log/nginx/hefei.space.access.log;
    error_log /var/log/nginx/hefei.space.error.log;

    location ~* \.(css|js|png|jpg|jpeg|gif|ico|svg)$ {
        expires 7d;
        add_header Cache-Control "public, immutable";
    }

    location / {
        try_files $uri $uri/ /index.html;
    }
}

Git 远程仓库配置

添加远程仓库并推送代码

git init -b main
git remote add origin <CNB_PRIVATE_REPO_SSH_URL>
git add .
git commit -m "init static site"
git push -u origin main

Tailwind CSS 配置

shadcn/ui 风格的 Tailwind 配置

<script src="https://cdn.tailwindcss.com"></script>
<script>
  tailwindcss.config = {
    theme: {
      extend: {
        colors: {
          border: 'hsl(214.3 31.8% 91.4%)',
          background: 'hsl(0 0% 100%)',
          foreground: 'hsl(222.2 84% 4.9%)',
          primary: { DEFAULT: 'hsl(222.2 47.4% 11.2%)' },
          secondary: { DEFAULT: 'hsl(210 40% 96.1%)' },
          muted: { DEFAULT: 'hsl(210 40% 96.1%)' },
          accent: { DEFAULT: 'hsl(210 40% 96.1%)' },
          card: { DEFAULT: 'hsl(0 0% 100%)' },
        },
        borderRadius: {
          lg: '0.5rem',
          md: 'calc(0.5rem - 2px)',
          sm: 'calc(0.5rem - 4px)',
        },
      }
    }
  }
</script>