CHGenerator/WebsiteGenerator/Generic/GenericMetadata+Localized.swift
2022-08-25 00:12:05 +02:00

208 lines
6.1 KiB
Swift

import Foundation
extension GenericMetadata {
/**
Metadata localized for a specific language.
*/
struct LocalizedMetadata {
/**
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.
- Note: If `nil` is specified, then the (localized) thumbnail is used.
*/
let linkPreviewImage: String?
/**
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.
*/
let moreLinkText: String?
/**
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.
- Note: If this property is not specified, then the root `backLinkText` is used.
- Note: The root element must specify this property.
*/
let backLinkText: String?
/**
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?
}
}
extension GenericMetadata.LocalizedMetadata: Codable {
private static var knownKeyList: [CodingKeys] {
[
.language,
.title,
.subtitle,
.description,
.linkPreviewTitle,
.linkPreviewImage,
.linkPreviewDescription,
.moreLinkText,
.backLinkText,
.placeholderTitle,
.placeholderText,
.titleSuffix,
.thumbnailSuffix,
.cornerText,
.externalUrl,
]
}
static var knownKeys: Set<String> {
Set(knownKeyList.map { $0.stringValue })
}
}
extension GenericMetadata.LocalizedMetadata {
/**
The mandatory minimum for a site element.
*/
static var mandatory: GenericMetadata.LocalizedMetadata {
.init(
language: "",
title: "",
subtitle: nil,
description: nil,
linkPreviewTitle: nil,
linkPreviewImage: nil,
linkPreviewDescription: nil,
moreLinkText: nil,
backLinkText: nil,
placeholderTitle: nil,
placeholderText: nil,
titleSuffix: nil,
thumbnailSuffix: nil,
cornerText: nil,
externalUrl: nil)
}
/**
The mandatory minimum for the root element of a site.
*/
static var mandatoryAtRoot: GenericMetadata.LocalizedMetadata {
.init(language: "",
title: "",
subtitle: nil,
description: nil,
linkPreviewTitle: nil,
linkPreviewImage: nil,
linkPreviewDescription: nil,
moreLinkText: nil,
backLinkText: "",
placeholderTitle: "",
placeholderText: "",
titleSuffix: nil,
thumbnailSuffix: nil,
cornerText: nil,
externalUrl: nil)
}
static var full: GenericMetadata.LocalizedMetadata {
.init(language: "",
title: "",
subtitle: "",
description: "",
linkPreviewTitle: "",
linkPreviewImage: "",
linkPreviewDescription: "",
moreLinkText: "",
backLinkText: "",
placeholderTitle: "",
placeholderText: "",
titleSuffix: "",
thumbnailSuffix: "",
cornerText: "",
externalUrl: "")
}
}