Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compatibility with Open Graph protocol #88

Merged
merged 3 commits into from
Apr 1, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Looking at the above, it may at first seem like Plot simply maps each function c
<head>
<title>My website</title>
<meta name="twitter:title" content="My website"/>
<meta name="og:title" content="My website"/>
<meta property="og:title" content="My website"/>
<link rel="stylesheet" href="styles.css" type="text/css"/>
</head>
<body>
Expand Down Expand Up @@ -588,4 +588,4 @@ This project does [not come with GitHub Issues-based support](CONTRIBUTING.md#bu

If you wish to make a change, [open a Pull Request](https://github.com/JohnSundell/Plot/pull/new) — even if it just contains a draft of the changes you’re planning, or a test that reproduces an issue — and we can discuss it further from there. See [Plot’s contribution guide](CONTRIBUTING.md) for more information about how to contribute to this project.

Hope you’ll enjoy using Plot!
Hope you’ll enjoy using Plot!
16 changes: 16 additions & 0 deletions Sources/Plot/API/HTMLAttributes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,22 @@ public extension Node where Context: HTMLNamableContext {
}
}

public extension Attribute where Context: HTMLNamableContext {
CoolONEOfficial marked this conversation as resolved.
Show resolved Hide resolved
/// Assign a property to the element.
/// - parameter property: The property to assign.
static func property(_ property: String) -> Attribute {
Attribute(name: "property", value: property)
}
}

public extension Node where Context: HTMLNamableContext {
CoolONEOfficial marked this conversation as resolved.
Show resolved Hide resolved
/// Assign a property to the element.
/// - parameter property: The property to assign.
static func property(_ property: String) -> Node {
.attribute(named: "property", value: property)
}
}

public extension Attribute where Context: HTMLTypeContext {
/// Assign a type string to this element.
/// - parameter type: The name of the type to assign.
Expand Down
10 changes: 5 additions & 5 deletions Sources/Plot/API/HTMLComponents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ public extension Node where Context == HTML.HeadContext {
return .group([
.link(.rel(.canonical), .href(url)),
.meta(.name("twitter:url"), .content(url)),
.meta(.name("og:url"), .content(url))
.meta(.property("og:url"), .content(url))
])
}

/// Declare the name of the site that this HTML page belongs to.
/// - parameter name: The name to declare.
static func siteName(_ name: String) -> Node {
.meta(.name("og:site_name"), .content(name))
.meta(.property("og:site_name"), .content(name))
}

/// Declare the HTML page's title, both for browsers and for social sharing.
Expand All @@ -49,7 +49,7 @@ public extension Node where Context == HTML.HeadContext {
.group([
.element(named: "title", text: title),
.meta(.name("twitter:title"), .content(title)),
.meta(.name("og:title"), .content(title))
.meta(.property("og:title"), .content(title))
])
}

Expand All @@ -59,7 +59,7 @@ public extension Node where Context == HTML.HeadContext {
.group([
.meta(.name("description"), .content(text)),
.meta(.name("twitter:description"), .content(text)),
.meta(.name("og:description"), .content(text))
.meta(.property("og:description"), .content(text))
])
}

Expand All @@ -71,7 +71,7 @@ public extension Node where Context == HTML.HeadContext {

return .group([
.meta(.name("twitter:image"), .content(url)),
.meta(.name("og:image"), .content(url))
.meta(.property("og:image"), .content(url))
])
}

Expand Down
10 changes: 5 additions & 5 deletions Tests/PlotTests/HTMLTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ final class HTMLTests: XCTestCase {
func testSiteName() {
let html = HTML(.head(.siteName("MySite")))
assertEqualHTMLContent(html, """
<head><meta name="og:site_name" content="MySite"/></head>
<head><meta property="og:site_name" content="MySite"/></head>
""")
}

Expand All @@ -58,7 +58,7 @@ final class HTMLTests: XCTestCase {
<head>\
<link rel="canonical" href="url.com"/>\
<meta name="twitter:url" content="url.com"/>\
<meta name="og:url" content="url.com"/>\
<meta property="og:url" content="url.com"/>\
</head>
""")
}
Expand All @@ -69,7 +69,7 @@ final class HTMLTests: XCTestCase {
<head>\
<title>Title</title>\
<meta name="twitter:title" content="Title"/>\
<meta name="og:title" content="Title"/>\
<meta property="og:title" content="Title"/>\
</head>
""")
}
Expand All @@ -80,7 +80,7 @@ final class HTMLTests: XCTestCase {
<head>\
<meta name="description" content="Description"/>\
<meta name="twitter:description" content="Description"/>\
<meta name="og:description" content="Description"/>\
<meta property="og:description" content="Description"/>\
</head>
""")
}
Expand All @@ -94,7 +94,7 @@ final class HTMLTests: XCTestCase {
assertEqualHTMLContent(html, """
<head>\
<meta name="twitter:image" content="url.png"/>\
<meta name="og:image" content="url.png"/>\
<meta property="og:image" content="url.png"/>\
<meta name="twitter:card" content="summary_large_image"/>\
</head>
""")
Expand Down