Skip to content

Commit

Permalink
Eliminate the userDefined. prefix and the .data file (#20)
Browse files Browse the repository at this point in the history
- Eliminates the `{{userDefined.xyz}}` prefix -> `{{xyz}}`
- Eliminate the `index.data.yml` files, data should be moved to the
`index.yml`
    NOTE: the index.yml and the index.md files can be separate.
- Remove unnecessary `import Yams`
- Minor log metadata fixes: content -> slug
  • Loading branch information
tib authored Oct 7, 2024
1 parent 97f611c commit e58dd43
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 41 deletions.
2 changes: 0 additions & 2 deletions Sources/ToucanSDK/Parsers/FrontMatterParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
// Created by Tibor Bodecs on 03/05/2024.
//

import Yams

struct FrontMatterParser {

func parse(
Expand Down
6 changes: 2 additions & 4 deletions Sources/ToucanSDK/Site/SiteRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -505,18 +505,17 @@ struct SiteRenderer {
userDefined: pageBundle.userDefined
.recursivelyMerged(with: source.config.site.userDefined)
.sanitized(),
data: pageBundle.data,
pagination: .init(
links: paginationContext,
data: paginationData.mapValues {
$0.map { getContext(pageBundle: $0) }
}
),
year: currentYear
),
)
.context,
to: fileUrl
)

}

// MARK: - render related methods
Expand Down Expand Up @@ -624,7 +623,6 @@ struct SiteRenderer {
assets: pageBundle.assets,
redirects: pageBundle.redirects,
userDefined: pageBundle.userDefined,
data: pageBundle.data,
context: .init(
slug: finalSlug,
permalink: finalPermalink,
Expand Down
18 changes: 11 additions & 7 deletions Sources/ToucanSDK/Site/Types/Output+HTML.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@ struct Context {
let isCurrent: Bool
}

// let home: Link?
// let first: Link?
// let prev: Link?
// let next: Link?
// let last: Link?

let links: [String: [Link]]
let data: [String: Any]
}
Expand All @@ -41,7 +35,17 @@ struct HTML: Output {
let site: Context.Site
let page: [String: Any]
let userDefined: [String: Any]
let data: [[String: Any]]
let pagination: Context.Pagination
let year: Int

var context: [String: Any] {
userDefined.recursivelyMerged(
with: [
"site": site,
"page": page,
"pagination": pagination,
]
)
.sanitized()
}
}
1 change: 0 additions & 1 deletion Sources/ToucanSDK/Source/PageBundle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ struct PageBundle {
let redirects: [Redirect]

let userDefined: [String: Any]
let data: [[String: Any]]

let context: Context

Expand Down
38 changes: 11 additions & 27 deletions Sources/ToucanSDK/Source/PageBundleLoader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import Foundation
import FileManagerKit
import Logging
import Yams

extension String {

Expand Down Expand Up @@ -199,18 +198,6 @@ public struct PageBundleLoader {
return frontMatter.recursivelyMerged(with: overrides)
}

func loadData(
id: String,
dirUrl: URL
) throws -> [[String: Any]] {
/// load additional data files for data definitions
try Yaml.load(
at: dirUrl,
name: "\(id).data",
fileManager: fileManager
)
}

func convert(
date: Date
) -> PageBundle.Context.DateValue {
Expand Down Expand Up @@ -369,11 +356,6 @@ public struct PageBundleLoader {
rawMarkdown: rawMarkdown
)

let data = try loadData(
id: indexName,
dirUrl: dirUrl
)

/// filter out drafts
if draft(frontMatter: frontMatter) {
logger.debug("Page bundle is a draft.", metadata: metadata)
Expand Down Expand Up @@ -513,7 +495,6 @@ public struct PageBundleLoader {
assets: .init(path: assetsPath),
redirects: redirects,
userDefined: userDefined,
data: data,
context: context
)
}
Expand All @@ -530,23 +511,26 @@ extension PageBundleLoader {
for contentType: ContentType,
at slug: String
) {
let metadata: Logger.Metadata = [
"slug": "\(slug)"
]
// properties
for property in contentType.properties ?? [:] {
if frontMatter[property.key] == nil {
logger.warning("Missing content type property", metadata: [
"content": "\(slug)",
"property": "\(property.key)"
])
logger.warning(
"Missing content type property: `\(property.key)`",
metadata: metadata
)
}
}

// relations
for relation in contentType.relations ?? [:] {
if frontMatter[relation.key] == nil {
logger.warning("Missing content type relation", metadata: [
"content": "\(slug)",
"relation": "\(relation.key)"
])
logger.warning(
"Missing content type relation: `\(relation.key)`",
metadata: metadata
)
}
}
}
Expand Down

0 comments on commit e58dd43

Please sign in to comment.