Skip to content

Commit 0e5b729

Browse files
committed
time change
1 parent c64025a commit 0e5b729

1 file changed

Lines changed: 28 additions & 22 deletions

File tree

app/sitemap.xml/route.ts

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ export async function GET() {
1010
try {
1111
const baseUrl = 'https://ppippi-dev.github.io'
1212

13-
// XML 헤더와 시작 태그
14-
let xml = '<?xml version="1.0" encoding="UTF-8"?>\n'
15-
xml += '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n'
16-
17-
// 메인 페이지 추가
18-
xml += '<url>\n'
19-
xml += ` <loc>${baseUrl}</loc>\n`
20-
xml += ` <lastmod>${formatDate(new Date(new Date().getTime() - (9 * 60 * 60 * 1000)))}</lastmod>\n`
21-
xml += '</url>\n'
13+
// XML 문자열 생성 시작
14+
const xmlStrings = [
15+
'<?xml version="1.0" encoding="UTF-8"?>',
16+
'<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">',
17+
'<url>',
18+
` <loc>${baseUrl}</loc>`,
19+
` <lastmod>${formatDate(new Date(new Date().getTime() - (9 * 60 * 60 * 1000)))}</lastmod>`,
20+
'</url>'
21+
];
2222

2323
// 블로그 포스트 추가
2424
const posts = await getPostDatabase()
@@ -29,14 +29,18 @@ export async function GET() {
2929
? formatDate(new Date(new Date(postDate).getTime() - (9 * 60 * 60 * 1000)))
3030
: formatDate(new Date(new Date().getTime() - (9 * 60 * 60 * 1000)))
3131

32-
xml += '<url>\n'
33-
xml += ` <loc>${baseUrl}/post/${post.id}</loc>\n`
34-
xml += ` <lastmod>${lastmod}</lastmod>\n`
35-
xml += '</url>\n'
32+
xmlStrings.push(
33+
'<url>',
34+
` <loc>${baseUrl}/post/${post.id}</loc>`,
35+
` <lastmod>${lastmod}</lastmod>`,
36+
'</url>'
37+
);
3638
}
3739

38-
// XML 종료 태그
39-
xml += '</urlset>'
40+
xmlStrings.push('</urlset>');
41+
42+
// 배열을 줄바꿈으로 결합
43+
const xml = xmlStrings.join('\n');
4044

4145
// Response 헤더 설정과 함께 XML 반환
4246
return new Response(xml, {
@@ -50,13 +54,15 @@ export async function GET() {
5054
console.error('Sitemap generation failed:', error)
5155

5256
// 에러 발생 시 기본 sitemap 반환
53-
const fallbackXml = `<?xml version="1.0" encoding="UTF-8"?>
54-
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
55-
<url>
56-
<loc>https://ppippi-dev.github.io</loc>
57-
<lastmod>${formatDate(new Date(new Date().getTime() - (9 * 60 * 60 * 1000)))}</lastmod>
58-
</url>
59-
</urlset>`
57+
const fallbackXml = [
58+
'<?xml version="1.0" encoding="UTF-8"?>',
59+
'<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">',
60+
'<url>',
61+
` <loc>https://ppippi-dev.github.io</loc>`,
62+
` <lastmod>${formatDate(new Date(new Date().getTime() - (9 * 60 * 60 * 1000)))}</lastmod>`,
63+
'</url>',
64+
'</urlset>'
65+
].join('\n');
6066

6167
return new Response(fallbackXml, {
6268
headers: {

0 commit comments

Comments
 (0)