Parcourir la source

Add Google Ads configuration and deployment script

bob il y a 5 mois
Parent
commit
54081ba97e
4 fichiers modifiés avec 94 ajouts et 1 suppressions
  1. 76 0
      deploy.sh
  2. 12 1
      nuxt.config.ts
  3. 5 0
      pages/index.vue
  4. 1 0
      public/ads.txt

+ 76 - 0
deploy.sh

@@ -0,0 +1,76 @@
+#!/bin/bash
+
+# 服务器配置信息
+SERVER_IP="47.253.147.187"
+SERVER_USER="root"
+SERVER_PASS="5H0FuZ:2s0q)Lx"
+REMOTE_PARENT_DIR="/www/wwwroot/ccdw-website" # 项目父目录
+
+# 颜色输出
+GREEN='\033[0;32m'
+NC='\033[0m'
+
+echo -e "${GREEN}开始部署流程...${NC}"
+
+# 1. 本地构建 (Static Site Generation)
+echo -e "${GREEN}正在执行本地构建 (npm run generate)...${NC}"
+npm run generate
+
+if [ $? -ne 0 ]; then
+    echo "构建失败,请检查错误信息"
+    exit 1
+fi
+
+# 2. 压缩构建产物
+echo -e "${GREEN}正在打包构建产物...${NC}"
+if [ -d ".output/public" ]; then
+    cd .output/public
+    # 打包所有文件到 release.tar.gz
+    tar -czf ../../release.tar.gz .
+    cd ../..
+    echo "打包完成: release.tar.gz"
+else
+    echo "错误: 未找到 .output/public 目录"
+    exit 1
+fi
+
+# 3. 上传文件 (使用 expect 自动输入密码)
+echo -e "${GREEN}正在上传文件到服务器...${NC}"
+/usr/bin/expect <<EOF
+set timeout 300
+spawn scp -o StrictHostKeyChecking=no release.tar.gz $SERVER_USER@$SERVER_IP:$REMOTE_PARENT_DIR/release.tar.gz
+expect {
+    "password:" { send "$SERVER_PASS\r" }
+    "yes/no" { send "yes\r"; exp_continue }
+}
+expect eof
+EOF
+
+# 4. 服务器端解压部署
+echo -e "${GREEN}正在服务器上解压并部署...${NC}"
+/usr/bin/expect <<EOF
+set timeout 30
+spawn ssh -o StrictHostKeyChecking=no $SERVER_USER@$SERVER_IP
+expect {
+    "password:" { send "$SERVER_PASS\r" }
+    "yes/no" { send "yes\r"; exp_continue }
+}
+expect "#"
+# 进入目录
+send "mkdir -p $REMOTE_PARENT_DIR/public\r"
+send "cd $REMOTE_PARENT_DIR\r"
+# 解压覆盖到 public 目录
+send "tar -xzf release.tar.gz -C public\r"
+# 清理压缩包
+send "rm release.tar.gz\r"
+# 修正权限 (假设 web 用户为 www,如果不是宝塔面板可能需要调整)
+send "chown -R www:www public\r"
+send "chmod -R 755 public\r"
+send "exit\r"
+expect eof
+EOF
+
+echo -e "${GREEN}部署完成! 请访问 https://ccdw.xyz${NC}"
+
+# 5. 清理本地压缩包
+rm release.tar.gz

+ 12 - 1
nuxt.config.ts

@@ -1,5 +1,16 @@
 // https://nuxt.com/docs/api/configuration/nuxt-config
 export default defineNuxtConfig({
   compatibilityDate: '2025-05-15',
-  devtools: { enabled: true }
+  devtools: { enabled: true },
+  app: {
+    head: {
+      script: [
+        {
+          src: 'https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-9165036986914822',
+          async: true,
+          crossorigin: 'anonymous'
+        }
+      ]
+    }
+  }
 })

+ 5 - 0
pages/index.vue

@@ -81,6 +81,11 @@
   
   <script setup>
   // 如果需要,可以在这里添加页面特定的逻辑
+  function head() {
+    return {
+        title: this.title,
+    }    
+  }
   </script>
   
 <style scoped>

+ 1 - 0
public/ads.txt

@@ -0,0 +1 @@
+google.com, pub-9165036986914822, DIRECT, f08c47fec0942fa0