@@ -73,7 +73,8 @@ public struct Metadata {
73
73
self . site = site
74
74
self . title = title
75
75
self . titleSeperator = titleSeperator
76
- self . pageTitle = " \( title ?? " " ) \( site. map { " \( titleSeperator) \( $0) " } ?? " " ) "
76
+ self . pageTitle =
77
+ " \( title ?? " " ) \( site. map { " \( titleSeperator) \( $0) " } ?? " " ) "
77
78
self . description = description
78
79
self . date = date
79
80
self . image = image
@@ -85,3 +86,52 @@ public struct Metadata {
85
86
self . themeColor = themeColor
86
87
}
87
88
}
89
+
90
+ extension Metadata {
91
+ /// Initializes a new `Metadata` instance based on an existing one, with optional modifications to any property.
92
+ ///
93
+ /// - Parameters:
94
+ /// - base: The original `Metadata` instance.
95
+ /// - site: Optional site value, default is `nil`.
96
+ /// - title: Optional title value, default is `nil`.
97
+ /// - titleSeperator: Optional title separator, default is the same as `base`.
98
+ /// - description: Optional description value, default is the same as `base`.
99
+ /// - date: Optional date value, default is the same as `base`.
100
+ /// - image: Optional image value, default is the same as `base`.
101
+ /// - author: Optional author value, default is the same as `base`.
102
+ /// - keywords: Optional keywords value, default is the same as `base`.
103
+ /// - twitter: Optional twitter handle, default is the same as `base`.
104
+ /// - locale: Optional locale value, default is the same as `base`.
105
+ /// - type: Optional content type, default is the same as `base`.
106
+ /// - themeColor: Optional theme color, default is the same as `base`.
107
+ public init (
108
+ base: Metadata ,
109
+ site: String ? = nil ,
110
+ title: String ? = nil ,
111
+ titleSeperator: String ? = nil ,
112
+ description: String ? = nil ,
113
+ date: Date ? = nil ,
114
+ image: String ? = nil ,
115
+ author: String ? = nil ,
116
+ keywords: [ String ] ? = nil ,
117
+ twitter: String ? = nil ,
118
+ locale: Locale ? = nil ,
119
+ type: ContentType ? = nil ,
120
+ themeColor: ThemeColor ? = nil
121
+ ) {
122
+ self . site = site ?? base. site
123
+ self . title = title ?? base. title
124
+ self . titleSeperator = titleSeperator ?? base. titleSeperator
125
+ self . pageTitle =
126
+ " \( title ?? " " ) \( site. map { " \( titleSeperator ?? " | " ) \( $0) " } ?? " " ) "
127
+ self . description = description ?? base. description
128
+ self . date = date ?? base. date
129
+ self . image = image ?? base. image
130
+ self . author = author ?? base. author
131
+ self . keywords = keywords ?? base. keywords
132
+ self . twitter = twitter ?? base. twitter
133
+ self . locale = locale ?? base. locale
134
+ self . type = type ?? base. type
135
+ self . themeColor = themeColor ?? base. themeColor
136
+ }
137
+ }
0 commit comments