Unverified Commit 27259738 authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

[metadata] use https protocol for schema urls (#80356)

parent 1f3a186a
...@@ -88,7 +88,7 @@ describe('resolveRouteData', () => { ...@@ -88,7 +88,7 @@ describe('resolveRouteData', () => {
]) ])
).toMatchInlineSnapshot(` ).toMatchInlineSnapshot(`
"<?xml version="1.0" encoding="UTF-8"?> "<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> <urlset xmlns="https://www.sitemaps.org/schemas/sitemap/0.9">
<url> <url>
<loc>https://example.com</loc> <loc>https://example.com</loc>
<lastmod>2021-01-01</lastmod> <lastmod>2021-01-01</lastmod>
...@@ -115,7 +115,7 @@ describe('resolveRouteData', () => { ...@@ -115,7 +115,7 @@ describe('resolveRouteData', () => {
]) ])
).toMatchInlineSnapshot(` ).toMatchInlineSnapshot(`
"<?xml version="1.0" encoding="UTF-8"?> "<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml"> <urlset xmlns="https://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="https://www.w3.org/1999/xhtml">
<url> <url>
<loc>https://example.com</loc> <loc>https://example.com</loc>
<xhtml:link rel="alternate" hreflang="es" href="https://example.com/es" /> <xhtml:link rel="alternate" hreflang="es" href="https://example.com/es" />
...@@ -139,7 +139,7 @@ describe('resolveRouteData', () => { ...@@ -139,7 +139,7 @@ describe('resolveRouteData', () => {
]) ])
).toMatchInlineSnapshot(` ).toMatchInlineSnapshot(`
"<?xml version="1.0" encoding="UTF-8"?> "<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"> <urlset xmlns="https://www.sitemaps.org/schemas/sitemap/0.9" xmlns:image="https://www.google.com/schemas/sitemap-image/1.1">
<url> <url>
<loc>https://example.com</loc> <loc>https://example.com</loc>
<image:image> <image:image>
...@@ -195,7 +195,7 @@ describe('resolveRouteData', () => { ...@@ -195,7 +195,7 @@ describe('resolveRouteData', () => {
]) ])
).toMatchInlineSnapshot(` ).toMatchInlineSnapshot(`
"<?xml version="1.0" encoding="UTF-8"?> "<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1"> <urlset xmlns="https://www.sitemaps.org/schemas/sitemap/0.9" xmlns:video="https://www.google.com/schemas/sitemap-video/1.1">
<url> <url>
<loc>https://example.com</loc> <loc>https://example.com</loc>
<video:video> <video:video>
......
...@@ -52,15 +52,15 @@ export function resolveSitemap(data: MetadataRoute.Sitemap): string { ...@@ -52,15 +52,15 @@ export function resolveSitemap(data: MetadataRoute.Sitemap): string {
let content = '' let content = ''
content += '<?xml version="1.0" encoding="UTF-8"?>\n' content += '<?xml version="1.0" encoding="UTF-8"?>\n'
content += '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"' content += '<urlset xmlns="https://www.sitemaps.org/schemas/sitemap/0.9"'
if (hasImages) { if (hasImages) {
content += ' xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"' content += ' xmlns:image="https://www.google.com/schemas/sitemap-image/1.1"'
} }
if (hasVideos) { if (hasVideos) {
content += ' xmlns:video="http://www.google.com/schemas/sitemap-video/1.1"' content += ' xmlns:video="https://www.google.com/schemas/sitemap-video/1.1"'
} }
if (hasAlternates) { if (hasAlternates) {
content += ' xmlns:xhtml="http://www.w3.org/1999/xhtml">\n' content += ' xmlns:xhtml="https://www.w3.org/1999/xhtml">\n'
} else { } else {
content += '>\n' content += '>\n'
} }
......
...@@ -52,7 +52,7 @@ describe('app dir - metadata dynamic routes', () => { ...@@ -52,7 +52,7 @@ describe('app dir - metadata dynamic routes', () => {
expect(text).toMatchInlineSnapshot(` expect(text).toMatchInlineSnapshot(`
"<?xml version="1.0" encoding="UTF-8"?> "<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> <urlset xmlns="https://www.sitemaps.org/schemas/sitemap/0.9">
<url> <url>
<loc>https://example.com</loc> <loc>https://example.com</loc>
<lastmod>2021-01-01</lastmod> <lastmod>2021-01-01</lastmod>
...@@ -95,7 +95,7 @@ describe('app dir - metadata dynamic routes', () => { ...@@ -95,7 +95,7 @@ describe('app dir - metadata dynamic routes', () => {
it('should support alternate.languages in sitemap', async () => { it('should support alternate.languages in sitemap', async () => {
const xml = await (await next.fetch('/lang/sitemap.xml')).text() const xml = await (await next.fetch('/lang/sitemap.xml')).text()
expect(xml).toContain('xmlns:xhtml="http://www.w3.org/1999/xhtml') expect(xml).toContain('xmlns:xhtml="https://www.w3.org/1999/xhtml')
expect(xml).toContain( expect(xml).toContain(
`<xhtml:link rel="alternate" hreflang="es" href="https://example.com/es/about" />` `<xhtml:link rel="alternate" hreflang="es" href="https://example.com/es/about" />`
) )
...@@ -119,7 +119,7 @@ describe('app dir - metadata dynamic routes', () => { ...@@ -119,7 +119,7 @@ describe('app dir - metadata dynamic routes', () => {
const xml = await (await next.fetch('/sitemap-video/sitemap.xml')).text() const xml = await (await next.fetch('/sitemap-video/sitemap.xml')).text()
expect(xml).toMatchInlineSnapshot(` expect(xml).toMatchInlineSnapshot(`
"<?xml version="1.0" encoding="UTF-8"?> "<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1"> <urlset xmlns="https://www.sitemaps.org/schemas/sitemap/0.9" xmlns:video="https://www.google.com/schemas/sitemap-video/1.1">
<url> <url>
<loc>https://example.com/about</loc> <loc>https://example.com/about</loc>
<video:video> <video:video>
......
...@@ -4,7 +4,7 @@ export default function sitemap(): MetadataRoute.Sitemap { ...@@ -4,7 +4,7 @@ export default function sitemap(): MetadataRoute.Sitemap {
return [ return [
{ {
url: 'https://vercel.com', url: 'https://vercel.com',
lastModified: new Date(), lastModified: '2023-10-01',
changeFrequency: 'yearly', changeFrequency: 'yearly',
priority: 1, priority: 1,
}, },
......
...@@ -9,11 +9,18 @@ describe('middleware-sitemap', () => { ...@@ -9,11 +9,18 @@ describe('middleware-sitemap', () => {
let html = await next.render('/') let html = await next.render('/')
expect(html).toContain('redirected') expect(html).toContain('redirected')
html = await next.render('/sitemap.xml') const xml = await next.render('/sitemap.xml')
expect(html).not.toContain('redirected') expect(xml).toMatchInlineSnapshot(`
expect(html).toContain('<?xml version="1.0" encoding="UTF-8"?>') "<?xml version="1.0" encoding="UTF-8"?>
expect(html).toContain( <urlset xmlns="https://www.sitemaps.org/schemas/sitemap/0.9">
'<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' <url>
) <loc>https://vercel.com</loc>
<lastmod>2023-10-01</lastmod>
<changefreq>yearly</changefreq>
<priority>1</priority>
</url>
</urlset>
"
`)
}) })
}) })
...@@ -12,7 +12,7 @@ describe('sitemap-group', () => { ...@@ -12,7 +12,7 @@ describe('sitemap-group', () => {
const text = await res.text() const text = await res.text()
expect(text).toMatchInlineSnapshot(` expect(text).toMatchInlineSnapshot(`
"<?xml version="1.0" encoding="UTF-8"?> "<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> <urlset xmlns="https://www.sitemaps.org/schemas/sitemap/0.9">
<url> <url>
<loc>https://www.vercel.com</loc> <loc>https://www.vercel.com</loc>
<lastmod>2024-12-05T23:45:13.405Z</lastmod> <lastmod>2024-12-05T23:45:13.405Z</lastmod>
......
...@@ -44,7 +44,7 @@ describe('use-cache-metadata-route-handler', () => { ...@@ -44,7 +44,7 @@ describe('use-cache-metadata-route-handler', () => {
if (isNextDev) { if (isNextDev) {
expect(body).toMatchInlineSnapshot(` expect(body).toMatchInlineSnapshot(`
"<?xml version="1.0" encoding="UTF-8"?> "<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> <urlset xmlns="https://www.sitemaps.org/schemas/sitemap/0.9">
<url> <url>
<loc>https://acme.com?sentinel=runtime</loc> <loc>https://acme.com?sentinel=runtime</loc>
</url> </url>
...@@ -54,7 +54,7 @@ describe('use-cache-metadata-route-handler', () => { ...@@ -54,7 +54,7 @@ describe('use-cache-metadata-route-handler', () => {
} else { } else {
expect(body).toMatchInlineSnapshot(` expect(body).toMatchInlineSnapshot(`
"<?xml version="1.0" encoding="UTF-8"?> "<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> <urlset xmlns="https://www.sitemaps.org/schemas/sitemap/0.9">
<url> <url>
<loc>https://acme.com?sentinel=buildtime</loc> <loc>https://acme.com?sentinel=buildtime</loc>
</url> </url>
...@@ -74,7 +74,7 @@ describe('use-cache-metadata-route-handler', () => { ...@@ -74,7 +74,7 @@ describe('use-cache-metadata-route-handler', () => {
if (isNextDev) { if (isNextDev) {
expect(body).toMatchInlineSnapshot(` expect(body).toMatchInlineSnapshot(`
"<?xml version="1.0" encoding="UTF-8"?> "<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> <urlset xmlns="https://www.sitemaps.org/schemas/sitemap/0.9">
<url> <url>
<loc>https://acme.com/1?sentinel=runtime</loc> <loc>https://acme.com/1?sentinel=runtime</loc>
</url> </url>
...@@ -84,7 +84,7 @@ describe('use-cache-metadata-route-handler', () => { ...@@ -84,7 +84,7 @@ describe('use-cache-metadata-route-handler', () => {
} else { } else {
expect(body).toMatchInlineSnapshot(` expect(body).toMatchInlineSnapshot(`
"<?xml version="1.0" encoding="UTF-8"?> "<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> <urlset xmlns="https://www.sitemaps.org/schemas/sitemap/0.9">
<url> <url>
<loc>https://acme.com/1?sentinel=buildtime</loc> <loc>https://acme.com/1?sentinel=buildtime</loc>
</url> </url>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment