(locale = defaultLocale.code, path = '')
| 198 | * @returns {Promise<import('next').Metadata>} |
| 199 | */ |
| 200 | const _getPageMetadata = async (locale = defaultLocale.code, path = '') => { |
| 201 | const pageMetadata = { ...PAGE_METADATA }; |
| 202 | |
| 203 | const { source = '' } = await getMarkdownFile(locale, path); |
| 204 | |
| 205 | const { data } = matter(source); |
| 206 | |
| 207 | const getUrlForPathname = (l, p) => |
| 208 | `${baseUrlAndPath}/${l}${p ? `/${p}` : ''}`; |
| 209 | |
| 210 | // Default Title for the page |
| 211 | pageMetadata.title = data.title |
| 212 | ? `${siteConfig.title} — ${data.title}` |
| 213 | : siteConfig.title; |
| 214 | |
| 215 | pageMetadata.description = data.description |
| 216 | ? data.description |
| 217 | : siteConfig.description; |
| 218 | |
| 219 | // Default Twitter Title for the page |
| 220 | pageMetadata.twitter.title = pageMetadata.title; |
| 221 | |
| 222 | // Default Open Graph Image for the page |
| 223 | pageMetadata.openGraph.images = [ |
| 224 | ENABLE_STATIC_EXPORT |
| 225 | ? `${defaultLocale.code}/next-data/og/announcement/Run JavaScript Everywhere` |
| 226 | : `${defaultLocale.code}/next-data/og/${data.category ?? DEFAULT_CATEGORY_OG_TYPE}/${pageMetadata.title}`, |
| 227 | ]; |
| 228 | |
| 229 | // Default canonical URL for the page |
| 230 | pageMetadata.alternates.canonical = |
| 231 | data.canonical ?? getUrlForPathname(locale, path); |
| 232 | |
| 233 | // Default alternate URL for the page in the default locale |
| 234 | pageMetadata.alternates.languages['x-default'] = getUrlForPathname( |
| 235 | defaultLocale.code, |
| 236 | path |
| 237 | ); |
| 238 | |
| 239 | // Retrieves a matching blog feed for the category of the blog post |
| 240 | // If no matching blog feed is found, we simply fallback to the default blog feed |
| 241 | const matchingBlogFeed = siteConfig.rssFeeds.find( |
| 242 | feed => feed.category === data.category |
| 243 | ); |
| 244 | |
| 245 | // Adds the RSS Feed URL to the page metadata, if a matching feed is found |
| 246 | // otherwise, we fallback to the default blog feed |
| 247 | pageMetadata.alternates.types['application/rss+xml'] = getUrlForPathname( |
| 248 | locale, |
| 249 | `feed/${matchingBlogFeed?.file ?? 'blog.xml'}` |
| 250 | ); |
| 251 | |
| 252 | // Iterate all languages to generate alternate URLs for each language |
| 253 | availableLocaleCodes.forEach(currentLocale => { |
| 254 | pageMetadata.alternates.languages[currentLocale] = getUrlForPathname( |
| 255 | currentLocale, |
| 256 | path |
| 257 | ); |
no test coverage detected