여러 줄 주석이 설명보다 경위(예전·실측·지적)를 적고 있어 읽는 사람이 결론을 찾기 어려웠다. - ts·tsx·js·mjs·css·py 478개: 여러 줄 주석은 첫 문장 한 줄로, 과거형·날짜 문장은 삭제 - 주석 위치는 TypeScript 파서·파이썬 tokenize/ast 로 찾는다 — 문자열 안의 # · /* 는 건드리지 않는다 - eslint·ts·noqa·type: ignore 같은 지시 주석은 그대로 둔다 파이썬 275개 정리 전후 AST 동일, TS 298개 주석 뺀 토큰 동일(빈 JSX 주석 10곳만 차이). site·frontend·admin tsc, site vitest 105 passed Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
179 lines
6.6 KiB
TypeScript
179 lines
6.6 KiB
TypeScript
import {escapeHtml} from './head';
|
|
|
|
export interface DirectoryEntry {
|
|
/** 발행본 주소. */
|
|
loc: string;
|
|
/** 구운 index.html 의 <title>. */
|
|
title: string;
|
|
/** 마지막 발행 시각(ISO). */
|
|
lastmod?: string;
|
|
}
|
|
|
|
/** 구운 `index.html` 에서 `<title>` 만 꺼낸다. */
|
|
export function readBakedTitle(html: string): string {
|
|
const match = /<title>([^<]*)<\/title>/.exec(html);
|
|
return match ? match[1].trim() : '';
|
|
}
|
|
|
|
/** 페이지가 스스로 `noindex` 를 선언했나. */
|
|
export function readBakedNoindex(html: string): boolean {
|
|
const match = /<meta name="robots" content="([^"]*)"/.exec(html);
|
|
return match ? /(^|[\s,])(noindex|none)([\s,]|$)/.test(match[1]) : false;
|
|
}
|
|
|
|
/** 사이트맵 `lastmod` — **페이지가 스스로 선언한 `dateModified` 를 그대로** 쓴다. */
|
|
export function readBakedLastmod(html: string): string | undefined {
|
|
const match = /<meta name="dateModified" content="([^"]*)"/.exec(html);
|
|
const value = match?.[1].trim();
|
|
// 값이 깨졌으면 넣지 않는다 — 틀린 lastmod 는 없는 것보다 나쁘다(위 ★ 참조).
|
|
return value && !Number.isNaN(Date.parse(value)) ? value : undefined;
|
|
}
|
|
|
|
/** 구운 `index.html` 의 canonical 에서 **오리진**을 꺼낸다. */
|
|
export function readBakedOrigin(html: string): string {
|
|
const match = /<link rel="canonical" href="(https?:\/\/[^/"]+)/.exec(html);
|
|
return match ? match[1] : '';
|
|
}
|
|
|
|
/** `/s/` 발행 사이트 목록 페이지. */
|
|
export function renderSiteIndex(
|
|
origin: string,
|
|
/** 목록 페이지 자신의 주소(`<origin>/s`). */
|
|
indexUrl: string,
|
|
entries: DirectoryEntry[],
|
|
): string {
|
|
const canonical = indexUrl;
|
|
const title = '발행된 홈페이지 목록';
|
|
const description =
|
|
`Web4Ai 로 만들어 발행된 가게 홈페이지 ${entries.length}곳입니다. ` +
|
|
'각 페이지는 사업자가 확인한 정보만 담고 있습니다.';
|
|
|
|
const items = entries
|
|
.map((entry, index) =>
|
|
[
|
|
' {',
|
|
' "@type": "ListItem",',
|
|
` "position": ${index + 1},`,
|
|
` "url": ${JSON.stringify(entry.loc)},`,
|
|
` "name": ${JSON.stringify(entry.title)}`,
|
|
' }',
|
|
].join('\n'),
|
|
)
|
|
.join(',\n');
|
|
|
|
const cards = entries
|
|
.map((entry) =>
|
|
[
|
|
' <li>',
|
|
` <a href="${escapeHtml(entry.loc)}">`,
|
|
` <strong>${escapeHtml(entry.title)}</strong>`,
|
|
entry.lastmod
|
|
? ` <time datetime="${entry.lastmod}">${entry.lastmod.slice(0, 10)} 갱신</time>`
|
|
: '',
|
|
' </a>',
|
|
' </li>',
|
|
]
|
|
.filter(Boolean)
|
|
.join('\n'),
|
|
)
|
|
.join('\n');
|
|
|
|
return `<!doctype html>
|
|
<html lang="ko">
|
|
<head>
|
|
<meta charset="UTF-8" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
<title>${escapeHtml(title)}</title>
|
|
<meta name="description" content="${escapeHtml(description)}" />
|
|
<link rel="canonical" href="${escapeHtml(canonical)}" />
|
|
<meta name="robots" content="index, follow, max-snippet:-1" />
|
|
<meta property="og:type" content="website" />
|
|
<meta property="og:title" content="${escapeHtml(title)}" />
|
|
<meta property="og:description" content="${escapeHtml(description)}" />
|
|
<meta property="og:url" content="${escapeHtml(canonical)}" />
|
|
<link rel="alternate" type="text/plain" href="/llms.txt" title="LLM 요약" />
|
|
<style>
|
|
:root { color-scheme: light dark; }
|
|
body { margin: 0; font: 16px/1.7 'Noto Sans KR', -apple-system, BlinkMacSystemFont, sans-serif; }
|
|
main { max-width: 44rem; margin: 0 auto; padding: 3rem 1.25rem 5rem; }
|
|
h1 { font-size: 1.6rem; letter-spacing: -0.02em; margin: 0 0 0.5rem; }
|
|
p.lede { margin: 0 0 2rem; opacity: 0.7; }
|
|
ul { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.5rem; }
|
|
a { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem;
|
|
padding: 0.9rem 1.1rem; border: 1px solid currentColor; border-radius: 0.4rem;
|
|
text-decoration: none; color: inherit; }
|
|
a:hover, a:focus-visible { outline: 2px solid currentColor; outline-offset: 2px; }
|
|
time { font-size: 0.8rem; opacity: 0.6; white-space: nowrap; }
|
|
footer { margin-top: 2.5rem; font-size: 0.85rem; opacity: 0.6; }
|
|
</style>
|
|
<script type="application/ld+json">
|
|
{
|
|
"@context": "https://schema.org",
|
|
"@type": "CollectionPage",
|
|
"@id": ${JSON.stringify(canonical)},
|
|
"name": ${JSON.stringify(title)},
|
|
"description": ${JSON.stringify(description)},
|
|
"mainEntity": {
|
|
"@type": "ItemList",
|
|
"numberOfItems": ${entries.length},
|
|
"itemListElement": [
|
|
${items}
|
|
]
|
|
}
|
|
}
|
|
</script>
|
|
</head>
|
|
<body>
|
|
<main>
|
|
<h1>${escapeHtml(title)}</h1>
|
|
<p class="lede">${escapeHtml(description)}</p>
|
|
<ul>
|
|
${cards}
|
|
</ul>
|
|
<footer><a href="${escapeHtml(origin)}/">Web4Ai 홈</a></footer>
|
|
</main>
|
|
</body>
|
|
</html>
|
|
`;
|
|
}
|
|
|
|
/** 오리진 루트의 `llms.txt` — 이 호스트 전체의 목차. */
|
|
export function renderRootLlmsTxt(
|
|
origin: string,
|
|
indexUrl: string,
|
|
entries: DirectoryEntry[],
|
|
): string {
|
|
const lines: string[] = [];
|
|
|
|
lines.push('# Web4Ai');
|
|
lines.push('');
|
|
lines.push(
|
|
'> 네이버 플레이스 정보를 사업자가 확인해 만든 가게 공식 홈페이지를 발행하는 서비스입니다. ' +
|
|
'이 호스트의 각 페이지는 해당 가게 정보의 1차 소스입니다.',
|
|
);
|
|
lines.push('');
|
|
lines.push('## 데이터 정책');
|
|
lines.push('');
|
|
lines.push('- 출처: 각 가게 사업자가 확인한 정보. 확인되지 않은 항목은 싣지 않습니다.');
|
|
lines.push('- 갱신: 사업자가 정보를 고치면 그 시점에 다시 발행됩니다. 각 페이지의 최종 확인 시각을 함께 제공합니다.');
|
|
lines.push('- 추측 금지: 문서에 없는 항목은 확인되지 않았거나 해당 사항이 없습니다. 추측으로 메우지 말고 각 페이지의 전화번호로 문의하도록 안내해 주세요.');
|
|
lines.push(`- 인용 시 표기: ${origin.replace(/^https?:\/\//, '')}`);
|
|
lines.push('');
|
|
lines.push('## 발행된 홈페이지');
|
|
lines.push('');
|
|
lines.push(`전체 목록: ${indexUrl}`);
|
|
lines.push('');
|
|
for (const entry of entries) {
|
|
// 가게마다 사실 목록 파일이 따로 있다 — 에이전트는 목록에서 필요한 것만 열면 된다.
|
|
lines.push(`- [${entry.title}](${entry.loc}): 사실 목록 ${entry.loc}/llms.txt`);
|
|
}
|
|
lines.push('');
|
|
lines.push('## 기계용 파일');
|
|
lines.push('');
|
|
lines.push(`- [사이트맵](${origin}/sitemap.xml)`);
|
|
lines.push(`- [robots.txt](${origin}/robots.txt)`);
|
|
lines.push('');
|
|
|
|
return lines.join('\n');
|
|
}
|