import { render } from '../dist-ssr/entry-server.js';
import fs from 'fs';
import path from 'path';
async function runAudit() {
const testUrls = [
'/daegu/suseong-gu/hwanggeum-dong/middle/math',
'/seoul/gangnam-gu/daechi-dong/high/korean',
'/busan/haeundae-gu/u-dong/middle/english',
'/gyeonggi/bundang-gu/sunae-dong/high/science'
];
console.log('===========================================================');
console.log('π ν°μ²PICK μ κ΅ 5λ§ κ° SSR & λ€μ΄λ² SEO μ’
ν© μ μ κ²μ¦ 리ν¬νΈ');
console.log('===========================================================');
for (const url of testUrls) {
console.log(`\nπ λμ URL: ${url}`);
const { html, head, routeName } = await render(url);
// 1. SSR μ€λ₯ μ λ° μμ κ²μ¬ (λΈλΌμ°μ μ μ© κ°μ²΄ λ―Έμ²λ¦¬ λ±)
const hasWindowError = html.includes('window is not defined') || html.includes('document is not defined');
console.log('1. SSR μμ μ±:', hasWindowError ? 'β μλ¬ λ°μ' : 'β
100% μ μ (λΈλΌμ°μ κ°μ²΄ μΆ©λ μμ)');
// 2. μλ§¨ν± νκ·Έ ꡬ쑰 κ²μ¬
const h1Count = (html.match(/
]/g) || []).length;
const h2Count = (html.match(/]/g) || []).length;
const h3Count = (html.match(/]/g) || []).length;
const hasMain = html.includes(']*>([^<]+)<\/title>/);
const descMatch = head.match(/name="description" content="([^"]+)"/);
const canonicalMatch = head.match(/rel="canonical" href="([^"]+)"/);
const hasJsonLd = head.includes('application/ld+json');
const ogTitle = head.includes('property="og:title"');
const ogImage = head.includes('property="og:image"');
console.log('3. λ€μ΄λ² κ²μμμ§(SEO) λ©ν μμ:');
console.log(` - Title: ${titleMatch ? titleMatch[1] : 'β μμ'}`);
console.log(` - Description: ${descMatch ? descMatch[1].slice(0, 45) + '...' : 'β μμ'}`);
console.log(` - Canonical URL: ${canonicalMatch ? canonicalMatch[1] : 'β μμ'}`);
console.log(` - Open Graph (og:title, og:image): ${ogTitle && ogImage ? 'β
μλΉ' : 'β λλ½'}`);
console.log(` - JSON-LD ꡬ쑰ν λ°μ΄ν°: ${hasJsonLd ? 'β
νμ¬ (Organization, Service, Breadcrumb)' : 'β λλ½'}`);
// 4. λ€μ΄λ² λ‘λ΄ μμ§μ± λ° ν
μ€νΈ νμ§
const imgWithoutAlt = (html.match(/
]*alt=)[^>]*>/g) || []).length;
const hasForbiddenWords = html.includes('μλ₯λ§μ ') || html.includes('μΈκ·Ό 곡립μ€νκ΅');
console.log('4. λ€μ΄λ² Yeti λ΄ μμ§μ± λ° νμ§:');
console.log(` - μ΄λ―Έμ§ alt μμ± λλ½: ${imgWithoutAlt}κ° (${imgWithoutAlt === 0 ? 'β
μ μ΄λ―Έμ§ alt μλΉ' : 'β alt λλ½ μμ'})`);
console.log(` - κΈμ§μ΄/κ³Όμ₯ λ¨μ΄ κ²μΆ: ${hasForbiddenWords ? 'β κΈμ§μ΄ λ°κ²¬' : 'β
0건 (μμ μ²μ )'}`);
}
// 5. μ¬μ΄νΈλ§΅ λ° robots.txt κ²μ¬
console.log('\n===========================================================');
console.log('5. μ¬μ΄νΈλ§΅ λ° ν¬λ‘€λ¬ μμ§ νκ²½ κ²μ¦:');
const robotsTxt = fs.readFileSync(path.resolve('public/robots.txt'), 'utf-8');
console.log(' - robots.txt Sitemap μ§μ :', robotsTxt.includes('Sitemap:') ? 'β
μ μ' : 'β λλ½');
console.log(' - robots.txt Allow /: ', robotsTxt.includes('Allow: /') ? 'β
μ 체 μμ§ νμ©' : 'β μ°¨λ¨λ¨');
const sitemapXml = fs.readFileSync(path.resolve('public/sitemap.xml'), 'utf-8');
console.log(' - sitemap.xml μΒ·λ λΆν μΈλ±μ€ ꡬ쑰:', sitemapXml.includes('