Fix scripts for Next.js + Payload CMS workflow
- new-project.sh: Use nextjs-payload-starter template, Next.js AI rules - convert-astro.sh: Complete rewrite to migrate Astro MDX to Payload CMS Lexical JSON - deploy.sh: Check for next.config instead of astro.config.mjs, use MONGODB_URL - preview.sh: Check for Next.js, default port 3002 - audit-seo.sh: Check .tsx pages in src/app, Next.js config All scripts now properly support Next.js + Payload CMS workflow.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
#===============================================================================
|
||||
# audit-seo.sh - SEO Audit สำหรับ Astro + Payload CMS project
|
||||
# audit-seo.sh - SEO Audit สำหรับ Next.js + Payload CMS project
|
||||
#
|
||||
# Usage: ./audit-seo.sh [project-path]
|
||||
#
|
||||
@@ -15,7 +15,7 @@
|
||||
#
|
||||
# Requirements:
|
||||
# - node.js
|
||||
# - npm (สำหรับ Astro CLI)
|
||||
# - npm
|
||||
# - curl
|
||||
#
|
||||
#===============================================================================
|
||||
@@ -57,7 +57,7 @@ print_usage() {
|
||||
cat << EOF
|
||||
Usage: $(basename "$0") [project-path]
|
||||
|
||||
SEO Audit สำหรับ Astro + Payload CMS project
|
||||
SEO Audit สำหรับ Next.js + Payload CMS project
|
||||
|
||||
Arguments:
|
||||
project-path ที่อยู่ project (default: current directory)
|
||||
@@ -106,23 +106,17 @@ check_project_structure() {
|
||||
|
||||
cd "$PROJECT_PATH"
|
||||
|
||||
if [ ! -f "astro.config.mjs" ]; then
|
||||
log_fail "ไม่พบ astro.config.mjs"
|
||||
if [ ! -f "next.config.ts" ] && [ ! -f "next.config.js" ]; then
|
||||
log_fail "ไม่พบ next.config.ts หรือ next.config.js"
|
||||
else
|
||||
log_success "พบ astro.config.mjs"
|
||||
log_success "พบ Next.js config"
|
||||
fi
|
||||
|
||||
if [ -d "src/pages" ]; then
|
||||
local page_count=$(find src/pages -name "*.astro" | wc -l)
|
||||
if [ -d "src/app" ]; then
|
||||
local page_count=$(find src/app -name "page.tsx" -o -name "page.ts" | wc -l)
|
||||
log_success "พบ $page_count pages"
|
||||
else
|
||||
log_fail "ไม่พบ src/pages"
|
||||
fi
|
||||
|
||||
if [ -d "src/layouts" ]; then
|
||||
log_success "พบ layouts directory"
|
||||
else
|
||||
log_warning "ไม่พบ layouts directory"
|
||||
log_fail "ไม่พบ src/app"
|
||||
fi
|
||||
|
||||
if [ -d "src/components" ]; then
|
||||
@@ -130,6 +124,12 @@ check_project_structure() {
|
||||
else
|
||||
log_warning "ไม่พบ components directory"
|
||||
fi
|
||||
|
||||
if [ -f "payload.config.ts" ]; then
|
||||
log_success "พบ Payload CMS config"
|
||||
else
|
||||
log_warning "ไม่พบ payload.config.ts"
|
||||
fi
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
@@ -149,7 +149,7 @@ check_meta_tags() {
|
||||
local pages_with_keywords=0
|
||||
local total_pages=0
|
||||
|
||||
for page in src/pages/**/*.astro src/pages/*.astro; do
|
||||
for page in src/app/**/page.tsx src/app/**/page.ts src/app/page.tsx src/app/page.ts; do
|
||||
if [ -f "$page" ]; then
|
||||
total_pages=$((total_pages + 1))
|
||||
|
||||
@@ -194,7 +194,7 @@ check_headings() {
|
||||
local pages_with_h2=0
|
||||
local total_pages=0
|
||||
|
||||
for page in src/pages/**/*.astro src/pages/*.astro; do
|
||||
for page in src/app/**/page.tsx src/app/**/page.ts src/app/page.tsx src/app/page.ts; do
|
||||
if [ -f "$page" ]; then
|
||||
total_pages=$((total_pages + 1))
|
||||
|
||||
@@ -230,10 +230,10 @@ check_sitemap() {
|
||||
|
||||
cd "$PROJECT_PATH"
|
||||
|
||||
if [ -f "astro.config.mjs" ] && grep -q 'sitemap' "astro.config.mjs"; then
|
||||
log_success "Astro sitemap integration ถูกตั้งค่า"
|
||||
if [ -f "next.config.ts" ] && grep -q 'sitemap' "next.config.ts"; then
|
||||
log_success "Sitemap integration ถูกตั้งค่า"
|
||||
else
|
||||
log_warning "ไม่พบ Astro sitemap integration"
|
||||
log_warning "ไม่พบ sitemap integration"
|
||||
fi
|
||||
|
||||
if [ -f "public/sitemap.xml" ]; then
|
||||
@@ -279,7 +279,7 @@ check_open_graph() {
|
||||
local pages_with_og=0
|
||||
local total_pages=0
|
||||
|
||||
for page in src/pages/**/*.astro src/pages/*.astro; do
|
||||
for page in src/app/**/page.tsx src/app/**/page.ts src/app/page.tsx src/app/page.ts; do
|
||||
if [ -f "$page" ]; then
|
||||
total_pages=$((total_pages + 1))
|
||||
|
||||
@@ -310,7 +310,7 @@ check_thai_language() {
|
||||
|
||||
cd "$PROJECT_PATH"
|
||||
|
||||
if grep -q 'lang="th"' "src/pages"/*.astro 2>/dev/null; then
|
||||
if grep -q 'lang="th"' "src/app"/*.tsx "src/app"/*.ts 2>/dev/null; then
|
||||
log_success "พบ lang='th' attribute"
|
||||
else
|
||||
log_warning "ไม่พบ lang='th' attribute"
|
||||
@@ -345,7 +345,7 @@ check_json_ld() {
|
||||
local pages_with_jsonld=0
|
||||
local total_pages=0
|
||||
|
||||
for page in src/pages/**/*.astro src/pages/*.astro; do
|
||||
for page in src/app/**/page.tsx src/app/**/page.ts src/app/page.tsx src/app/page.ts; do
|
||||
if [ -f "$page" ]; then
|
||||
total_pages=$((total_pages + 1))
|
||||
|
||||
@@ -422,7 +422,7 @@ show_summary() {
|
||||
main() {
|
||||
echo "=============================================="
|
||||
echo " SEO Audit Tool"
|
||||
echo " Astro + Payload CMS"
|
||||
echo " Next.js + Payload CMS"
|
||||
echo "=============================================="
|
||||
echo ""
|
||||
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
#!/usr/bin/env bash
|
||||
#===============================================================================
|
||||
# convert-astro.sh - แปลงเว็บเก่าเป็น Astro + Payload CMS
|
||||
# migrate-to-payload.sh - Migrate Astro content to Payload CMS with Lexical
|
||||
#
|
||||
# Usage: ./convert-astro.sh [source-path] [project-name]
|
||||
# Usage: ./migrate-to-payload.sh [source-path] [target-path]
|
||||
#
|
||||
# รองรับ:
|
||||
# - Astro เวอร์ชั่นเก่า
|
||||
# - Next.js
|
||||
# - Static HTML
|
||||
# This script migrates content from Astro MDX/Markdown to Payload CMS Lexical.
|
||||
# - Converts .md/.mdx files to Payload CMS Lexical JSON format
|
||||
# - Creates Payload collection entries
|
||||
# - Preserves frontmatter as collection fields
|
||||
#
|
||||
# Requirements:
|
||||
# - git
|
||||
# - node.js 20+
|
||||
# - npm
|
||||
#
|
||||
@@ -18,253 +17,277 @@
|
||||
|
||||
set -e
|
||||
|
||||
# Colors
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m'
|
||||
|
||||
# Default values
|
||||
SOURCE_PATH="${1:-}"
|
||||
PROJECT_NAME="${2:-}"
|
||||
TARGET_PATH="${2:-.}"
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Helper functions
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
log_info() {
|
||||
echo -e "${BLUE}[INFO]${NC} $1"
|
||||
}
|
||||
|
||||
log_success() {
|
||||
echo -e "${GREEN}[SUCCESS]${NC} $1"
|
||||
}
|
||||
|
||||
log_warning() {
|
||||
echo -e "${YELLOW}[WARNING]${NC} $1"
|
||||
}
|
||||
|
||||
log_error() {
|
||||
echo -e "${RED}[ERROR]${NC} $1"
|
||||
}
|
||||
log_info() { echo -e "${BLUE}[INFO]${NC} $1"; }
|
||||
log_success() { echo -e "${GREEN}[SUCCESS]${NC} $1"; }
|
||||
log_warning() { echo -e "${YELLOW}[WARNING]${NC} $1"; }
|
||||
log_error() { echo -e "${RED}[ERROR]${NC} $1"; }
|
||||
|
||||
print_usage() {
|
||||
cat << EOF
|
||||
Usage: $(basename "$0") [source-path] [project-name]
|
||||
Usage: $(basename "$0") [source-path] [target-path]
|
||||
|
||||
แปลงเว็บเก่าเป็น Astro + Payload CMS
|
||||
Migrate Astro content to Payload CMS with Lexical
|
||||
|
||||
Arguments:
|
||||
source-path ที่อยู่เว็บเก่า
|
||||
project-name ชื่อ project ใหม่
|
||||
|
||||
Supported Sources:
|
||||
- Astro เวอร์ชั่นเก่า
|
||||
- Next.js
|
||||
- Static HTML
|
||||
source-path Path to Astro project with content
|
||||
target-path Path to Next.js + Payload CMS project
|
||||
|
||||
Examples:
|
||||
$(basename "$0") /path/to/old-site my-new-site
|
||||
$(basename "$0") /path/to/astro-site /path/to/payload-site
|
||||
|
||||
EOF
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Detect source type
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
detect_source_type() {
|
||||
log_info "ตรวจสอบประเภทเว็บเก่า..."
|
||||
|
||||
if [ ! -d "$SOURCE_PATH" ]; then
|
||||
log_error "ไม่พบ source path: $SOURCE_PATH"
|
||||
exit 1
|
||||
fi
|
||||
detect_content_type() {
|
||||
log_info "Detecting content structure..."
|
||||
|
||||
cd "$SOURCE_PATH"
|
||||
|
||||
if [ -f "package.json" ]; then
|
||||
if grep -q '"next"' "package.json" 2>/dev/null; then
|
||||
SOURCE_TYPE="nextjs"
|
||||
log_success "ตรวจพบ: Next.js"
|
||||
elif grep -q '"astro"' "package.json" 2>/dev/null; then
|
||||
SOURCE_TYPE="astro"
|
||||
log_success "ตรวจพบ: Astro"
|
||||
elif grep -q '"remix"' "package.json" 2>/dev/null; then
|
||||
SOURCE_TYPE="remix"
|
||||
log_success "ตรวจพบ: Remix"
|
||||
elif grep -q '"nuxt"' "package.json" 2>/dev/null; then
|
||||
SOURCE_TYPE="nuxt"
|
||||
log_success "ตรวจพบ: Nuxt"
|
||||
if [ -d "src/content" ]; then
|
||||
CONTENT_DIR="src/content"
|
||||
elif [ -d "content" ]; then
|
||||
CONTENT_DIR="content"
|
||||
elif [ -d "src/pages" ]; then
|
||||
CONTENT_DIR="src/pages"
|
||||
else
|
||||
SOURCE_TYPE="unknown"
|
||||
log_warning "ไม่สามารถระบุประเภท - จะใช้เป็น static HTML"
|
||||
fi
|
||||
elif [ -f "index.html" ]; then
|
||||
SOURCE_TYPE="static"
|
||||
log_success "ตรวจพบ: Static HTML"
|
||||
else
|
||||
log_error "ไม่พบ package.json หรือ index.html"
|
||||
log_error "No content directory found"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
log_success "Content directory: $CONTENT_DIR"
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Backup source
|
||||
#-------------------------------------------------------------------------------
|
||||
backup_content() {
|
||||
log_info "Backing up content..."
|
||||
|
||||
backup_source() {
|
||||
log_info "สำรองข้อมูลเว็บเก่า..."
|
||||
|
||||
BACKUP_DIR="/tmp/backup-$(basename "$SOURCE_PATH")-$(date +%s)"
|
||||
BACKUP_DIR="/tmp/migration-backup-$(date +%s)"
|
||||
mkdir -p "$BACKUP_DIR"
|
||||
|
||||
cp -r "$SOURCE_PATH" "$BACKUP_DIR/"
|
||||
if [ -d "$SOURCE_PATH/$CONTENT_DIR" ]; then
|
||||
cp -r "$SOURCE_PATH/$CONTENT_DIR" "$BACKUP_DIR/"
|
||||
fi
|
||||
|
||||
log_success "สำรองข้อมูลที่: $BACKUP_DIR"
|
||||
log_success "Backup at: $BACKUP_DIR"
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Analyze structure
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
analyze_structure() {
|
||||
log_info "วิเคราะห์โครงสร้างเว็บเก่า..."
|
||||
analyze_content() {
|
||||
log_info "Analyzing content..."
|
||||
|
||||
cd "$SOURCE_PATH"
|
||||
|
||||
echo ""
|
||||
echo " โครงสร้างไฟล์:"
|
||||
find . -type f \( -name "*.astro" -o -name "*.tsx" -o -name "*.jsx" -o -name "*.vue" -o -name "*.html" -o -name "*.md" -o -name "*.mdx" \) 2>/dev/null | grep -v node_modules | head -30
|
||||
local md_count=$(find "$CONTENT_DIR" -type f \( -name "*.md" -o -name "*.mdx" \) 2>/dev/null | wc -l)
|
||||
local astro_count=$(find . -type f -name "*.astro" 2>/dev/null | grep -v node_modules | wc -l)
|
||||
|
||||
echo ""
|
||||
echo " Package.json scripts:"
|
||||
if [ -f "package.json" ]; then
|
||||
grep -A 10 '"scripts"' "package.json" 2>/dev/null | head -15
|
||||
fi
|
||||
echo " Content files: $md_count"
|
||||
echo " Astro components: $astro_count"
|
||||
echo ""
|
||||
|
||||
find "$CONTENT_DIR" -type f \( -name "*.md" -o -name "*.mdx" \) 2>/dev/null | head -20
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Create new Astro project
|
||||
#-------------------------------------------------------------------------------
|
||||
create_lexical_content() {
|
||||
log_info "Converting MDX to Payload CMS Lexical format..."
|
||||
|
||||
create_new_project() {
|
||||
log_info "สร้าง Astro project ใหม่..."
|
||||
cd "$SOURCE_PATH"
|
||||
|
||||
NEW_PROJECT_PATH="$(dirname "$SOURCE_PATH")/$PROJECT_NAME"
|
||||
local output_dir="$TARGET_PATH/src/content-migration"
|
||||
mkdir -p "$output_dir"
|
||||
|
||||
if [ -d "$NEW_PROJECT_PATH" ]; then
|
||||
log_warning "Project มีอยู่แล้ว: $NEW_PROJECT_PATH"
|
||||
read -p "ลบและสร้างใหม่? (y/n): " -n 1 -r
|
||||
echo
|
||||
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
||||
rm -rf "$NEW_PROJECT_PATH"
|
||||
find "$CONTENT_DIR" -type f \( -name "*.md" -o -name "*.mdx" \) 2>/dev/null | while read -r file; do
|
||||
local relative_path="${file#$SOURCE_PATH/$CONTENT_DIR/}"
|
||||
local filename=$(basename "$file" .mdx .md | sed 's/\.mdx$//' | sed 's/\.md$//')
|
||||
local slug=$(echo "$filename" | tr '[:upper:]' '[:lower:]' | tr ' ' '-')
|
||||
|
||||
local frontmatter=""
|
||||
local content=""
|
||||
|
||||
if grep -q "^---" "$file" 2>/dev/null; then
|
||||
frontmatter=$(sed -n '/^---/,/^---/p' "$file" | head -n -1 | tail -n +2)
|
||||
content=$(awk '/^---/{found=1; next} found' "$file")
|
||||
else
|
||||
log_info "ใช้ existing project"
|
||||
return 0
|
||||
fi
|
||||
content=$(cat "$file")
|
||||
fi
|
||||
|
||||
mkdir -p "$NEW_PROJECT_PATH"
|
||||
cd "$NEW_PROJECT_PATH"
|
||||
local title=$(echo "$frontmatter" | grep -i "^title:" | cut -d':' -f2- | tr -d ' "' | head -1)
|
||||
local date=$(echo "$frontmatter" | grep -i "^date:" | cut -d':' -f2- | tr -d ' "' | head -1)
|
||||
local description=$(echo "$frontmatter" | grep -i "^description:" | cut -d':' -f2- | tr -d ' "' | head -1)
|
||||
local author=$(echo "$frontmatter" | grep -i "^author:" | cut -d':' -f2- | tr -d ' "' | head -1)
|
||||
local image=$(echo "$frontmatter" | grep -i "^image:" | cut -d':' -f2- | tr -d ' "' | head -1)
|
||||
local tags=$(echo "$frontmatter" | grep -i "^tags:" | cut -d':' -f2- | tr -d '[]"' | head -1)
|
||||
|
||||
# Create Astro project
|
||||
npm create astro@latest . -- --template minimal --no-install --no-git --typescript strict << EOF
|
||||
y
|
||||
EOF
|
||||
title=${title:-$filename}
|
||||
date=${date:-$(date +%Y-%m-%d)}
|
||||
|
||||
log_success "สร้าง Astro project เสร็จสมบูรณ์: $NEW_PROJECT_PATH"
|
||||
cat > "$output_dir/${slug}.json" << JSONEOF
|
||||
{
|
||||
"title": "$title",
|
||||
"slug": "$slug",
|
||||
"createdAt": "$date",
|
||||
"updatedAt": "$(date +%Y-%m-%d)",
|
||||
"meta": {
|
||||
"title": "$title",
|
||||
"description": "$description"
|
||||
},
|
||||
"author": "$author",
|
||||
"heroImage": "$image",
|
||||
"tags": ["$tags"],
|
||||
"content": {
|
||||
"root": {
|
||||
"type": "root",
|
||||
"format": "",
|
||||
"indent": 0,
|
||||
"version": 1,
|
||||
"children": [
|
||||
{
|
||||
"type": "paragraph",
|
||||
"version": 1,
|
||||
"children": [
|
||||
{
|
||||
"type": "text",
|
||||
"version": 1,
|
||||
"text": "$content",
|
||||
"mode": "tokenized",
|
||||
"style": ""
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
JSONEOF
|
||||
|
||||
echo " Converted: $filename → $slug.json"
|
||||
done
|
||||
|
||||
log_success "Conversion complete: $output_dir/"
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Copy content
|
||||
#-------------------------------------------------------------------------------
|
||||
create_payload_import_script() {
|
||||
log_info "Creating Payload import script..."
|
||||
|
||||
copy_content() {
|
||||
log_info "คัดลอก content..."
|
||||
local output_dir="$TARGET_PATH/scripts"
|
||||
mkdir -p "$output_dir"
|
||||
|
||||
cd "$SOURCE_PATH"
|
||||
cat > "$output_dir/import-content.ts" << 'TSEOF'
|
||||
import { payload } from '../src/lib/payload'
|
||||
import { promises as fs } from 'fs'
|
||||
import path from 'path'
|
||||
|
||||
# Copy markdown content
|
||||
if [ -d "src/content" ]; then
|
||||
mkdir -p "$NEW_PROJECT_PATH/src/content/migration"
|
||||
cp -r src/content/* "$NEW_PROJECT_PATH/src/content/migration/"
|
||||
log_success "คัดลอก content จาก src/content"
|
||||
elif [ -d "content" ]; then
|
||||
mkdir -p "$NEW_PROJECT_PATH/src/content/migration"
|
||||
cp -r content/* "$NEW_PROJECT_PATH/src/content/migration/"
|
||||
log_success "คัดลอก content จาก content"
|
||||
fi
|
||||
async function importContent() {
|
||||
const contentDir = path.join(process.cwd(), 'src/content-migration')
|
||||
|
||||
# Copy public assets
|
||||
if [ -d "public" ]; then
|
||||
cp -r public/* "$NEW_PROJECT_PATH/public/" 2>/dev/null || true
|
||||
log_success "คัดลอก public assets"
|
||||
fi
|
||||
try {
|
||||
const files = await fs.readdir(contentDir)
|
||||
const jsonFiles = files.filter(f => f.endsWith('.json'))
|
||||
|
||||
# Copy pages (needs manual conversion)
|
||||
if [ -d "src/pages" ] || [ -d "pages" ]; then
|
||||
mkdir -p "$NEW_PROJECT_PATH/src/pages/legacy"
|
||||
log_info "Pages ต้องการ manual conversion - เก็บไว้ที่ legacy/"
|
||||
fi
|
||||
for (const file of jsonFiles) {
|
||||
const filePath = path.join(contentDir, file)
|
||||
const content = JSON.parse(await fs.readFile(filePath, 'utf-8'))
|
||||
|
||||
await payload.create({
|
||||
collection: 'posts',
|
||||
data: {
|
||||
title: content.title,
|
||||
slug: content.slug,
|
||||
createdAt: content.createdAt,
|
||||
updatedAt: content.updatedAt,
|
||||
meta: content.meta,
|
||||
author: content.author,
|
||||
heroImage: content.heroImage,
|
||||
tags: content.tags,
|
||||
content: content.content,
|
||||
_status: 'published',
|
||||
},
|
||||
})
|
||||
|
||||
console.log(`Imported: ${content.title}`)
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Create content migration report
|
||||
#-------------------------------------------------------------------------------
|
||||
console.log(`\nSuccessfully imported ${jsonFiles.length} posts`)
|
||||
} catch (error) {
|
||||
console.error('Import failed:', error)
|
||||
process.exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
importContent()
|
||||
TSEOF
|
||||
|
||||
log_success "Created: $output_dir/import-content.ts"
|
||||
}
|
||||
|
||||
create_migration_report() {
|
||||
log_info "สร้าง migration report..."
|
||||
log_info "Creating migration report..."
|
||||
|
||||
cd "$SOURCE_PATH"
|
||||
|
||||
local page_count=$(find . -type f \( -name "*.astro" -o -name "*.tsx" -o -name "*.jsx" -o -name "*.html" -o -name "*.md" -o -name "*.mdx" \) 2>/dev/null | grep -v node_modules | wc -l)
|
||||
local page_count=$(find "$CONTENT_DIR" -type f \( -name "*.md" -o -name "*.mdx" \) 2>/dev/null | wc -l)
|
||||
|
||||
cat > "$NEW_PROJECT_PATH/MIGRATION_REPORT.md" << EOF
|
||||
# Migration Report
|
||||
cat > "$TARGET_PATH/MIGRATION_REPORT.md" << EOF
|
||||
# Migration Report: Astro → Payload CMS
|
||||
|
||||
## Source Information
|
||||
- **Type:** $SOURCE_TYPE
|
||||
## Source
|
||||
- **Type:** Astro
|
||||
- **Path:** $SOURCE_PATH
|
||||
- **Backup:** $BACKUP_DIR
|
||||
- **Date:** $(date)
|
||||
|
||||
## Content Statistics
|
||||
- **Total Pages:** $page_count
|
||||
## Statistics
|
||||
- **Total Posts:** $page_count
|
||||
|
||||
## Files to Migrate
|
||||
## Content Migration
|
||||
|
||||
### Pages (Manual Conversion Required)
|
||||
Content has been converted to Payload CMS Lexical JSON format in:
|
||||
\`\`\`
|
||||
src/content-migration/
|
||||
\`\`\`
|
||||
|
||||
## Next Steps
|
||||
|
||||
1. **Review converted content:**
|
||||
\`\`\`bash
|
||||
ls src/content-migration/
|
||||
\`\`\`
|
||||
|
||||
2. **Configure Payload collection:**
|
||||
Make sure you have a 'posts' collection in \`src/collections/Posts.ts\`
|
||||
|
||||
3. **Import content to Payload:**
|
||||
\`\`\`bash
|
||||
npx tsx scripts/import-content.ts
|
||||
\`\`\`
|
||||
|
||||
4. **Verify in admin:**
|
||||
- Go to http://localhost:3002/admin
|
||||
- Navigate to Posts collection
|
||||
- Verify content and rich text editor (Lexical)
|
||||
|
||||
## Notes
|
||||
|
||||
- MDX/Markdown content is converted to Lexical JSON format
|
||||
- Frontmatter fields (title, date, description) are mapped to collection fields
|
||||
- Complex MDX components need manual conversion in Payload admin
|
||||
- Images need to be re-uploaded to Payload Media
|
||||
EOF
|
||||
|
||||
# List pages that need conversion
|
||||
if [ -d "src/pages" ]; then
|
||||
find src/pages -type f \( -name "*.astro" -o -name "*.tsx" -o -name "*.jsx" \) 2>/dev/null >> "$NEW_PROJECT_PATH/MIGRATION_REPORT.md"
|
||||
elif [ -d "pages" ]; then
|
||||
find pages -type f \( -name "*.html" -o -name "*.jsx" -o -name "*.tsx" \) 2>/dev/null >> "$NEW_PROJECT_PATH/MIGRATION_REPORT.md"
|
||||
fi
|
||||
|
||||
cat >> "$NEW_PROJECT_PATH/MIGRATION_REPORT.md" << EOF
|
||||
|
||||
### Content (Auto-migrated)
|
||||
EOF
|
||||
|
||||
if [ -d "$NEW_PROJECT_PATH/src/content/migration" ]; then
|
||||
find "$NEW_PROJECT_PATH/src/content/migration" -type f -name "*.md" -o -name "*.mdx" 2>/dev/null >> "$NEW_PROJECT_PATH/MIGRATION_REPORT.md"
|
||||
fi
|
||||
|
||||
log_success "สร้าง migration report: $NEW_PROJECT_PATH/MIGRATION_REPORT.md"
|
||||
log_success "Migration report: $TARGET_PATH/MIGRATION_REPORT.md"
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Main
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
main() {
|
||||
echo "=============================================="
|
||||
echo " Website Migration Tool"
|
||||
echo " แปลงเว็บเก่าเป็น Astro + Payload CMS"
|
||||
echo " Astro → Payload CMS Migration Tool"
|
||||
echo " Convert MDX/MD to Payload CMS with Lexical"
|
||||
echo "=============================================="
|
||||
echo ""
|
||||
|
||||
@@ -276,28 +299,38 @@ main() {
|
||||
if [ -z "$SOURCE_PATH" ]; then
|
||||
print_usage
|
||||
echo ""
|
||||
log_error "กรุณาระบุ source path"
|
||||
log_error "Please specify source path"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
detect_source_type
|
||||
backup_source
|
||||
analyze_structure
|
||||
create_new_project
|
||||
copy_content
|
||||
if [ ! -d "$SOURCE_PATH" ]; then
|
||||
log_error "Source path not found: $SOURCE_PATH"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ ! -d "$TARGET_PATH" ]; then
|
||||
log_error "Target path not found: $TARGET_PATH"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
detect_content_type
|
||||
backup_content
|
||||
analyze_content
|
||||
create_lexical_content
|
||||
create_payload_import_script
|
||||
create_migration_report
|
||||
|
||||
echo ""
|
||||
echo "=============================================="
|
||||
log_success "Migration เริ่มต้นเสร็จสมบูรณ์!"
|
||||
log_success "Migration preparation complete!"
|
||||
echo "=============================================="
|
||||
echo ""
|
||||
echo "ขั้นตอนถัดไป:"
|
||||
echo " 1. cd $NEW_PROJECT_PATH"
|
||||
echo " 2. npm install"
|
||||
echo " 3. ดู MIGRATION_REPORT.md"
|
||||
echo " 4. ปรับ content และ pages ตาม report"
|
||||
echo " 5. npm run dev"
|
||||
echo "Next steps:"
|
||||
echo " 1. cd $TARGET_PATH"
|
||||
echo " 2. Review converted content in src/content-migration/"
|
||||
echo " 3. Run: npm run dev"
|
||||
echo " 4. Import: npx tsx scripts/import-content.ts"
|
||||
echo " 5. Verify in Payload admin (http://localhost:3002/admin)"
|
||||
echo ""
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
#===============================================================================
|
||||
# deploy.sh - Deploy Astro + Payload CMS ไปยัง Easypanel
|
||||
# deploy.sh - Deploy Next.js + Payload CMS ไปยัง Easypanel
|
||||
#
|
||||
# Usage: ./deploy.sh [project-path] [server] [domain]
|
||||
#
|
||||
@@ -49,7 +49,7 @@ print_usage() {
|
||||
cat << EOF
|
||||
Usage: $(basename "$0") [project-path] [server] [domain]
|
||||
|
||||
Deploy Astro + Payload CMS ไปยัง Easypanel
|
||||
Deploy Next.js + Payload CMS ไปยัง Easypanel
|
||||
|
||||
Arguments:
|
||||
project-path ที่อยู่ project (default: current directory)
|
||||
@@ -87,8 +87,8 @@ check_requirements() {
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ ! -f "astro.config.mjs" ]; then
|
||||
log_error "ไม่พบ astro.config.mjs"
|
||||
if [ ! -f "next.config.ts" ] && [ ! -f "next.config.js" ]; then
|
||||
log_error "ไม่พบ next.config.ts หรือ next.config.js"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@@ -180,7 +180,7 @@ show_deploy_instructions() {
|
||||
echo " 4. ใส่ git repo URL"
|
||||
echo " 5. ตั้งค่า environment variables:"
|
||||
echo " - PAYLOAD_SECRET"
|
||||
echo " - DATABASE_URL"
|
||||
echo " - MONGODB_URL"
|
||||
echo " 6. ตั้งค่า domain: $DOMAIN"
|
||||
echo " 7. Deploy"
|
||||
echo ""
|
||||
@@ -209,14 +209,14 @@ create_deploy_config() {
|
||||
"domain": "$DOMAIN",
|
||||
"build": {
|
||||
"command": "npm run build",
|
||||
"output": "dist"
|
||||
"output": ".next"
|
||||
},
|
||||
"environment": {
|
||||
"NODE_ENV": "production"
|
||||
},
|
||||
"required_env": [
|
||||
"PAYLOAD_SECRET",
|
||||
"DATABASE_URL"
|
||||
"MONGODB_URL"
|
||||
]
|
||||
}
|
||||
EOF
|
||||
@@ -231,7 +231,7 @@ EOF
|
||||
main() {
|
||||
echo "=============================================="
|
||||
echo " Deploy Tool"
|
||||
echo " Astro + Payload CMS -> Easypanel"
|
||||
echo " Next.js + Payload CMS -> Easypanel"
|
||||
echo "=============================================="
|
||||
echo ""
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
#!/usr/bin/env bash
|
||||
#===============================================================================
|
||||
# new-project.sh - สร้าง Astro + Payload CMS project ใหม่จาก Astro Starter Template
|
||||
# new-project.sh - สร้าง Next.js + Payload CMS project ใหม่จาก Template
|
||||
#
|
||||
# Usage: ./new-project.sh [project-name] [project-path]
|
||||
#
|
||||
# สร้าง Astro project ใหม่โดย:
|
||||
# 1. คัดลอก astro-starter template
|
||||
# สร้าง Next.js + Payload CMS project ใหม่โดย:
|
||||
# 1. คัดลอก nextjs-payload-starter template
|
||||
# 2. ติดตั้ง dependencies
|
||||
# 3. ตั้งค่า environment
|
||||
#
|
||||
@@ -31,7 +31,7 @@ PROJECT_PATH="${2:-.}"
|
||||
|
||||
# Get skill directory
|
||||
SKILL_DIR="$(dirname "$(dirname "$(readlink -f "$0")")")"
|
||||
TEMPLATE_DIR="$SKILL_DIR/templates/astro-starter"
|
||||
TEMPLATE_DIR="$SKILL_DIR/templates/nextjs-payload-starter"
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Helper functions
|
||||
@@ -57,7 +57,7 @@ print_usage() {
|
||||
cat << EOF
|
||||
Usage: $(basename "$0") [project-name] [project-path]
|
||||
|
||||
สร้าง Astro + Payload CMS project ใหม่จาก Astro Starter Template
|
||||
สร้าง Next.js + Payload CMS project ใหม่จาก Template
|
||||
|
||||
Arguments:
|
||||
project-name ชื่อ project (optional)
|
||||
@@ -103,7 +103,7 @@ check_requirements() {
|
||||
|
||||
# Check template exists
|
||||
if [ ! -d "$TEMPLATE_DIR" ]; then
|
||||
log_error "ไม่พบ Astro Starter Template: $TEMPLATE_DIR"
|
||||
log_error "ไม่พบ Next.js Payload Starter Template: $TEMPLATE_DIR"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@@ -143,7 +143,7 @@ setup_directory() {
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
copy_template() {
|
||||
log_info "คัดลอก Astro Starter Template..."
|
||||
log_info "คัดลอก Next.js Payload Starter Template..."
|
||||
|
||||
# Copy all template files
|
||||
cp -r "$TEMPLATE_DIR/"* "$PROJECT_PATH/"
|
||||
@@ -237,9 +237,9 @@ create_ai_rules() {
|
||||
|
||||
## Tech Stack Overview
|
||||
|
||||
- **Frontend:** Astro เวอร์ชั่นล่าสุด + TypeScript
|
||||
- **Frontend:** Next.js App Router + TypeScript
|
||||
- **Backend/CMS:** Payload CMS 3.0
|
||||
- **Database:** PostgreSQL (via Payload)
|
||||
- **Database:** MongoDB (via mongooseAdapter)
|
||||
- **Styling:** Tailwind CSS v4
|
||||
- **Authentication:** Payload built-in auth with role-based access
|
||||
- **Image Handling:** Payload Media collection
|
||||
@@ -247,9 +247,9 @@ create_ai_rules() {
|
||||
## File Organization
|
||||
|
||||
- **Collections:** Define Payload collections in `src/collections/`
|
||||
- **Pages:** Use Astro file-based routing in `src/pages/`
|
||||
- **Pages:** Next.js App Router in `src/app/`
|
||||
- **Components:** Reusable components in `src/components/`
|
||||
- **Styles:** Global styles in `src/styles/`
|
||||
- **Styles:** Global styles in `src/app/globals.css`
|
||||
|
||||
## Never Modify These Files
|
||||
|
||||
@@ -279,7 +279,7 @@ init_git() {
|
||||
if [ ! -d ".git" ]; then
|
||||
git init
|
||||
git add .
|
||||
git commit -m "Initial commit: Astro + Payload CMS starter"
|
||||
git commit -m "Initial commit: Next.js + Payload CMS starter"
|
||||
log_success "เริ่มต้น git เสร็จสมบูรณ์"
|
||||
else
|
||||
log_info "git repo มีอยู่แล้ว"
|
||||
@@ -303,8 +303,8 @@ show_structure() {
|
||||
|
||||
main() {
|
||||
echo "=============================================="
|
||||
echo " Astro + Payload CMS Project Creator"
|
||||
echo " Using Astro Starter Template"
|
||||
echo " Next.js + Payload CMS Project Creator"
|
||||
echo " Using Next.js Payload Starter"
|
||||
echo "=============================================="
|
||||
echo ""
|
||||
|
||||
@@ -327,16 +327,15 @@ main() {
|
||||
|
||||
echo ""
|
||||
echo "=============================================="
|
||||
log_success "สร้าง Astro + Payload CMS project เสร็จสมบูรณ์!"
|
||||
log_success "สร้าง Next.js + Payload CMS project เสร็จสมบูรณ์!"
|
||||
echo "=============================================="
|
||||
echo ""
|
||||
echo "ขั้นตอนถัดไป:"
|
||||
echo " 1. cd $PROJECT_PATH"
|
||||
echo " 2. แก้ไข .env (DATABASE_URL, PAYLOAD_SECRET)"
|
||||
echo " 3. npm run db:push (สร้าง database tables)"
|
||||
echo " 4. npm run generate (สร้าง Payload types)"
|
||||
echo " 5. npm run dev"
|
||||
echo " 6. เปิด http://localhost:4321/admin สำหรับ Payload admin"
|
||||
echo " 2. แก้ไข .env (MONGODB_URL, PAYLOAD_SECRET)"
|
||||
echo " 3. npm install"
|
||||
echo " 4. npm run dev"
|
||||
echo " 5. เปิด http://localhost:3002/admin สำหรับ Payload admin"
|
||||
echo ""
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ NC='\033[0m'
|
||||
|
||||
# Default values
|
||||
PROJECT_PATH="${1:-.}"
|
||||
PORT="${2:-4321}"
|
||||
PORT="${2:-3002}"
|
||||
HOST="0.0.0.0"
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
@@ -64,13 +64,13 @@ check_project() {
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check for Astro or Emdash
|
||||
if ! grep -q "astro" "$PROJECT_PATH/package.json"; then
|
||||
log_error "ไม่ใช่ Astro project"
|
||||
# Check for Next.js
|
||||
if ! grep -q '"next"' "$PROJECT_PATH/package.json"; then
|
||||
log_error "ไม่ใช่ Next.js project"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
log_success "พบ Astro project"
|
||||
log_success "พบ Next.js project"
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
@@ -159,7 +159,7 @@ check_port() {
|
||||
|
||||
main() {
|
||||
echo "=============================================="
|
||||
echo " Astro Preview Server"
|
||||
echo " Next.js Preview Server"
|
||||
echo "=============================================="
|
||||
echo ""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user