|
1 | 1 | import { defineConfig } from "vitepress"; |
| 2 | +import { |
| 3 | + describePage, |
| 4 | + ogImageOutPath, |
| 5 | + ogImageRelPath, |
| 6 | + writeOgImage, |
| 7 | + type OgPageInfo, |
| 8 | +} from "./og-image.mts"; |
2 | 9 |
|
3 | 10 | const repoName = "SimDeck"; |
4 | 11 | const githubUrl = `https://github.com/NativeScript/${repoName}`; |
5 | 12 | const siteUrl = "https://simdeck.nativescript.org"; |
6 | 13 |
|
| 14 | +type CollectedPage = OgPageInfo & { |
| 15 | + slug: string; |
| 16 | + urlPath: string; |
| 17 | +}; |
| 18 | + |
| 19 | +const collectedPages = new Map<string, CollectedPage>(); |
| 20 | + |
7 | 21 | export default defineConfig({ |
8 | 22 | title: "SimDeck", |
9 | 23 | description: |
10 | 24 | "Stream, inspect, and automate iOS Simulators and Android emulators from a browser, CLI, or test.", |
11 | 25 | lang: "en-US", |
12 | 26 | cleanUrls: true, |
13 | 27 | lastUpdated: true, |
| 28 | + srcExclude: ["**/public/**"], |
14 | 29 |
|
15 | 30 | head: [ |
16 | 31 | ["meta", { name: "theme-color", content: "#0a84ff" }], |
17 | 32 | ["meta", { property: "og:type", content: "website" }], |
18 | | - ["meta", { property: "og:title", content: "SimDeck" }], |
19 | | - [ |
20 | | - "meta", |
21 | | - { |
22 | | - property: "og:description", |
23 | | - content: |
24 | | - "Stream, inspect, and automate iOS Simulators and Android emulators from a browser, CLI, or test.", |
25 | | - }, |
26 | | - ], |
27 | | - ["meta", { property: "og:url", content: `${siteUrl}/` }], |
28 | | - ["link", { rel: "canonical", href: `${siteUrl}/` }], |
| 33 | + ["meta", { property: "og:site_name", content: "SimDeck" }], |
| 34 | + ["meta", { name: "twitter:card", content: "summary_large_image" }], |
| 35 | + ["meta", { name: "twitter:site", content: "@NativeScript" }], |
29 | 36 | ], |
30 | 37 |
|
| 38 | + transformPageData(pageData) { |
| 39 | + if (pageData.relativePath === "404.md") return; |
| 40 | + |
| 41 | + const { slug, urlPath, category } = describePage(pageData.relativePath); |
| 42 | + |
| 43 | + const isHome = pageData.frontmatter.layout === "home"; |
| 44 | + const hero = (pageData.frontmatter.hero ?? {}) as { |
| 45 | + name?: string; |
| 46 | + text?: string; |
| 47 | + tagline?: string; |
| 48 | + }; |
| 49 | + |
| 50 | + const title = isHome |
| 51 | + ? hero.text || hero.name || "SimDeck" |
| 52 | + : pageData.title || "SimDeck"; |
| 53 | + |
| 54 | + const description = |
| 55 | + (pageData.frontmatter.description as string | undefined) || |
| 56 | + (isHome ? hero.tagline : undefined) || |
| 57 | + pageData.description || |
| 58 | + "Stream, inspect, and automate iOS Simulators and Android emulators from a browser, CLI, or test."; |
| 59 | + |
| 60 | + collectedPages.set(slug, { |
| 61 | + slug, |
| 62 | + urlPath, |
| 63 | + title, |
| 64 | + description, |
| 65 | + category: isHome ? undefined : category, |
| 66 | + }); |
| 67 | + |
| 68 | + const pageUrl = `${siteUrl}${urlPath}`; |
| 69 | + const imageUrl = `${siteUrl}/${ogImageRelPath(slug)}`; |
| 70 | + |
| 71 | + pageData.frontmatter.head ??= []; |
| 72 | + pageData.frontmatter.head.push( |
| 73 | + ["link", { rel: "canonical", href: pageUrl }], |
| 74 | + ["meta", { property: "og:title", content: title }], |
| 75 | + ["meta", { property: "og:description", content: description }], |
| 76 | + ["meta", { property: "og:url", content: pageUrl }], |
| 77 | + ["meta", { property: "og:image", content: imageUrl }], |
| 78 | + ["meta", { property: "og:image:width", content: "1200" }], |
| 79 | + ["meta", { property: "og:image:height", content: "630" }], |
| 80 | + ["meta", { property: "og:image:alt", content: title }], |
| 81 | + ["meta", { name: "twitter:title", content: title }], |
| 82 | + ["meta", { name: "twitter:description", content: description }], |
| 83 | + ["meta", { name: "twitter:image", content: imageUrl }], |
| 84 | + ); |
| 85 | + }, |
| 86 | + |
| 87 | + async buildEnd(siteConfig) { |
| 88 | + const outDir = siteConfig.outDir; |
| 89 | + if (collectedPages.size === 0) { |
| 90 | + console.warn("[og-image] No pages collected; skipping image generation."); |
| 91 | + return; |
| 92 | + } |
| 93 | + |
| 94 | + const tasks: Array<Promise<void>> = []; |
| 95 | + for (const page of collectedPages.values()) { |
| 96 | + tasks.push( |
| 97 | + writeOgImage( |
| 98 | + { |
| 99 | + title: page.title, |
| 100 | + description: page.description, |
| 101 | + category: page.category, |
| 102 | + }, |
| 103 | + ogImageOutPath(outDir, page.slug), |
| 104 | + ), |
| 105 | + ); |
| 106 | + } |
| 107 | + await Promise.all(tasks); |
| 108 | + console.log(`[og-image] Generated ${tasks.length} social card images.`); |
| 109 | + }, |
| 110 | + |
31 | 111 | themeConfig: { |
32 | 112 | siteTitle: "SimDeck", |
33 | 113 |
|
|
0 commit comments