Check page state for overviews
This commit is contained in:
parent
04272c620e
commit
fff62f4b44
@ -250,11 +250,23 @@ extension Element {
|
|||||||
elements.contains { $0.containsElements }
|
elements.contains { $0.containsElements }
|
||||||
}
|
}
|
||||||
|
|
||||||
var sortedItems: [Element] {
|
func itemsForOverview(_ count: Int? = nil) -> [Element] {
|
||||||
if useManualSorting {
|
if let shownItemCount = count {
|
||||||
return elements.sorted { $0.sortIndex! < $1.sortIndex! }
|
return Array(sortedItems.prefix(shownItemCount))
|
||||||
|
} else {
|
||||||
|
return sortedItems
|
||||||
}
|
}
|
||||||
return elements.sorted { $0.date! > $1.date! }
|
}
|
||||||
|
|
||||||
|
private var sortedItems: [Element] {
|
||||||
|
if useManualSorting {
|
||||||
|
return shownItems.sorted { $0.sortIndex! < $1.sortIndex! }
|
||||||
|
}
|
||||||
|
return shownItems.sorted { $0.date! > $1.date! }
|
||||||
|
}
|
||||||
|
|
||||||
|
private var shownItems: [Element] {
|
||||||
|
elements.filter { $0.state.isShownInOverview }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -340,9 +352,9 @@ extension Element {
|
|||||||
/**
|
/**
|
||||||
Get the next language to switch to with the language button.
|
Get the next language to switch to with the language button.
|
||||||
*/
|
*/
|
||||||
func nextLanguage(for languageIdentifier: String) -> String? {
|
func nextLanguage(for language: String) -> String? {
|
||||||
let langs = languages.map { $0.language }
|
let langs = languages.map { $0.language }
|
||||||
guard let index = langs.firstIndex(of: languageIdentifier) else {
|
guard let index = langs.firstIndex(of: language) else {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
for i in 1..<langs.count {
|
for i in 1..<langs.count {
|
||||||
@ -350,7 +362,7 @@ extension Element {
|
|||||||
guard hasContent(for: next) else {
|
guard hasContent(for: next) else {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
guard next != languageIdentifier else {
|
guard next != language else {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -393,7 +405,10 @@ extension Element {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func hasContent(for language: String) -> Bool {
|
private func hasContent(for language: String) -> Bool {
|
||||||
existingContentUrl(for: language) != nil
|
if !elements.isEmpty {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return existingContentUrl(for: language) != nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,3 +16,26 @@ enum PageState: String {
|
|||||||
*/
|
*/
|
||||||
case hide
|
case hide
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension PageState {
|
||||||
|
|
||||||
|
var isShownInOverview: Bool {
|
||||||
|
switch self {
|
||||||
|
case .standard, .draft:
|
||||||
|
return true
|
||||||
|
case .hide:
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var hasThumbnailLink: Bool {
|
||||||
|
switch self {
|
||||||
|
case .standard:
|
||||||
|
return true
|
||||||
|
case .draft:
|
||||||
|
return false
|
||||||
|
case .hide:
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -23,7 +23,11 @@ struct OverviewSectionGenerator {
|
|||||||
var content = [OverviewSectionTemplate.Key : String]()
|
var content = [OverviewSectionTemplate.Key : String]()
|
||||||
content[.url] = relativeUrl
|
content[.url] = relativeUrl
|
||||||
content[.title] = metadata.title
|
content[.title] = metadata.title
|
||||||
content[.items] = sectionContent(section: section, in: parent, language: language, shownItemCount: sectionItemCount)
|
content[.items] = generator.generateContent(
|
||||||
|
items: section.itemsForOverview(sectionItemCount),
|
||||||
|
parent: parent,
|
||||||
|
language: language,
|
||||||
|
style: section.thumbnailStyle)
|
||||||
content[.more] = metadata.moreLinkText
|
content[.more] = metadata.moreLinkText
|
||||||
|
|
||||||
return multipleSectionsTemplate.generate(content)
|
return multipleSectionsTemplate.generate(content)
|
||||||
@ -33,21 +37,11 @@ struct OverviewSectionGenerator {
|
|||||||
|
|
||||||
func generate(section: Element, language: String) -> String {
|
func generate(section: Element, language: String) -> String {
|
||||||
var content = [OverviewSectionCleanTemplate.Key : String]()
|
var content = [OverviewSectionCleanTemplate.Key : String]()
|
||||||
content[.items] = sectionContent(section: section, in: section, language: language, shownItemCount: nil)
|
content[.items] = generator.generateContent(
|
||||||
return singleSectionsTemplate.generate(content)
|
items: section.itemsForOverview(),
|
||||||
}
|
parent: section,
|
||||||
|
|
||||||
private func sectionContent(section: Element, in parent: Element, language: String, shownItemCount: Int?) -> String {
|
|
||||||
let sectionItems: [Element]
|
|
||||||
if let shownItemCount = shownItemCount {
|
|
||||||
sectionItems = Array(section.sortedItems.prefix(shownItemCount))
|
|
||||||
} else {
|
|
||||||
sectionItems = section.sortedItems
|
|
||||||
}
|
|
||||||
return generator.generateContent(
|
|
||||||
items: sectionItems,
|
|
||||||
parent: parent,
|
|
||||||
language: language,
|
language: language,
|
||||||
style: section.thumbnailStyle)
|
style: section.thumbnailStyle)
|
||||||
|
return singleSectionsTemplate.generate(content)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,13 +14,18 @@ struct ThumbnailListGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func itemContent(_ item: Element, parent: Element, language: String, style: ThumbnailStyle) -> String {
|
private func itemContent(_ item: Element, parent: Element, language: String, style: ThumbnailStyle) -> String {
|
||||||
let fullPageUrl = item.fullPageUrl(for: language)
|
|
||||||
let relativePageUrl = parent.relativePathToFileWithPath(fullPageUrl)
|
|
||||||
let fullThumbnailPath = item.thumbnailFilePath(for: language)
|
let fullThumbnailPath = item.thumbnailFilePath(for: language)
|
||||||
let relativeImageUrl = parent.relativePathToFileWithPath(fullThumbnailPath)
|
let relativeImageUrl = parent.relativePathToFileWithPath(fullThumbnailPath)
|
||||||
|
|
||||||
var content = [ThumbnailKey : String]()
|
var content = [ThumbnailKey : String]()
|
||||||
|
|
||||||
|
if item.state.hasThumbnailLink {
|
||||||
|
#warning("If page in language is missing, link to different language")
|
||||||
|
let fullPageUrl = item.fullPageUrl(for: language)
|
||||||
|
let relativePageUrl = parent.relativePathToFileWithPath(fullPageUrl)
|
||||||
content[.url] = "href=\"\(relativePageUrl)\""
|
content[.url] = "href=\"\(relativePageUrl)\""
|
||||||
|
}
|
||||||
|
|
||||||
content[.image] = relativeImageUrl
|
content[.image] = relativeImageUrl
|
||||||
content[.title] = item.title(for: language)
|
content[.title] = item.title(for: language)
|
||||||
#warning("Generate thumbnail suffix")
|
#warning("Generate thumbnail suffix")
|
||||||
|
Loading…
Reference in New Issue
Block a user