-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Part of #25.
- Loading branch information
Showing
4 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
Sources/Slipstream/Views/W3C/Elements/DocumentMetadata/Title.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import SwiftSoup | ||
|
||
/// A view that represents the document’s title or name. | ||
/// | ||
/// The content of this element sets the title displayed in the browser's title bar or tab, and | ||
/// is also used by search engines to identify the content of the page. A well-chosen title | ||
/// improves user experience and can significantly impact search engine optimization (SEO). | ||
/// | ||
/// ```swift | ||
/// struct MySiteMetadata: View { | ||
/// var body: some View { | ||
/// Head { | ||
/// Title("My awesome site") | ||
/// } | ||
/// } | ||
/// } | ||
/// ``` | ||
/// | ||
/// - SeeAlso: W3C [`title`](https://www.w3.org/TR/2012/WD-html-markup-20121025/title.html#title) specification. | ||
@available(iOS 17.0, macOS 14.0, *) | ||
public struct Title: View { | ||
/// Creates a Title view. | ||
public init(_ text: String) { | ||
self.text = text | ||
} | ||
|
||
@_documentation(visibility: private) | ||
public func render(_ container: Element, environment: EnvironmentValues) throws { | ||
let element = try container.appendElement("title") | ||
try element.appendText(text) | ||
} | ||
|
||
private let text: String | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import Testing | ||
|
||
import Slipstream | ||
|
||
struct TitleTests { | ||
@Test func emptyBlock() throws { | ||
try #expect(renderHTML(Title("")) == "<title></title>") | ||
} | ||
|
||
@Test func withText() throws { | ||
try #expect(renderHTML(Title("Hello, world!")) == "<title>Hello, world!</title>") | ||
} | ||
} |