[fix] solution/site: 사이트맵 lastmod 를 파일 mtime 에서 뗀다 — 페이지의 dateModified 를 그대로 쓴다
lastmod 를 구운 index.html 의 mtime 에서 읽었다. 렌더러를 배포하면 번들 해시가 바뀌어 내용이 같은 사이트까지 전부 다시 구워지고, mtime 은 그때마다 오늘이 된다 — 사이트맵이 "전 사이트가 오늘 갱신됨" 을 통보한다. 구글은 lastmod 를 페이지의 실제 수정과 대조해 맞을 때만 쓰고 어긋나면 필드를 아예 무시한다 (Search Central: "the date and time of the last significant update" · "consistently and verifiably accurate"). 지금 뭘 깨뜨리는 게 아니라, 사장님이 진짜로 내용을 고쳐 재발행한 날의 신호를 미리 죽여 두는 종류다. 사이트가 100개를 넘기면 되돌리는 데 시간이 걸린다. - seo/directory.ts: readBakedTitle · readBakedLastmod 추가. lastmod 는 head 가 선언한 dateModified(= payload.site.updatedAt) 그 값이다 — 구글이 대조하는 값과 같아 어긋날 수 없다 - scripts/prerender.ts: 사이트맵 항목에서 mtime 제거, 파일 한 번 읽어 제목·lastmod 동시 추출. mtime 은 dateModified 메타가 없던 산출물에만 남는 폴백이다 - seo/directory.test.ts: head.ts 태그와 파서의 커플링 고정 — 모양이 바뀌면 파서가 조용히 undefined 를 내고 mtime 으로 되돌아간다(빌드도 화면도 멀쩡한 회귀) - docs/DEVLOG.md tsc·eslint 통과, vitest 22 passed (신규 5건) Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018xTWrJ6Mrr6HhEN6hZEER4
This commit is contained in:
1 parent
533de126fb
commit
09b0538c9c
4 files changed
+122
-18
No files matched your search
@@ -0,0 +1,46 @@
|
||||
/**
|
||||
* 구운 HTML → 사이트맵·목록 값.
|
||||
*
|
||||
* ★ 이 테스트가 지키는 것은 **커플링 하나**다. 사이트맵의 lastmod 는 페이지가 head 에
|
||||
* 선언한 dateModified 와 같은 값이어야 한다 — 구글이 lastmod 를 신뢰하는 조건이
|
||||
* "페이지의 실제 수정과 대조해 맞을 것" 이기 때문이다. head.ts 가 태그 모양을 바꾸면
|
||||
* readBakedLastmod 는 조용히 undefined 를 내고 사이트맵은 mtime 으로 되돌아간다 —
|
||||
* 빌드는 통과하고 화면도 멀쩡한, 눈으로 못 찾는 종류의 회귀다. 그래서 붙인다.
|
||||
*/
|
||||
import {describe, expect, it} from 'vitest';
|
||||
|
||||
import {MOONLIGHT_STAY_PAYLOAD} from '../fixtures/moonlight-stay';
|
||||
import {readBakedLastmod, readBakedTitle} from './directory';
|
||||
import {renderHead} from './head';
|
||||
import {homeMeta} from './meta';
|
||||
|
||||
/** 실제 프리렌더와 같은 경로로 head 를 굽는다(prerender.ts prerenderSite). */
|
||||
function bakedHead(): string {
|
||||
const payload = MOONLIGHT_STAY_PAYLOAD;
|
||||
return renderHead({payload, meta: homeMeta(payload)});
|
||||
}
|
||||
|
||||
describe('readBakedLastmod', () => {
|
||||
it('head 가 선언한 dateModified 를 그대로 돌려준다', () => {
|
||||
expect(readBakedLastmod(bakedHead())).toBe(MOONLIGHT_STAY_PAYLOAD.site.updatedAt);
|
||||
});
|
||||
|
||||
it('메타가 없으면 undefined — 호출부가 mtime 으로 떨어진다', () => {
|
||||
expect(readBakedLastmod('<html><head><title>x</title></head></html>')).toBeUndefined();
|
||||
});
|
||||
|
||||
it('날짜로 못 읽는 값은 버린다 — 틀린 lastmod 는 없는 것보다 나쁘다', () => {
|
||||
expect(readBakedLastmod('<meta name="dateModified" content="어제" />')).toBeUndefined();
|
||||
expect(readBakedLastmod('<meta name="dateModified" content="" />')).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('readBakedTitle', () => {
|
||||
it('구운 HTML 의 title 을 꺼낸다', () => {
|
||||
expect(readBakedTitle(bakedHead())).toBe(homeMeta(MOONLIGHT_STAY_PAYLOAD).title);
|
||||
});
|
||||
|
||||
it('title 이 없으면 빈 문자열 — 호출부가 슬러그로 떨어진다', () => {
|
||||
expect(readBakedTitle('<html><head></head></html>')).toBe('');
|
||||
});
|
||||
});
|
||||
@@ -9,6 +9,38 @@ export interface DirectoryEntry {
|
||||
lastmod?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 구운 `index.html` 에서 `<title>` 만 꺼낸다. 파서를 붙일 값어치가 없는 한 줄짜리 일이다.
|
||||
*
|
||||
* ★ 왜 payload 가 아니라 구운 HTML 을 읽나 — 발행은 **바뀐 사이트 하나만** 굽는다.
|
||||
* 이번 실행분으로만 목록을 만들면 나머지 사이트가 목록에서 사라진다.
|
||||
*/
|
||||
export function readBakedTitle(html: string): string {
|
||||
const match = /<title>([^<]*)<\/title>/.exec(html);
|
||||
return match ? match[1].trim() : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* 사이트맵 `lastmod` — **페이지가 스스로 선언한 `dateModified` 를 그대로** 쓴다.
|
||||
*
|
||||
* ★ 파일 mtime 을 쓰면 안 된다(예전 구현). 렌더러를 배포하면 번들 해시가 바뀌어 내용이
|
||||
* 같은 사이트까지 전부 다시 구워진다 — mtime 은 그때마다 오늘이 되고, 사이트맵은
|
||||
* **"전 사이트가 오늘 갱신됨"** 을 통보한다. 구글은 lastmod 를 페이지의 실제 수정과
|
||||
* 대조해 맞을 때만 쓰고 어긋나면 그 필드를 **아예 무시한다**(Search Central: "the date and
|
||||
* time of the last significant update" · "consistently and verifiably accurate").
|
||||
* 즉 이 오염은 사장님이 **진짜로** 내용을 고쳐 재발행한 날의 신호까지 같이 죽인다.
|
||||
*
|
||||
* ★ head.ts 의 `dateModified` 메타와 **같은 값**을 읽는다 — 구글이 대조하는 그 값이라
|
||||
* 사이트맵과 페이지가 어긋날 수 없다. head.ts 가 이 태그를 바꾸면 여기도 같이 고친다
|
||||
* (directory.test.ts 가 그 커플링을 고정해 둔다).
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* `/s/` 발행 사이트 목록 페이지.
|
||||
*
|
||||
|
||||
Reference in new issue
Block a user