From d316d32588f708e9dcdf8ec58b041192776a86a4 Mon Sep 17 00:00:00 2001 From: Vithanco Date: Sat, 13 May 2023 06:14:23 +0200 Subject: [PATCH 01/19] making file location more accessible --- Sources/Publish/API/HTMLFileMode.swift | 15 +++++++++++++++ Sources/Publish/Internal/HTMLGenerator.swift | 7 +------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/Sources/Publish/API/HTMLFileMode.swift b/Sources/Publish/API/HTMLFileMode.swift index ab26aac6..174407cb 100644 --- a/Sources/Publish/API/HTMLFileMode.swift +++ b/Sources/Publish/API/HTMLFileMode.swift @@ -15,3 +15,18 @@ public enum HTMLFileMode { /// `section/item` becomes `section/item/index.html`. case foldersAndIndexFiles } + + +extension HTMLFileMode { + + ///Determining the right file name based on HTMLFileMode + public func filePath(for location: Location) -> Path { + switch self { + case .foldersAndIndexFiles: + return "\(location.path)/index.html" + case .standAloneFiles: + return "\(location.path).html" + } + } + +} diff --git a/Sources/Publish/Internal/HTMLGenerator.swift b/Sources/Publish/Internal/HTMLGenerator.swift index 411bf428..9339fd0b 100644 --- a/Sources/Publish/Internal/HTMLGenerator.swift +++ b/Sources/Publish/Internal/HTMLGenerator.swift @@ -141,11 +141,6 @@ private extension HTMLGenerator { } func filePath(for location: Location, fileMode: HTMLFileMode) -> Path { - switch fileMode { - case .foldersAndIndexFiles: - return "\(location.path)/index.html" - case .standAloneFiles: - return "\(location.path).html" - } + return fileMode.filePath(for: location) } } From cf9b425d2f16c9ec4911c533a590fc9c428803b1 Mon Sep 17 00:00:00 2001 From: Vithanco Date: Sat, 13 May 2023 08:13:36 +0200 Subject: [PATCH 02/19] allowing Path instead of Location for HTMLFileMode --- Sources/Publish/API/HTMLFileMode.swift | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Sources/Publish/API/HTMLFileMode.swift b/Sources/Publish/API/HTMLFileMode.swift index 174407cb..81b45f44 100644 --- a/Sources/Publish/API/HTMLFileMode.swift +++ b/Sources/Publish/API/HTMLFileMode.swift @@ -21,11 +21,16 @@ extension HTMLFileMode { ///Determining the right file name based on HTMLFileMode public func filePath(for location: Location) -> Path { + return filePath(path: location.path) + } + + ///Determining the right file name based on HTMLFileMode + public func filePath(path: Path) -> Path { switch self { case .foldersAndIndexFiles: - return "\(location.path)/index.html" + return "\(path)/index.html" case .standAloneFiles: - return "\(location.path).html" + return "\(path).html" } } From 75b3abb818d544e45763f7c29ca8f2bb5a6e8ff9 Mon Sep 17 00:00:00 2001 From: Vithanco Date: Sun, 25 Jun 2023 11:08:36 +0200 Subject: [PATCH 03/19] Update Package.swift switch to my forks to not being held back by Sundell's absense --- Package.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Package.swift b/Package.swift index f81064cc..8fe5f5db 100644 --- a/Package.swift +++ b/Package.swift @@ -23,7 +23,7 @@ let package = Package( ), .package( name: "Plot", - url: "https://github.com/johnsundell/plot.git", + url: "https://github.com/Vithanco/plot.git", from: "0.9.0" ), .package( From bf0243a1c0f3290d234101865dfe4bbca2b8f67f Mon Sep 17 00:00:00 2001 From: Vithanco Date: Sun, 25 Jun 2023 11:10:38 +0200 Subject: [PATCH 04/19] Update Package.swift switching to my forks --- Package.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Package.swift b/Package.swift index 8fe5f5db..c41251ef 100644 --- a/Package.swift +++ b/Package.swift @@ -18,7 +18,7 @@ let package = Package( dependencies: [ .package( name: "Ink", - url: "https://github.com/johnsundell/ink.git", + url: "https://github.com/Vithanco/ink.git", from: "0.2.0" ), .package( From 59ed24db6d97ab191d138a6644ce2dd82a21f2e5 Mon Sep 17 00:00:00 2001 From: Vithanco Date: Thu, 10 Aug 2023 20:59:43 +0200 Subject: [PATCH 05/19] mostly about fileMode --- Package.resolved | 8 +- Package.swift | 4 +- Sources/Publish/API/PublishingContext.swift | 11 ++ Sources/Publish/API/PublishingStep.swift | 4 +- Sources/Publish/API/Website.swift | 139 +++++++++++-------- Sources/Publish/Internal/HTMLGenerator.swift | 4 +- 6 files changed, 99 insertions(+), 71 deletions(-) diff --git a/Package.resolved b/Package.resolved index d3d55a8b..65e76174 100644 --- a/Package.resolved +++ b/Package.resolved @@ -33,8 +33,8 @@ "repositoryURL": "https://github.com/johnsundell/ink.git", "state": { "branch": null, - "revision": "77c3d8953374a9cf5418ef0bd7108524999de85a", - "version": "0.5.1" + "revision": "bcc9f219900a62c4210e6db726035d7f03ae757b", + "version": "0.6.0" } }, { @@ -42,8 +42,8 @@ "repositoryURL": "https://github.com/johnsundell/plot.git", "state": { "branch": null, - "revision": "80612b34252188edbef280e5375e2fc5249ac770", - "version": "0.9.0" + "revision": "271926b4413fe868739d99f5eadcf2bd6cd62fb8", + "version": "0.14.0" } }, { diff --git a/Package.swift b/Package.swift index c41251ef..f81064cc 100644 --- a/Package.swift +++ b/Package.swift @@ -18,12 +18,12 @@ let package = Package( dependencies: [ .package( name: "Ink", - url: "https://github.com/Vithanco/ink.git", + url: "https://github.com/johnsundell/ink.git", from: "0.2.0" ), .package( name: "Plot", - url: "https://github.com/Vithanco/plot.git", + url: "https://github.com/johnsundell/plot.git", from: "0.9.0" ), .package( diff --git a/Sources/Publish/API/PublishingContext.swift b/Sources/Publish/API/PublishingContext.swift index 4dd14caa..96a329bd 100644 --- a/Sources/Publish/API/PublishingContext.swift +++ b/Sources/Publish/API/PublishingContext.swift @@ -379,3 +379,14 @@ private extension PublishingContext { } } } + + +public extension PublishingContext { + var fileMode: HTMLFileMode { + return site.fileMode + } + + func tag2htmlfileName(tag: Tag) -> String { + return site.tag2htmlfileName(tag: tag) + } +} diff --git a/Sources/Publish/API/PublishingStep.swift b/Sources/Publish/API/PublishingStep.swift index 63e8a7b0..336fc355 100644 --- a/Sources/Publish/API/PublishingStep.swift +++ b/Sources/Publish/API/PublishingStep.swift @@ -363,14 +363,12 @@ public extension PublishingStep { /// - parameter fileMode: The mode to use when generating each HTML file. static func generateHTML( withTheme theme: Theme, - indentation: Indentation.Kind? = nil, - fileMode: HTMLFileMode = .foldersAndIndexFiles + indentation: Indentation.Kind? = nil ) -> Self { step(named: "Generate HTML") { context in let generator = HTMLGenerator( theme: theme, indentation: indentation, - fileMode: fileMode, context: context ) diff --git a/Sources/Publish/API/Website.swift b/Sources/Publish/API/Website.swift index fd4c5b8c..31602ffb 100644 --- a/Sources/Publish/API/Website.swift +++ b/Sources/Publish/API/Website.swift @@ -41,6 +41,8 @@ public protocol Website { /// The configuration to use when generating tag HTML for the website. /// If this is `nil`, then no tag HTML will be generated. var tagHTMLConfig: TagHTMLConfiguration? { get } + + var fileMode: HTMLFileMode {get} } // MARK: - Defaults @@ -130,67 +132,67 @@ public extension Website { semaphore.wait() return try result!.get() } - - /// Publish this website using a default pipeline. To build a completely - /// custom pipeline, use the `publish(using:)` method. - /// - parameter theme: The HTML theme to generate the website using. - /// - parameter indentation: How to indent the generated files. - /// - parameter path: Any specific path to generate the website at. - /// - parameter rssFeedSections: What sections to include in the site's RSS feed. - /// - parameter rssFeedConfig: The configuration to use for the site's RSS feed. - /// - parameter deploymentMethod: How to deploy the website. - /// - parameter additionalSteps: Any additional steps to add to the publishing - /// pipeline. Will be executed right before the HTML generation process begins. - /// - parameter plugins: Plugins to be installed at the start of the publishing process. - /// - parameter file: The file that this method is called from (auto-inserted). - /// - parameter line: The line that this method is called from (auto-inserted). - @discardableResult - func publish(withTheme theme: Theme, - indentation: Indentation.Kind? = nil, - at path: Path? = nil, - rssFeedSections: Set = Set(SectionID.allCases), - rssFeedConfig: RSSFeedConfiguration? = .default, - deployedUsing deploymentMethod: DeploymentMethod? = nil, - additionalSteps: [PublishingStep] = [], - plugins: [Plugin] = [], - file: StaticString = #file) async throws -> PublishedWebsite { - try await publish( - at: path, - using: [ - .group(plugins.map(PublishingStep.installPlugin)), - .optional(.copyResources()), - .addMarkdownFiles(), - .sortItems(by: \.date, order: .descending), - .group(additionalSteps), - .generateHTML(withTheme: theme, indentation: indentation), - .unwrap(rssFeedConfig) { config in - .generateRSSFeed( - including: rssFeedSections, - config: config - ) - }, - .generateSiteMap(indentedBy: indentation), - .unwrap(deploymentMethod, PublishingStep.deploy) - ], - file: file - ) - } - - /// Publish this website using a custom pipeline. - /// - parameter path: Any specific path to generate the website at. - /// - parameter steps: The steps to use to form the website's publishing pipeline. - /// - parameter file: The file that this method is called from (auto-inserted). - /// - parameter line: The line that this method is called from (auto-inserted). - @discardableResult - func publish(at path: Path? = nil, - using steps: [PublishingStep], - file: StaticString = #file) async throws -> PublishedWebsite { - let pipeline = PublishingPipeline( - steps: steps, - originFilePath: Path("\(file)") - ) - return try await pipeline.execute(for: self, at: path) - } +// +// /// Publish this website using a default pipeline. To build a completely +// /// custom pipeline, use the `publish(using:)` method. +// /// - parameter theme: The HTML theme to generate the website using. +// /// - parameter indentation: How to indent the generated files. +// /// - parameter path: Any specific path to generate the website at. +// /// - parameter rssFeedSections: What sections to include in the site's RSS feed. +// /// - parameter rssFeedConfig: The configuration to use for the site's RSS feed. +// /// - parameter deploymentMethod: How to deploy the website. +// /// - parameter additionalSteps: Any additional steps to add to the publishing +// /// pipeline. Will be executed right before the HTML generation process begins. +// /// - parameter plugins: Plugins to be installed at the start of the publishing process. +// /// - parameter file: The file that this method is called from (auto-inserted). +// /// - parameter line: The line that this method is called from (auto-inserted). +// @discardableResult +// func publish(withTheme theme: Theme, +// indentation: Indentation.Kind? = nil, +// at path: Path? = nil, +// rssFeedSections: Set = Set(SectionID.allCases), +// rssFeedConfig: RSSFeedConfiguration? = .default, +// deployedUsing deploymentMethod: DeploymentMethod? = nil, +// additionalSteps: [PublishingStep] = [], +// plugins: [Plugin] = [], +// file: StaticString = #file) async throws -> PublishedWebsite { +// try await publish( +// at: path, +// using: [ +// .group(plugins.map(PublishingStep.installPlugin)), +// .optional(.copyResources()), +// .addMarkdownFiles(), +// .sortItems(by: \.date, order: .descending), +// .group(additionalSteps), +// .generateHTML(withTheme: theme, indentation: indentation), +// .unwrap(rssFeedConfig) { config in +// .generateRSSFeed( +// including: rssFeedSections, +// config: config +// ) +// }, +// .generateSiteMap(indentedBy: indentation), +// .unwrap(deploymentMethod, PublishingStep.deploy) +// ], +// file: file +// ) +// } +// +// /// Publish this website using a custom pipeline. +// /// - parameter path: Any specific path to generate the website at. +// /// - parameter steps: The steps to use to form the website's publishing pipeline. +// /// - parameter file: The file that this method is called from (auto-inserted). +// /// - parameter line: The line that this method is called from (auto-inserted). +// @discardableResult +// func publish(at path: Path? = nil, +// using steps: [PublishingStep], +// file: StaticString = #file) async throws -> PublishedWebsite { +// let pipeline = PublishingPipeline( +// steps: steps, +// originFilePath: Path("\(file)") +// ) +// return try await pipeline.execute(for: self, at: path) +// } } // MARK: - Paths and URLs @@ -233,3 +235,18 @@ public extension Website { url(for: location.path) } } + + +extension Website { + public func tag2htmlfileName(tag: Tag) -> String { + let result = self.fileMode.filePath(path: self.path(for: tag)).absoluteString + debugPrint("tag2htmlfileName: \(tag) -> \(result)") + return result + } + + public func item2htmlfileName(item: Item) -> String { + let result = self.fileMode.filePath(path: item.path).absoluteString + debugPrint("item2htmlfileName: \(item) -> \(result)") + return result + } +} diff --git a/Sources/Publish/Internal/HTMLGenerator.swift b/Sources/Publish/Internal/HTMLGenerator.swift index 9339fd0b..9332120a 100644 --- a/Sources/Publish/Internal/HTMLGenerator.swift +++ b/Sources/Publish/Internal/HTMLGenerator.swift @@ -11,7 +11,9 @@ import CollectionConcurrencyKit internal struct HTMLGenerator { let theme: Theme let indentation: Indentation.Kind? - let fileMode: HTMLFileMode + var fileMode: HTMLFileMode { + return context.fileMode + } let context: PublishingContext func generate() async throws { From f4fabe5af3b03110404e98a0ec58946ad4ee0cff Mon Sep 17 00:00:00 2001 From: Vithanco Date: Thu, 10 Aug 2023 21:42:24 +0200 Subject: [PATCH 06/19] Update Package.swift changed Plot dependency version to 0.14.0 --- Package.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Package.swift b/Package.swift index f81064cc..ac3f3f1b 100644 --- a/Package.swift +++ b/Package.swift @@ -24,7 +24,7 @@ let package = Package( .package( name: "Plot", url: "https://github.com/johnsundell/plot.git", - from: "0.9.0" + from: "0.14.0" ), .package( name: "Files", From b4f8806a4dbb4265bc67b62d62418fa7f9886762 Mon Sep 17 00:00:00 2001 From: Vithanco Date: Thu, 10 Aug 2023 21:44:48 +0200 Subject: [PATCH 07/19] Changed to Vithanco Tech Stack --- Package.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Package.swift b/Package.swift index ac3f3f1b..1d0916a1 100644 --- a/Package.swift +++ b/Package.swift @@ -23,7 +23,7 @@ let package = Package( ), .package( name: "Plot", - url: "https://github.com/johnsundell/plot.git", + url: "https://github.com/vithanco/plot.git", from: "0.14.0" ), .package( From ac198634de403e5d33ddc1267ce9c6501d632759 Mon Sep 17 00:00:00 2001 From: Vithanco Date: Mon, 14 Aug 2023 10:54:38 +0200 Subject: [PATCH 08/19] switch to own tech stack changed to vithanvo/Ink --- Package.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Package.swift b/Package.swift index 1d0916a1..ea619ee0 100644 --- a/Package.swift +++ b/Package.swift @@ -18,8 +18,8 @@ let package = Package( dependencies: [ .package( name: "Ink", - url: "https://github.com/johnsundell/ink.git", - from: "0.2.0" + url: "https://github.com/vithanco/ink.git", + from: "0.6.1" ), .package( name: "Plot", From 255e808365b8afb6d7812ee4dae79e4ad8a6f6b1 Mon Sep 17 00:00:00 2001 From: Vithanco Date: Sat, 19 Aug 2023 20:51:42 +0200 Subject: [PATCH 09/19] tests are working again --- .gitignore | 1 + Package.resolved | 4 ++-- .../Infrastructure/PublishTestCase.swift | 14 +++++++++----- .../PublishTests/Infrastructure/WebsiteStub.swift | 1 + Tests/PublishTests/Tests/HTMLGenerationTests.swift | 4 ++-- Tests/PublishTests/Tests/PlotComponentTests.swift | 4 ++-- 6 files changed, 17 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index a8ce1bfe..fd41ba09 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ .swiftpm /*.xcodeproj xcuserdata/ +.vscode diff --git a/Package.resolved b/Package.resolved index 65e76174..f50650c7 100644 --- a/Package.resolved +++ b/Package.resolved @@ -39,10 +39,10 @@ }, { "package": "Plot", - "repositoryURL": "https://github.com/johnsundell/plot.git", + "repositoryURL": "https://github.com/vithanco/plot.git", "state": { "branch": null, - "revision": "271926b4413fe868739d99f5eadcf2bd6cd62fb8", + "revision": "2aa5c4bfdab0b9d097047ba7e812d06791c3d518", "version": "0.14.0" } }, diff --git a/Tests/PublishTests/Infrastructure/PublishTestCase.swift b/Tests/PublishTests/Infrastructure/PublishTestCase.swift index c9f12ef5..8317c99d 100644 --- a/Tests/PublishTests/Infrastructure/PublishTestCase.swift +++ b/Tests/PublishTests/Infrastructure/PublishTestCase.swift @@ -14,13 +14,15 @@ class PublishTestCase: XCTestCase { func publishWebsite( in folder: Folder? = nil, using steps: [PublishingStep], - content: [Path : String] = [:] + content: [Path : String] = [:], + fileMode: HTMLFileMode = .foldersAndIndexFiles ) throws -> PublishedWebsite { try performWebsitePublishing( in: folder, using: steps, files: content, - filePathPrefix: "Content/" + filePathPrefix: "Content/", + fileMode : fileMode ) } @@ -197,13 +199,15 @@ private extension PublishTestCase { in folder: Folder? = nil, using steps: [PublishingStep], files: [Path : String], - filePathPrefix: String = "" + filePathPrefix: String = "", + fileMode: HTMLFileMode = .foldersAndIndexFiles ) throws -> PublishedWebsite { let folder = try folder ?? Folder.createTemporary() try addFiles(withContent: files, to: folder, pathPrefix: filePathPrefix) - - return try T().publish( + var site = T() + site.fileMode = fileMode + return try site.publish( at: Path(folder.path), using: steps ) diff --git a/Tests/PublishTests/Infrastructure/WebsiteStub.swift b/Tests/PublishTests/Infrastructure/WebsiteStub.swift index 09c3638f..13a690e6 100644 --- a/Tests/PublishTests/Infrastructure/WebsiteStub.swift +++ b/Tests/PublishTests/Infrastructure/WebsiteStub.swift @@ -20,6 +20,7 @@ class WebsiteStub { var imagePath: Path? = nil var faviconPath: Path? = nil var tagHTMLConfig: TagHTMLConfiguration? = .default + var fileMode: Publish.HTMLFileMode = .foldersAndIndexFiles required init() {} diff --git a/Tests/PublishTests/Tests/HTMLGenerationTests.swift b/Tests/PublishTests/Tests/HTMLGenerationTests.swift index 2afca997..67145fb4 100644 --- a/Tests/PublishTests/Tests/HTMLGenerationTests.swift +++ b/Tests/PublishTests/Tests/HTMLGenerationTests.swift @@ -262,8 +262,8 @@ final class HTMLGenerationTests: PublishTestCase { try publishWebsite(in: folder, using: [ .addItem(Item.stub(withPath: "item").setting(\.tags, to: ["tag"])), .addItem(Item.stub(withPath: "rawValueItem", sectionID: .customRawValue).setting(\.tags, to: ["tag"])), - .generateHTML(withTheme: theme, fileMode: .standAloneFiles) - ]) + .generateHTML(withTheme: theme) + ],fileMode: .standAloneFiles) try verifyOutput( in: folder, diff --git a/Tests/PublishTests/Tests/PlotComponentTests.swift b/Tests/PublishTests/Tests/PlotComponentTests.swift index 5269da15..6767f813 100644 --- a/Tests/PublishTests/Tests/PlotComponentTests.swift +++ b/Tests/PublishTests/Tests/PlotComponentTests.swift @@ -63,7 +63,7 @@ final class PlotComponentTests: PublishTestCase { XCTAssertEqual(html, """ """) @@ -76,7 +76,7 @@ final class PlotComponentTests: PublishTestCase { XCTAssertEqual(html, """ """) From b7d0b3a32fb66b091827adff995f7e31fc248cb5 Mon Sep 17 00:00:00 2001 From: Vithanco Date: Sun, 20 Aug 2023 06:08:21 +0200 Subject: [PATCH 10/19] fixed warnings. --- Package.swift | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/Package.swift b/Package.swift index ea619ee0..ba903a47 100644 --- a/Package.swift +++ b/Package.swift @@ -17,37 +17,30 @@ let package = Package( ], dependencies: [ .package( - name: "Ink", url: "https://github.com/vithanco/ink.git", from: "0.6.1" ), .package( - name: "Plot", url: "https://github.com/vithanco/plot.git", from: "0.14.0" ), .package( - name: "Files", url: "https://github.com/johnsundell/files.git", from: "4.0.0" ), .package( - name: "Codextended", url: "https://github.com/johnsundell/codextended.git", from: "0.1.0" ), .package( - name: "ShellOut", url: "https://github.com/johnsundell/shellout.git", from: "2.3.0" ), .package( - name: "Sweep", url: "https://github.com/johnsundell/sweep.git", from: "0.4.0" ), .package( - name: "CollectionConcurrencyKit", url: "https://github.com/johnsundell/collectionConcurrencyKit.git", from: "0.1.0" ) @@ -56,8 +49,13 @@ let package = Package( .target( name: "Publish", dependencies: [ - "Ink", "Plot", "Files", "Codextended", - "ShellOut", "Sweep", "CollectionConcurrencyKit" + .product(name: "Ink", package: "ink"), + .product(name: "Plot", package: "plot"), + .product(name: "Files", package: "files"), + .product(name: "Codextended", package: "codextended"), + .product(name: "ShellOut", package: "shellOut"), + .product(name: "Sweep", package: "sweep"), + .product(name: "CollectionConcurrencyKit", package: "collectionConcurrencyKit") ] ), .executableTarget( From 6a83b7dbbbf800d53d917f3e58e47120fc2462df Mon Sep 17 00:00:00 2001 From: Vithanco Date: Sun, 20 Aug 2023 08:18:24 +0200 Subject: [PATCH 11/19] added Ted Talks --- Sources/Publish/API/PlotComponents.swift | 2 ++ Sources/Publish/API/Video.swift | 2 ++ 2 files changed, 4 insertions(+) diff --git a/Sources/Publish/API/PlotComponents.swift b/Sources/Publish/API/PlotComponents.swift index 5e0c0b09..bf9be30b 100644 --- a/Sources/Publish/API/PlotComponents.swift +++ b/Sources/Publish/API/PlotComponents.swift @@ -267,6 +267,8 @@ public struct VideoPlayer: Component { case .vimeo(let id): let url = "https://player.vimeo.com/video/" + id return iframeVideoPlayer(for: url) + case .tedTalk(let id): + let url = "https://embed.ted.com/talks/" + id } } diff --git a/Sources/Publish/API/Video.swift b/Sources/Publish/API/Video.swift index 84c41c11..b885b935 100644 --- a/Sources/Publish/API/Video.swift +++ b/Sources/Publish/API/Video.swift @@ -16,6 +16,8 @@ public enum Video: Hashable { case youTube(id: String) /// A Vimeo video with a given ID. case vimeo(id: String) + /// A Ted Talk with a given ID. + case tedTalk(id: String) } extension Video: Decodable { From e3ae9ac83cc4c48b5f532013dfc662e4a002906d Mon Sep 17 00:00:00 2001 From: Vithanco Date: Sun, 20 Aug 2023 11:37:32 +0200 Subject: [PATCH 12/19] added Ted Talks --- Sources/Publish/API/PlotComponents.swift | 75 ++++++++++++------------ Sources/Publish/API/Video.swift | 2 + 2 files changed, 40 insertions(+), 37 deletions(-) diff --git a/Sources/Publish/API/PlotComponents.swift b/Sources/Publish/API/PlotComponents.swift index bf9be30b..99941b1f 100644 --- a/Sources/Publish/API/PlotComponents.swift +++ b/Sources/Publish/API/PlotComponents.swift @@ -1,8 +1,8 @@ /** -* Publish -* Copyright (c) John Sundell 2019 -* MIT license, see LICENSE file for details -*/ + * Publish + * Copyright (c) John Sundell 2019 + * MIT license, see LICENSE file for details + */ import Foundation import Plot @@ -33,19 +33,19 @@ public extension Node where Context == HTML.DocumentContext { rssFeedTitle: String? = nil ) -> Node { var title = location.title - + if title.isEmpty { title = site.name } else { title.append(titleSeparator + site.name) } - + var description = location.description - + if description.isEmpty { description = site.description } - + return .head( .encoding(.utf8), .siteName(site.name), @@ -74,7 +74,7 @@ public extension Node where Context == HTML.HeadContext { static func stylesheet(_ path: Path) -> Node { .stylesheet(path.absoluteString) } - + /// Declare a favicon for the HTML page. /// - parameter favicon: The favicon to declare. static func favicon(_ favicon: Favicon) -> Node { @@ -88,7 +88,7 @@ public extension Node where Context: HTML.BodyContext { static func contentBody(_ body: Content.Body) -> Node { .raw(body.html) } - + /// Render a string of inline Markdown as HTML within the current context. /// - parameter markdown: The Markdown string to render. /// - parameter parser: The Markdown parser to use. Pass `context.markdownParser` to @@ -97,7 +97,7 @@ public extension Node where Context: HTML.BodyContext { using parser: MarkdownParser = .init()) -> Node { .raw(parser.html(from: markdown)) } - + /// Add an inline audio player within the current context. /// - parameter audio: The audio to add a player for. /// - parameter showControls: Whether playback controls should be shown to the user. @@ -109,7 +109,7 @@ public extension Node where Context: HTML.BodyContext { ) .convertToNode() } - + /// Add an inline video player within the current context. /// - parameter video: The video to add a player for. /// - parameter showControls: Whether playback controls should be shown to the user. @@ -147,17 +147,17 @@ internal extension Node where Context: RSSItemContext { .isPermaLink(item.rssProperties.guid == nil && item.rssProperties.link == nil) ) } - + static func content(for item: Item, site: T) -> Node { let baseURL = site.url let prefixes = (href: "href=\"", src: "src=\"") - + var html = item.rssProperties.bodyPrefix ?? "" html.append(item.body.html) html.append(item.rssProperties.bodySuffix ?? "") - + var links = [(url: URL, range: ClosedRange, isHref: Bool)]() - + html.scan(using: [ Matcher( identifiers: [ @@ -169,19 +169,19 @@ internal extension Node where Context: RSSItemContext { guard url.first == "/" else { return } - + let absoluteURL = baseURL.appendingPathComponent(String(url)) let isHref = (html[range.lowerBound] == "h") links.append((absoluteURL, range, isHref)) } ) ]) - + for (url, range, isHref) in links.reversed() { let prefix = isHref ? prefixes.href : prefixes.src html.replaceSubrange(range, with: prefix + url.absoluteString + "\"") } - + return content(html) } } @@ -221,15 +221,15 @@ public extension AudioPlayer { public struct Markdown: Component { /// The Markdown string to render. public var string: String - + @EnvironmentValue(.markdownParser) private var parser - + /// Initialize an instance of this component with a Markdown string. /// - parameter string: The Markdown string to render. public init(_ string: String) { self.string = string } - + public var body: Component { Node.markdown(string, using: parser) } @@ -244,7 +244,7 @@ public struct VideoPlayer: Component { /// Whether playback controls should be shown to the user. Note that this /// property is ignored when rendering a video hosted by a service like YouTube. public var showControls: Bool - + /// Create an inline player for a `Video` model. /// - parameter video: The video to create a player for. /// - parameter showControls: Whether playback controls should be shown to the user. @@ -253,25 +253,26 @@ public struct VideoPlayer: Component { self.video = video self.showControls = showControls } - + public var body: Component { switch video { - case .hosted(let url, let format): - return Node.video( - .controls(showControls), - .source(.type(format), .src(url)) - ) - case .youTube(let id): - let url = "https://www.youtube-nocookie.com/embed/" + id - return iframeVideoPlayer(for: url) - case .vimeo(let id): - let url = "https://player.vimeo.com/video/" + id - return iframeVideoPlayer(for: url) + case .hosted(let url, let format): + return Node.video( + .controls(showControls), + .source(.type(format), .src(url)) + ) + case .youTube(let id): + let url = "https://www.youtube-nocookie.com/embed/" + id + return iframeVideoPlayer(for: url) + case .vimeo(let id): + let url = "https://player.vimeo.com/video/" + id + return iframeVideoPlayer(for: url) case .tedTalk(let id): - let url = "https://embed.ted.com/talks/" + id + let url = "https://embed.ted.com/talks/" + id + return iframeVideoPlayer(for: url) } } - + private func iframeVideoPlayer(for url: URLRepresentable) -> Component { IFrame( url: url, diff --git a/Sources/Publish/API/Video.swift b/Sources/Publish/API/Video.swift index b885b935..6e005da1 100644 --- a/Sources/Publish/API/Video.swift +++ b/Sources/Publish/API/Video.swift @@ -26,6 +26,8 @@ extension Video: Decodable { self = .youTube(id: youTubeID) } else if let vimeoID: String = try decoder.decodeIfPresent("vimeo") { self = .vimeo(id: vimeoID) + } else if let tedTalkID: String = try decoder.decodeIfPresent("tedTalk") { + self = .tedTalk(id: tedTalkID) } else { self = try .hosted( url: decoder.decode("url"), From a6679ca86b9adb572b348b8baea49529c1132a2a Mon Sep 17 00:00:00 2001 From: Vithanco Date: Sun, 20 Aug 2023 20:23:58 +0200 Subject: [PATCH 13/19] added video documenation --- Documentation/HowTo/how-to-use-videos.md | 60 ++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 Documentation/HowTo/how-to-use-videos.md diff --git a/Documentation/HowTo/how-to-use-videos.md b/Documentation/HowTo/how-to-use-videos.md new file mode 100644 index 00000000..a8f486d6 --- /dev/null +++ b/Documentation/HowTo/how-to-use-videos.md @@ -0,0 +1,60 @@ +# How to use Videos + + +You can use videos on your pages. +You need to do 2 things: +- you define which video to include +- you define where to include the video on your page. + +## which video to include + +You need to include the video in your metadata: +``` +--- +title: Here the title of the item/page/section/index +... +video.tedTalk: celeste_headlee_10_ways_to_have_a_better_conversation +--- + +Now the content.... + +``` + +You can as well choose +- video.youtube +- video.vimeo +- video.url + +## where to include the video + +One way is to use this structure: + +```swift + public struct VideoPlayerIfNeeded : Component{ + let video: Video? + let height: String + + init(video: Video?, height: Int = 350) { + self.video = video + self.height = String(height) + } + + var body: Component { + video != nil ? VideoPlayer(video: video!,showControls: true).attribute(named:"height",value:self.height) : EmptyComponent() as Component + } + } +``` + +And then you can simply use it in your theme, e.g. + +```swift + Article { + H1(item.content.title) + VideoPlayerIfNeeded(video: item.video) + Div(item.content.body).class("content") + } +``` + + +## Alternatives +you can choose to use [this publish plugin](https://github.com/Vithanco/YoutubePublishPlugin). From 9ad74bd39e8197d4e2eb139fcf55eaa0f3793090 Mon Sep 17 00:00:00 2001 From: Vithanco Date: Mon, 28 Aug 2023 16:52:16 +0200 Subject: [PATCH 14/19] removed debugPrint --- Sources/Publish/API/Website.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/Publish/API/Website.swift b/Sources/Publish/API/Website.swift index 31602ffb..b777bb74 100644 --- a/Sources/Publish/API/Website.swift +++ b/Sources/Publish/API/Website.swift @@ -240,13 +240,13 @@ public extension Website { extension Website { public func tag2htmlfileName(tag: Tag) -> String { let result = self.fileMode.filePath(path: self.path(for: tag)).absoluteString - debugPrint("tag2htmlfileName: \(tag) -> \(result)") + //debugPrint("tag2htmlfileName: \(tag) -> \(result)") return result } public func item2htmlfileName(item: Item) -> String { let result = self.fileMode.filePath(path: item.path).absoluteString - debugPrint("item2htmlfileName: \(item) -> \(result)") + //debugPrint("item2htmlfileName: \(item) -> \(result)") return result } } From 52b153af53c8538c04f28323f7224e682ade0e33 Mon Sep 17 00:00:00 2001 From: Vithanco Date: Tue, 5 Sep 2023 15:11:13 +0200 Subject: [PATCH 15/19] updated plot to 0.14.1 --- Package.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Package.swift b/Package.swift index ba903a47..1d8c65ea 100644 --- a/Package.swift +++ b/Package.swift @@ -22,7 +22,7 @@ let package = Package( ), .package( url: "https://github.com/vithanco/plot.git", - from: "0.14.0" + from: "0.14.1" ), .package( url: "https://github.com/johnsundell/files.git", From 00c17031593d0e03715c9d77db93bdcad04bee8b Mon Sep 17 00:00:00 2001 From: Vithanco Date: Tue, 5 Sep 2023 15:13:48 +0200 Subject: [PATCH 16/19] updated to plot 0.14.2 --- Package.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Package.swift b/Package.swift index 1d8c65ea..d13c8e88 100644 --- a/Package.swift +++ b/Package.swift @@ -22,7 +22,7 @@ let package = Package( ), .package( url: "https://github.com/vithanco/plot.git", - from: "0.14.1" + from: "0.14.2" ), .package( url: "https://github.com/johnsundell/files.git", From e98ff3ec88a02a86cb1d3513e314360db20e9068 Mon Sep 17 00:00:00 2001 From: Vithanco Date: Tue, 5 Sep 2023 21:55:19 +0200 Subject: [PATCH 17/19] updated to Plot 0.14.3 --- Package.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Package.swift b/Package.swift index d13c8e88..c2dd222c 100644 --- a/Package.swift +++ b/Package.swift @@ -22,7 +22,7 @@ let package = Package( ), .package( url: "https://github.com/vithanco/plot.git", - from: "0.14.2" + from: "0.14.3" ), .package( url: "https://github.com/johnsundell/files.git", From b673af542e82e712396c54c909534a38bb4b2ec9 Mon Sep 17 00:00:00 2001 From: Vithanco Date: Mon, 11 Sep 2023 08:23:00 +0200 Subject: [PATCH 18/19] updated to plot 0.14.4 --- Package.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Package.swift b/Package.swift index c2dd222c..02e76949 100644 --- a/Package.swift +++ b/Package.swift @@ -22,7 +22,7 @@ let package = Package( ), .package( url: "https://github.com/vithanco/plot.git", - from: "0.14.3" + from: "0.14.4" ), .package( url: "https://github.com/johnsundell/files.git", From 3071223f832c822d631d3d34e18f5a796f7eb4d7 Mon Sep 17 00:00:00 2001 From: Vithanco Date: Wed, 20 Sep 2023 20:51:29 +0200 Subject: [PATCH 19/19] not sure --- Package.resolved | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Package.resolved b/Package.resolved index bc2488a0..1fc3bbea 100644 --- a/Package.resolved +++ b/Package.resolved @@ -42,8 +42,8 @@ "repositoryURL": "https://github.com/vithanco/plot.git", "state": { "branch": null, - "revision": "2aa5c4bfdab0b9d097047ba7e812d06791c3d518", - "version": "0.14.0" + "revision": "ae4ca6f2ec650733d3352628aca03b728e83a3c8", + "version": "0.14.4" } }, {