nuxt初始化
This commit is contained in:
64
nuxt-web/scripts/generate-prerender-routes.mjs
Normal file
64
nuxt-web/scripts/generate-prerender-routes.mjs
Normal file
@@ -0,0 +1,64 @@
|
||||
import { promises as fs } from 'node:fs'
|
||||
import path from 'node:path'
|
||||
|
||||
const appRoot = process.cwd()
|
||||
const newsDir = path.join(appRoot, 'content', 'news')
|
||||
const casesDir = path.join(appRoot, 'content', 'cases')
|
||||
|
||||
const markdownFiles = async (dir) => {
|
||||
const entries = await fs.readdir(dir, { withFileTypes: true })
|
||||
return entries
|
||||
.filter((entry) => entry.isFile() && entry.name.endsWith('.md'))
|
||||
.map((entry) => entry.name.replace(/\.md$/, ''))
|
||||
.sort()
|
||||
}
|
||||
|
||||
const buildRoutes = async () => {
|
||||
const news = await markdownFiles(newsDir)
|
||||
const cases = await markdownFiles(casesDir)
|
||||
|
||||
return [
|
||||
'/',
|
||||
'/contact',
|
||||
'/company',
|
||||
'/company/culture',
|
||||
'/company/tech',
|
||||
'/company/joinus',
|
||||
'/products/ecommerce',
|
||||
'/products/ecommerce/freight-booking',
|
||||
'/products/ecommerce/net-cargo',
|
||||
'/products/ecommerce/bctp',
|
||||
'/products/ecommerce/obh',
|
||||
'/products/logistics',
|
||||
'/products/logistics/platform',
|
||||
'/products/logistics/cargo-agent',
|
||||
'/products/logistics/ship-agent',
|
||||
'/products/logistics/vehicle-transport',
|
||||
'/products/logistics/warehouse',
|
||||
'/products/port',
|
||||
'/products/port/cdi',
|
||||
'/products/port/cdi-bulk',
|
||||
'/products/port/cdi-container',
|
||||
'/products/port/cloud-yard',
|
||||
'/products/shipping',
|
||||
'/products/shipping/boat',
|
||||
'/products/shipping/company',
|
||||
'/solutions/inland-river-shipping',
|
||||
'/solutions/logistics-chain',
|
||||
'/solutions/port-supply-chain',
|
||||
'/solutions/supply-chain',
|
||||
'/services/chuandai',
|
||||
'/services/yunmatou',
|
||||
'/services/jining',
|
||||
'/services/dianshang',
|
||||
'/services/ilog',
|
||||
'/services/changzhan',
|
||||
'/news',
|
||||
'/cases',
|
||||
...news.map((slug) => `/news/${slug}`),
|
||||
...cases.map((slug) => `/cases/${slug}`)
|
||||
]
|
||||
}
|
||||
|
||||
const routes = await buildRoutes()
|
||||
process.stdout.write(`${JSON.stringify(routes, null, 2)}\n`)
|
||||
33
nuxt-web/scripts/init-nuxt-foundation.sh
Executable file
33
nuxt-web/scripts/init-nuxt-foundation.sh
Executable file
@@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
SEED_DIR=/tmp/agweb-nuxt-seed
|
||||
|
||||
echo "Creating Nuxt seed in $SEED_DIR"
|
||||
rm -rf "$SEED_DIR"
|
||||
CI=1 npx create-nuxt@latest "$SEED_DIR" --template minimal --packageManager npm --no-install --force --gitInit false || true
|
||||
|
||||
echo "Creating nuxt-web target directories"
|
||||
mkdir -p nuxt-web
|
||||
mkdir -p nuxt-web/pages nuxt-web/layouts nuxt-web/components nuxt-web/composables nuxt-web/public nuxt-web/assets/styles nuxt-web/scripts
|
||||
|
||||
echo "Copying baseline files into nuxt-web/"
|
||||
cp "$SEED_DIR/package.json" nuxt-web/
|
||||
cp "$SEED_DIR/tsconfig.json" nuxt-web/
|
||||
cp "$SEED_DIR/.gitignore" nuxt-web/
|
||||
cp "$SEED_DIR/nuxt.config.ts" nuxt-web/
|
||||
cp "$SEED_DIR/public/favicon.ico" nuxt-web/public/
|
||||
cp "$SEED_DIR/public/robots.txt" nuxt-web/public/
|
||||
|
||||
cat <<'EOF'
|
||||
Nuxt foundation seed copied into nuxt-web/.
|
||||
|
||||
Next manual steps:
|
||||
1. Review and rewrite nuxt-web/package.json for AgWeb dependencies.
|
||||
2. cd nuxt-web && npm install
|
||||
3. cd nuxt-web && npm install @nuxt/content @nuxt/image @nuxtjs/sitemap @nuxtjs/robots @vueuse/nuxt swiper @fancyapps/ui three
|
||||
4. Add AgWeb baseline files: app.vue, layouts/default.vue, pages/index.vue, content.config.ts, assets/styles/main.css
|
||||
5. Verify with:
|
||||
cd nuxt-web && npm run dev
|
||||
cd nuxt-web && npm run generate
|
||||
EOF
|
||||
52
nuxt-web/scripts/verify-generated-site.sh
Executable file
52
nuxt-web/scripts/verify-generated-site.sh
Executable file
@@ -0,0 +1,52 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
OUTPUT_DIR="${OUTPUT_DIR:-.output/public}"
|
||||
|
||||
if [[ ! -d "$OUTPUT_DIR" ]]; then
|
||||
echo "Missing generated output directory: $OUTPUT_DIR" >&2
|
||||
echo "Run 'npm run generate' inside nuxt-web first." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
check_file_contains() {
|
||||
local file="$1"
|
||||
local label="$2"
|
||||
local pattern="$3"
|
||||
|
||||
if [[ ! -f "$file" ]]; then
|
||||
echo "Missing $label file: $file" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! rg -q "$pattern" "$file"; then
|
||||
echo "Missing expected content in $label file: $file" >&2
|
||||
echo "Pattern: $pattern" >&2
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
index_file="$OUTPUT_DIR/index.html"
|
||||
news_index_file="$OUTPUT_DIR/news/index.html"
|
||||
cases_index_file="$OUTPUT_DIR/cases/index.html"
|
||||
|
||||
check_file_contains "$index_file" "homepage" "<(main|section|h1|h2)"
|
||||
check_file_contains "$news_index_file" "news index" "<(article|main|h1|h2|h3)"
|
||||
check_file_contains "$cases_index_file" "cases index" "<(article|main|h1|h2|h3)"
|
||||
|
||||
news_detail_file="$(find "$OUTPUT_DIR/news" -mindepth 2 -maxdepth 2 -type f -name 'index.html' | head -n 1)"
|
||||
if [[ -z "${news_detail_file:-}" ]]; then
|
||||
echo "Missing generated news detail pages under $OUTPUT_DIR/news" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
case_detail_file="$(find "$OUTPUT_DIR/cases" -mindepth 2 -maxdepth 2 -type f -name 'index.html' | head -n 1)"
|
||||
if [[ -z "${case_detail_file:-}" ]]; then
|
||||
echo "Missing generated case detail pages under $OUTPUT_DIR/cases" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
check_file_contains "$news_detail_file" "news detail" "<(article|main|p|h1|h2)"
|
||||
check_file_contains "$case_detail_file" "case detail" "<(article|main|p|h1|h2)"
|
||||
|
||||
echo "verify-generated-site.sh: PASS"
|
||||
Reference in New Issue
Block a user