MCPcopy
hub / github.com/vercel/next.js / getMetadataMetas

Function getMetadataMetas

test/e2e/app-dir/metadata-static-file/utils.ts:36–71  ·  view source on GitHub ↗
(browser: Playwright)

Source from the content-addressed store, hash-verified

34}
35
36async function getMetadataMetas(browser: Playwright) {
37 const metas = await browser.locator('meta').evaluateAll((elements: any[]) => {
38 return elements
39 .filter((meta) => {
40 if (!meta.name && !meta.hasAttribute('property')) {
41 return false
42 }
43
44 const attr = meta.name || meta.getAttribute('property') || ''
45 return [
46 'og:',
47 'twitter:',
48 'viewport',
49 'description',
50 'keywords',
51 'robots',
52 ].some(
53 (prefix) => attr.startsWith(prefix) || attr === prefix.slice(0, -1)
54 )
55 })
56 .map((el) => ({
57 ...(el.name && { name: el.name }),
58 ...(el.hasAttribute('property') && {
59 property: el.getAttribute('property'),
60 }),
61 }))
62 .sort((a, b) => {
63 if (a.name && !b.name) return -1
64 if (!a.name && b.name) return 1
65 return (a.name || a.property || '').localeCompare(
66 b.name || b.property || ''
67 )
68 })
69 })
70 return metas
71}
72
73export async function getCommonMetadataHeadTags(browser: Playwright) {
74 const [links, metas] = await Promise.all([

Callers 1

Calls 8

locatorMethod · 0.80
getAttributeMethod · 0.80
someMethod · 0.80
startsWithMethod · 0.80
sortMethod · 0.45
mapMethod · 0.45
filterMethod · 0.45
sliceMethod · 0.45

Tested by

no test coverage detected