2022-08-19 18:05:06 +02:00
|
|
|
import Foundation
|
|
|
|
|
|
|
|
extension Element {
|
|
|
|
|
|
|
|
/**
|
|
|
|
Metadata localized for a specific language.
|
|
|
|
*/
|
|
|
|
struct LocalizedMetadata {
|
|
|
|
|
|
|
|
static let moreLinkDefaultText = "DefaultMoreText"
|
|
|
|
|
|
|
|
/**
|
|
|
|
The language for which the content is specified.
|
|
|
|
- Note: This field is mandatory
|
|
|
|
*/
|
|
|
|
let language: String
|
|
|
|
|
|
|
|
/**
|
|
|
|
- Note: This field is mandatory
|
|
|
|
The title used in the page header.
|
|
|
|
*/
|
|
|
|
let title: String
|
|
|
|
|
|
|
|
/**
|
|
|
|
The subtitle used in the page header.
|
|
|
|
*/
|
|
|
|
let subtitle: String?
|
|
|
|
|
|
|
|
/**
|
|
|
|
The description text used in the page header.
|
|
|
|
*/
|
|
|
|
let description: String?
|
|
|
|
|
|
|
|
/**
|
|
|
|
The title to use for the link preview.
|
|
|
|
|
|
|
|
If `nil` is specified, then the localized element `title` is used.
|
|
|
|
*/
|
|
|
|
let linkPreviewTitle: String
|
|
|
|
|
|
|
|
/**
|
|
|
|
The file name of the link preview image.
|
|
|
|
- Note: The image must be located in the element folder.
|
2022-08-26 17:40:51 +02:00
|
|
|
- Note: If `nil` is specified, then the (localized) thumbnail is used, if available.
|
2022-08-19 18:05:06 +02:00
|
|
|
*/
|
2022-08-26 17:40:51 +02:00
|
|
|
let linkPreviewImage: String?
|
2022-08-19 18:05:06 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
The description text for the link preview.
|
|
|
|
- Note: If `nil` is specified, then first the (localized) element `subtitle` is used.
|
|
|
|
If this is `nil` too, then the localized `description` of the element is used.
|
|
|
|
*/
|
|
|
|
let linkPreviewDescription: String
|
|
|
|
|
|
|
|
/**
|
|
|
|
The text on the link to show the section page when previewing multiple sections on an overview page.
|
|
|
|
- Note: If this value is inherited from the parent, if it is not defined. There must be at least one
|
|
|
|
element in the path that defines this property.
|
|
|
|
*/
|
2022-12-01 14:50:26 +01:00
|
|
|
let moreLinkText: String?
|
2022-08-19 18:05:06 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
The text on the back navigation link of **contained** elements.
|
|
|
|
|
|
|
|
This text does not appear on the section page, but on the pages contained within the section.
|
|
|
|
*/
|
|
|
|
let backLinkText: String
|
|
|
|
|
2022-08-26 17:40:51 +02:00
|
|
|
/**
|
|
|
|
The text on the back navigation link of the **parent** element.
|
|
|
|
|
|
|
|
This text appears on the section page, but not on the pages contained within the section.
|
|
|
|
*/
|
|
|
|
let parentBackLinkText: String
|
|
|
|
|
2022-08-19 18:05:06 +02:00
|
|
|
/**
|
|
|
|
The text to show as a title for placeholder boxes
|
|
|
|
|
|
|
|
Placeholders are included in missing pages.
|
|
|
|
- Note: If no value is specified, then this property is inherited from the parent. The root element must specify this property.
|
|
|
|
*/
|
|
|
|
let placeholderTitle: String
|
|
|
|
|
|
|
|
/**
|
|
|
|
The text to show as a description for placeholder boxes
|
|
|
|
|
|
|
|
Placeholders are included in missing pages.
|
|
|
|
- Note: If no value is specified, then this property is inherited from the parent. The root element must specify this property.
|
|
|
|
*/
|
|
|
|
let placeholderText: String
|
|
|
|
|
|
|
|
/**
|
|
|
|
An optional suffix to add to the title on a page.
|
|
|
|
|
|
|
|
This can be useful to express a different author, project grouping, etc.
|
|
|
|
*/
|
|
|
|
let titleSuffix: String?
|
|
|
|
|
|
|
|
/**
|
|
|
|
An optional suffix to add to the thumbnail title of a page.
|
|
|
|
|
|
|
|
This can be useful to express a different author, project grouping, etc.
|
|
|
|
*/
|
|
|
|
let thumbnailSuffix: String?
|
|
|
|
|
|
|
|
/**
|
|
|
|
A text to place in the top right corner of a large thumbnail.
|
|
|
|
|
|
|
|
The text should be a very short string to fit into the corner, like `soon`, or `draft`
|
|
|
|
|
|
|
|
- Note: This property is ignored if `thumbnailStyle` is not `large`.
|
|
|
|
*/
|
|
|
|
let cornerText: String?
|
|
|
|
|
|
|
|
/**
|
|
|
|
The external url to use instead of automatically generating the page.
|
|
|
|
|
|
|
|
This property can be used for links to other parts of the site, like additional services.
|
|
|
|
It can also be set to manually write a page.
|
|
|
|
*/
|
|
|
|
let externalUrl: String?
|
2022-09-25 17:19:07 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
The text to display for content related to the current page.
|
|
|
|
|
|
|
|
This property is mandatory at root level, and is propagated to child elements.
|
|
|
|
*/
|
|
|
|
let relatedContentText: String
|
2022-09-25 22:07:34 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
The text to display on the navigation element pointing to this element as the next page.
|
|
|
|
|
|
|
|
This property is mandatory at root level, and is propagated to child elements.
|
|
|
|
*/
|
|
|
|
let navigationTextAsNextPage: String
|
|
|
|
|
|
|
|
/**
|
|
|
|
The text to display on a navigation element pointing to this element as the previous page.
|
|
|
|
|
|
|
|
This property is mandatory at root level, and is propagated to child elements.
|
|
|
|
*/
|
|
|
|
let navigationTextAsPreviousPage: String
|
2022-08-19 18:05:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extension Element.LocalizedMetadata {
|
|
|
|
|
2022-12-01 14:50:26 +01:00
|
|
|
init?(atRoot folder: URL, data: GenericMetadata.LocalizedMetadata, log: MetadataInfoLogger) {
|
2022-08-19 18:05:06 +02:00
|
|
|
// Go through all elements and check them for completeness
|
|
|
|
// In the end, check that all required elements are present
|
2022-12-01 14:50:26 +01:00
|
|
|
var isValid = true
|
|
|
|
|
2022-08-19 18:05:06 +02:00
|
|
|
let source = "root"
|
2022-12-01 14:50:26 +01:00
|
|
|
self.language = log.required(data.language, name: "language", source: source, &isValid)
|
|
|
|
self.title = log.required(data.title, name: "title", source: source, &isValid)
|
2022-08-19 18:05:06 +02:00
|
|
|
self.subtitle = data.subtitle
|
|
|
|
self.description = data.description
|
|
|
|
self.linkPreviewTitle = data.linkPreviewTitle ?? data.title ?? ""
|
2022-12-01 14:50:26 +01:00
|
|
|
self.linkPreviewImage = data.linkPreviewImage
|
2022-08-29 17:22:24 +02:00
|
|
|
let linkPreviewDescription = data.linkPreviewDescription ?? data.description ?? data.subtitle
|
2022-12-01 14:50:26 +01:00
|
|
|
self.linkPreviewDescription = log.required(linkPreviewDescription, name: "linkPreviewDescription", source: source, &isValid)
|
|
|
|
self.moreLinkText = data.moreLinkText
|
|
|
|
self.backLinkText = log.required(data.backLinkText, name: "backLinkText", source: source, &isValid)
|
2022-08-26 17:40:51 +02:00
|
|
|
self.parentBackLinkText = "" // Root has no parent
|
2022-12-01 14:50:26 +01:00
|
|
|
self.placeholderTitle = log.required(data.placeholderTitle, name: "placeholderTitle", source: source, &isValid)
|
|
|
|
self.placeholderText = log.required(data.placeholderText, name: "placeholderText", source: source, &isValid)
|
2022-08-19 18:05:06 +02:00
|
|
|
self.titleSuffix = data.titleSuffix
|
2022-08-26 17:40:51 +02:00
|
|
|
self.thumbnailSuffix = log.unused(data.thumbnailSuffix, "thumbnailSuffix", source: source)
|
|
|
|
self.cornerText = log.unused(data.cornerText, "cornerText", source: source)
|
2022-12-01 14:50:26 +01:00
|
|
|
self.externalUrl = log.unused(data.externalUrl, "externalUrl", source: source)
|
|
|
|
self.relatedContentText = log.required(data.relatedContentText, name: "relatedContentText", source: source, &isValid)
|
|
|
|
self.navigationTextAsNextPage = log.required(data.navigationTextAsNextPage, name: "navigationTextAsNextPage", source: source, &isValid)
|
|
|
|
self.navigationTextAsPreviousPage = log.required(data.navigationTextAsPreviousPage, name: "navigationTextAsPreviousPage", source: source, &isValid)
|
|
|
|
|
|
|
|
guard isValid else {
|
2022-08-19 18:05:06 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-01 14:50:26 +01:00
|
|
|
init?(folder: URL, data: GenericMetadata.LocalizedMetadata, source: String, parent: Element.LocalizedMetadata, log: MetadataInfoLogger) {
|
2022-08-19 18:05:06 +02:00
|
|
|
// Go through all elements and check them for completeness
|
|
|
|
// In the end, check that all required elements are present
|
2022-12-01 14:50:26 +01:00
|
|
|
var isValid = true
|
|
|
|
|
2022-08-19 18:05:06 +02:00
|
|
|
self.language = parent.language
|
2022-12-01 14:50:26 +01:00
|
|
|
self.title = log.required(data.title, name: "title", source: source, &isValid)
|
2022-08-19 18:05:06 +02:00
|
|
|
self.subtitle = data.subtitle
|
|
|
|
self.description = data.description
|
|
|
|
self.linkPreviewTitle = data.linkPreviewTitle ?? data.title ?? ""
|
2022-12-01 14:50:26 +01:00
|
|
|
self.linkPreviewImage = data.linkPreviewImage
|
2022-08-29 17:22:24 +02:00
|
|
|
let linkPreviewDescription = data.linkPreviewDescription ?? data.description ?? data.subtitle
|
2022-12-01 14:50:26 +01:00
|
|
|
self.linkPreviewDescription = log.required(linkPreviewDescription, name: "linkPreviewDescription", source: source, &isValid)
|
|
|
|
self.moreLinkText = log.required(data.moreLinkText ?? parent.moreLinkText, name: "moreLinkText", source: source, &isValid)
|
2022-08-30 11:28:55 +02:00
|
|
|
self.backLinkText = data.backLinkText ?? data.title ?? ""
|
2022-08-26 17:40:51 +02:00
|
|
|
self.parentBackLinkText = parent.backLinkText
|
2022-08-19 18:05:06 +02:00
|
|
|
self.placeholderTitle = data.placeholderTitle ?? parent.placeholderTitle
|
|
|
|
self.placeholderText = data.placeholderText ?? parent.placeholderText
|
|
|
|
self.titleSuffix = data.titleSuffix
|
|
|
|
self.thumbnailSuffix = data.thumbnailSuffix
|
|
|
|
self.cornerText = data.cornerText
|
|
|
|
self.externalUrl = data.externalUrl
|
2022-09-25 17:19:07 +02:00
|
|
|
self.relatedContentText = data.relatedContentText ?? parent.relatedContentText
|
2022-09-25 22:07:34 +02:00
|
|
|
self.navigationTextAsPreviousPage = data.navigationTextAsPreviousPage ?? parent.navigationTextAsPreviousPage
|
|
|
|
self.navigationTextAsNextPage = data.navigationTextAsNextPage ?? parent.navigationTextAsNextPage
|
2022-08-19 18:05:06 +02:00
|
|
|
|
2022-12-01 14:50:26 +01:00
|
|
|
guard isValid else {
|
2022-08-19 18:05:06 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|