@@ -22,7 +22,6 @@ const head: HeadConfig[] = [
22
22
] ,
23
23
// Open Graph
24
24
[ "meta" , { property : "og:site_name" , content : "Oxc" } ] ,
25
- [ "meta" , { property : "og:url" , content : "https://github.com/oxc-project" } ] ,
26
25
[
27
26
"meta" ,
28
27
{
@@ -65,11 +64,11 @@ export const sharedConfig = defineConfig({
65
64
base : "/" ,
66
65
head,
67
66
lastUpdated : false ,
68
- transformHead : ( { pageData } ) => {
69
- const head : HeadConfig [ ] = [ ] ;
67
+ transformPageData ( pageData ) {
68
+ pageData . frontmatter . head ?? = [ ] ;
70
69
71
70
if ( pageData . frontmatter . canonical ) {
72
- head . push ( [
71
+ pageData . frontmatter . head . push ( [
73
72
"link" ,
74
73
{
75
74
rel : "canonical" ,
@@ -78,7 +77,31 @@ export const sharedConfig = defineConfig({
78
77
] ) ;
79
78
}
80
79
81
- return head ;
80
+ // Add page-specific Open Graph and Twitter meta tags
81
+ const title = pageData . frontmatter . title || pageData . title ;
82
+ const description = pageData . frontmatter . description || pageData . description
83
+ || "A collection of high-performance JavaScript tools written in Rust" ;
84
+
85
+ // Construct the canonical URL for the page
86
+ let url = "https://oxc.rs" ;
87
+ if ( pageData . relativePath !== "index.md" ) {
88
+ const path = pageData . relativePath . replace ( / \. m d $ / , ".html" ) . replace ( / \/ i n d e x \. h t m l $ / , "/" ) ;
89
+ if ( path !== "index.html" ) {
90
+ url += "/" + path . replace ( / ^ \/ + / , "" ) ;
91
+ }
92
+ }
93
+
94
+ if ( title ) {
95
+ pageData . frontmatter . head . push ( [ "meta" , { property : "og:title" , content : title } ] ) ;
96
+ pageData . frontmatter . head . push ( [ "meta" , { name : "twitter:title" , content : title } ] ) ;
97
+ }
98
+
99
+ if ( description ) {
100
+ pageData . frontmatter . head . push ( [ "meta" , { property : "og:description" , content : description } ] ) ;
101
+ pageData . frontmatter . head . push ( [ "meta" , { name : "twitter:description" , content : description } ] ) ;
102
+ }
103
+
104
+ pageData . frontmatter . head . push ( [ "meta" , { property : "og:url" , content : url } ] ) ;
82
105
} ,
83
106
themeConfig : {
84
107
siteTitle : "Oxc" ,
0 commit comments