Revert "[fix] solution/site: 사이트맵 lastmod 를 파일 mtime 에서 뗀다 — 페이지의 dateModified 를 그대로 쓴다"
This reverts commit 09b0538c9c.
This commit is contained in:
1 parent
b797535b17
commit
de5ff5186f
4 files changed
+18
-122
No files matched your search
@@ -1,46 +0,0 @@
|
||||
/**
|
||||
* 구운 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,38 +9,6 @@ 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