애드센스 거절 막는 초안 페이지 noindex 자동화 (Astro)
검수 전 초안 페이지를 noindex·사이트맵 제외·광고 미노출로 자동 처리하고, 시맨틱 HTML 뼈대까지 잡는 Astro 설정을 복붙으로 정리했습니다.
최종 수정 2026년 11월 29일 · 예상 소요 약 30분
- 월 유지비
- 0원
- PC 상시 가동
- 불필요
- 필수 계정
- Cloudflare
버튼을 누르면 AI 지시문이 복사됩니다. Claude Code·Cursor 같은 AI 코딩 도구의 채팅창에 붙여넣으세요.
시작하기 전에 필요한 것
- Astro 문서가 요구하는 Node.js(2026-11 기준 v22.23.4 이상)가 설치된 PC
- Astro 정적 사이트 프로젝트 (npm create astro 로 만든 기본 프로젝트면 충분)
- 배포 환경에서 환경변수를 지정할 수 있는 호스팅 (Cloudflare 등)
① 한눈에 요약
애드센스 게시자 정책은 “내용이 없거나 가치가 낮은 화면, 제작 중인 화면”에 광고를 게재하지 못하게 합니다(Google 게시자 정책, 2026-11-29 확인). 그래서 덜 만든 페이지는 광고를 빼고 검색에도 내보내지 않는 편이 안전합니다. 이 레시피는 사람이 신경 쓰지 않아도 아래 네 가지가 자동으로 지켜지게 만듭니다.
- 검수가 끝나지 않은 페이지는
noindex, follow메타 태그를 단다. - 같은 페이지는 사이트맵(
sitemap-index.xml)에서도 뺀다. - 같은 페이지에는 광고 슬롯을 렌더링하지 않는다.
- 미리보기·개발 빌드는 사이트 전체를
noindex, nofollow로 둔다.
판정 기준은 마크다운 frontmatter 의 reviewStatus 한 줄입니다. verified 로 바꾸는 순간 색인 대상·사이트맵 대상·광고 대상이 함께 켜집니다.
이 설정이 애드센스 승인을 보장하지는 않습니다. 미완성 페이지가 검색에 노출되는 위험을 줄이는 안전장치일 뿐이며, 승인 여부는 콘텐츠 품질과 정책 준수에 달려 있습니다.
② 준비물
- Astro 5 이상 정적 프로젝트와
@astrojs/sitemap - 환경변수 2개
SITE_ENV:production일 때만 색인을 허용한다.PUBLIC_SITE_URL: canonical, 사이트맵, robots.txt 에 쓰는 사이트 주소의 단일 출처. 예시는https://example.com.
- 콘텐츠 컬렉션(
src/content/recipes/*.md) 각 글의 frontmatter 에reviewStatus: draft | verified
npm install @astrojs/sitemap
③ 폴더 구조
.
├─ astro.config.mjs # 사이트맵 필터 (초안 경로 제외)
├─ src/
│ ├─ content.config.ts # recipes 컬렉션 (glob 로더)
│ ├─ content/recipes/*.md # reviewStatus 가 들어 있는 글
│ ├─ lib/
│ │ ├─ site.ts # 환경변수 단일 출처
│ │ └─ indexing.ts # frontmatter 원문 -> 색인 가능 여부
│ ├─ layouts/BaseLayout.astro # robots 메타 + 시맨틱 뼈대
│ ├─ components/AdSlot.astro # (선택) 광고 슬롯
│ └─ pages/
│ ├─ robots.txt.ts # robots.txt 엔드포인트
│ └─ recipes/[slug].astro # 글 상세 (noindex·광고 분기)
④ 복붙 설정 파일
1) src/lib/site.ts
// 서버(빌드) 코드에서만 환경변수를 읽는다. 주소는 PUBLIC_SITE_URL 한 곳에서만 정한다.
function env(name: string): string | undefined {
const fromProc = typeof process !== 'undefined' ? process.env[name] : undefined;
const fromVite = (import.meta as unknown as { env?: Record<string, string | undefined> }).env?.[name];
const v = fromProc ?? fromVite;
return v && v.length > 0 ? v : undefined;
}
export const SITE_URL = (env('PUBLIC_SITE_URL') ?? 'https://example.com').replace(/\/$/, '');
export const IS_PRODUCTION = env('SITE_ENV') === 'production';
2) src/lib/indexing.ts
설정 파일(astro.config.mjs)은 content collection 을 쓸 수 없으므로, 마크다운 원문의 frontmatter 만 정규식으로 읽어 판정합니다. 순수 함수라 테스트하기 쉽습니다.
/** 마크다운 원문에서 reviewStatus 가 verified 인지 판정한다. */
export function isIndexable(rawMarkdown: string): boolean {
const fm = /^?---\r?\n([\s\S]*?)\r?\n---/.exec(rawMarkdown);
if (!fm) return false; // frontmatter 가 없으면 안전하게 비색인
return /^reviewStatus:[ \t]*(?:"verified"|'verified'|verified)[ \t]*$/m.test(fm[1]);
}
3) astro.config.mjs
import { defineConfig } from 'astro/config';
import sitemap from '@astrojs/sitemap';
import { readdirSync, readFileSync, existsSync } from 'node:fs';
import { join } from 'node:path';
import { isIndexable } from './src/lib/indexing.ts';
const site = process.env.PUBLIC_SITE_URL || 'https://example.com';
const isProduction = process.env.SITE_ENV === 'production';
// 검수 전(verified 가 아닌) 글은 사이트맵에서 뺀다.
const excluded = new Set(['/404']);
const dir = join(process.cwd(), 'src/content/recipes');
if (existsSync(dir)) {
for (const f of readdirSync(dir).filter((x) => x.endsWith('.md'))) {
if (!isIndexable(readFileSync(join(dir, f), 'utf8'))) excluded.add(`/recipes/${f.replace(/\.md$/, '')}`);
}
}
const toPath = (page) => new URL(page).pathname.replace(/\.html$/, '').replace(/\/+$/, '') || '/';
export default defineConfig({
site,
output: 'static',
trailingSlash: 'never',
build: { format: 'file' },
integrations: [
sitemap({
// production 이 아니면 사이트맵 자체를 비운다.
filter: (page) => isProduction && !excluded.has(toPath(page)),
}),
],
});
4) src/layouts/BaseLayout.astro
---
import { IS_PRODUCTION, SITE_URL } from '../lib/site';
interface Props {
title: string;
description?: string;
/** 사이트 루트 기준 경로. 예: /recipes/my-post */
path: string;
/** true 면 이 페이지만 noindex (링크는 따라가게 follow 유지) */
noindex?: boolean;
}
const { title, description = '', path, noindex = false } = Astro.props;
// 프로덕션이 아니면 전체 noindex, nofollow. 프로덕션의 개별 noindex 는 follow 유지.
const robots = !IS_PRODUCTION ? 'noindex, nofollow' : noindex ? 'noindex, follow' : 'index, follow';
const canonical = `${SITE_URL}${path}`;
---
<!doctype html>
<html lang="ko">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>{title}</title>
<meta name="description" content={description} />
<meta name="robots" content={robots} />
<link rel="canonical" href={canonical} />
</head>
<body>
<a href="#main">본문 바로가기</a>
<header>
<nav aria-label="주 메뉴">
<a href="/">홈</a>
<a href="/recipes">레시피</a>
</nav>
</header>
<div id="main" tabindex="-1">
<slot />
</div>
<footer>
<nav aria-label="정책 링크">
<a href="/about">소개</a>
<a href="/contact">문의</a>
<a href="/privacy">개인정보처리방침</a>
<a href="/terms">이용약관</a>
</nav>
</footer>
</body>
</html>
5) src/pages/recipes/[slug].astro
---
import { getCollection, render } from 'astro:content';
import BaseLayout from '../../layouts/BaseLayout.astro';
import AdSlot from '../../components/AdSlot.astro';
export async function getStaticPaths() {
const entries = await getCollection('recipes');
return entries.map((entry) => ({ params: { slug: entry.id }, props: { entry } }));
}
const { entry } = Astro.props;
const verified = entry.data.reviewStatus === 'verified';
const { Content } = await render(entry);
---
<BaseLayout title={entry.data.title} description={entry.data.description} path={`/recipes/${entry.id}`} noindex={!verified}>
<main>
<article>
<h1>{entry.data.title}</h1>
{!verified && <p role="note">이 글은 초안으로 검수 중입니다. 코드는 실행 전 반드시 확인하세요.</p>}
<Content />
{verified && <AdSlot />}
</article>
</main>
</BaseLayout>
시맨틱 구조 규칙은 세 가지만 지키면 됩니다. 페이지당 h1 은 하나, main 과 article 은 본문에만, 내비게이션에는 aria-label 을 붙입니다.
6) src/pages/robots.txt.ts
import type { APIRoute } from 'astro';
import { SITE_URL } from '../lib/site';
// 사이트맵 주소를 PUBLIC_SITE_URL 에서 만들어 도메인이 바뀌어도 손댈 필요가 없다.
export const GET: APIRoute = () =>
new Response(`User-agent: *\nAllow: /\n\nSitemap: ${SITE_URL}/sitemap-index.xml\n`, {
headers: { 'Content-Type': 'text/plain; charset=utf-8' },
});
Disallow: /recipes/ 처럼 초안 경로를 막지 마세요. 크롤러가 페이지를 읽지 못하면 noindex 메타도 읽지 못합니다.
⑤ 단계
-
위 파일들을 프로젝트에 복사합니다. 이미 있는 파일은
robots·excluded부분만 합칩니다. -
모든 글의 frontmatter 에
reviewStatus: draft를 넣습니다. 검수를 마친 글만verified로 바꾸고verifiedAt: 2026-11-29같은 날짜를 함께 적습니다. -
개발 서버로 초안 글을 열어
<meta name="robots">가noindex, nofollow인지 확인합니다. -
프로덕션 모드로 빌드합니다. PowerShell 기준입니다.
$env:SITE_ENV = 'production' $env:PUBLIC_SITE_URL = 'https://example.com' npm run build -
dist에서 아래를 확인합니다.- 초안 글 HTML 에
noindex, follow가 있고adsbygoogle가 없다. sitemap-0.xml에 초안 글 주소가 없다.- 검수 완료 글에는
index, follow가 있다.
- 초안 글 HTML 에
-
확인이 끝나면 환경변수를 지웁니다 (
Remove-Item Env:SITE_ENV, Env:PUBLIC_SITE_URL). -
호스팅의 빌드 환경변수에
SITE_ENV=production,PUBLIC_SITE_URL=<실제 주소>를 등록하고 배포합니다. 미리보기 배포에는SITE_ENV를 넣지 않습니다.
⑥ 자주 나는 에러·해결
| 증상 | 원인 | 해결 |
|---|---|---|
| 초안 글이 사이트맵에 그대로 들어간다 | 빌드 형식 때문에 URL 모양이 달라 경로 비교가 어긋남 | toPath 가 .html 과 끝 슬래시를 모두 지우는지 확인하고, excluded 에 /recipes/<파일명> 형태로 넣었는지 본다 |
| 사이트맵이 비어 있다 | SITE_ENV=production 을 주지 않음 |
의도된 동작이다. 프로덕션 빌드에서만 사이트맵을 채운다 |
| 프로덕션인데 모든 페이지가 noindex | SITE_ENV 오타 또는 CI 에 환경변수 미등록 |
워크플로·호스팅 설정의 변수 이름과 값(production)을 다시 확인한다 |
| canonical 이 example.com 으로 나온다 | PUBLIC_SITE_URL 미지정 |
프로덕션 빌드에서 기본값이면 빌드를 실패시키는 가드를 추가해 실수를 막는다 |
| noindex 를 달았는데 색인에 남아 있다 | robots.txt 로 해당 경로를 막아 크롤러가 메타를 못 읽음 | Disallow 를 제거하고 재크롤링을 기다린다 |
reviewStatus: verified # 메모 가 인식되지 않는다 |
정규식이 줄 끝 주석을 허용하지 않음 | 값 뒤에 주석을 쓰지 않거나 정규식 끝에 (?:#.*)? 를 추가한다 |
⑦ 비용
추가 비용은 없습니다. 모든 처리는 빌드 시점에 끝나는 정적 HTML 이며, 별도의 서버나 유료 서비스가 필요하지 않습니다. 정적 호스팅은 Cloudflare 무료 플랜 등의 한도 안에서 운영할 수 있으나, 한도와 정책은 변경될 수 있으므로 배포 전 공식 문서를 확인하세요.
사용된 도구
Cloudflare Workers
무료 티어 있음정적 사이트와 서버리스 코드를 올리는 Cloudflare의 배포 플랫폼