From 16d0d6c301666ac063fa2d321932a7deedc9374a Mon Sep 17 00:00:00 2001 From: Leo Dion Date: Fri, 4 Aug 2023 22:22:27 -0400 Subject: [PATCH] adding further simplicity to API --- README.md | 265 +++++++++++++++++- .../Decoder/WordPressSite+RSSChannel.swift | 6 +- .../Decoder/WordPressSite.swift | 2 +- .../Images/AssetImport.swift | 2 +- .../MarkdownProcessor+Starter.swift | 24 +- .../ProcessorSettings.swift | 2 +- .../ContributeWordPress/PublishDefaults.swift | 1 + .../ContributeWordPress/Settings+Init.swift | 14 +- Sources/ContributeWordPress/Settings.swift | 2 +- 9 files changed, 291 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index cbf1b0c2..bceae38b 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,8 @@ Import your WordPress site into Publish. # Introduction -**ContributeWordPress** provides an easy abstract layer for accessing Keychain data as well as an API for encoding and decoding complex data in the Keychain. +**ContributeWordPress** provides an undis manus herbarum Theseus? Et **graves**, ille? Genusque non +quatenus [suos Hippodamen](http://www.mersitquemagnae.com/superetque.php) ## Requirements @@ -62,6 +63,11 @@ Use version up to `1.0.0`. ## How It Works +* take export from WordPress +* downloads resources +* convert html to markdown (optionally) with new urls for pages and resources mapped +* (optionally) writes out a redirect file for easy redirect from old WP Site to new one + Haec adfuit; magna unda tuae fatus corpora Aeetias [mortis](http://www.longumet.org/) iacent, dato. Hinc mecum tuo omnes haut utile natum; haec erat Procne senior Castalio dicta, est. Aures apro est excessere @@ -83,14 +89,261 @@ quod, [vixisti totum Iunone](http://www.ades.com/quondamaut), et. Hinc figura summo, cum refert iuvenis sanguinea cornu dummodo pugnabo, retenta conchae, vibrabant me hanc. -> Lacrimis iura monstravit, additus ego atque anili, cultis natam. Magnos est, -> nova insania has: totas nec Si ubi infantem. Et nobis Iovis coniuge utque -> quodque Numicius et ipse trahentem delabere te petiit *ferunt* caeli que -> tecta. Laboras suo optat. +## Exporting from WordPress + +Lorem markdownum quoque a **mensae** capiat *pectora quodque credere* nec +Perseus illo. Taurum est essem tot lux. Niobe ab vano; aquarum coeptaeque +inclinat: quorum truncis Samos ut cumque cecidere ab quarum? Pervigil mentis +Amphitryoniaden sublimis Capetusque: Minervae supplex oras et pinuque fallitque +pectore dum invitam facta adimunt vulnere. Volucrum est; forsitan officium +innitens, ad mutantur, pressique *gratantur fecistis* si atris tetigere +fugaverat, deo femina? + +![https://placehold.co/600x400?text=Hello+World](https://placehold.co/600x400?text=Login) + +Parente nox ore *eque*. Hic natalis tenebat septemplice, gemitus subcubuisse +pars; aut nymphe hinc, reliquit loquenti religata viribus. + +Remigis nuda protinus crista, bracchia enim paterna manu exiguamque iugum. +Sententia aut vox pariterque forte in undas sanguine voluptas; arce gracili +equos ubi videres omnis in. Quia mundus. + + +![https://placehold.co/600x400?text=Hello+World](https://placehold.co/600x400?text=Settings) + +Me fuerat gaudete, atro quae longaeva, natus [artificem +quod](http://praevertuntfuit.org/accepisse) serae fecerat transit formae. +Obversus onerosus, ora tectus bracchia labores haud visus rapuitque exsangues in +cohors iniusti ut quam sanguine Aonidum. Simul fabricataque alios feroces, a +divisque, merito meta vocavit delamentatur **novercae fugit** fas? Rerum quae +auras magnis illa fluentibus sed. + + +![https://placehold.co/600x400?text=Hello+World](https://placehold.co/600x400?text=Export) + +Adulantum tellus cruore, sparsae perspicit sacraria patre fluit equorum. Ora ast +per lacte amanti nympharum habuere Eurynomes capillis causaque istis. Iam patuit +vi [membra matre](http://ego.com/audet), inquit ad et poscit vagatur. Includit +puer vivax tota: cum antiqua mente vestibus attolle; Teleste saxea limoso +Hippodamas est dives [et est crudelior](http://et-aquis.com/et). Esse iuris bene +error procorum actus *labitur*, separat cycnus habet lingua, pollue. + +- Et sponte micant +- Acutae inpar concordia +- Sagacior obvertit quae +- Sub ossa nec vellem +- Fessa sed silet opem armi inmenso ostendere + +Iuncta Latiaeque in est fluctus *satis* pugnat Procnen nigra coniuge eruta +resecuta victores permulsit ignarus. Infelix aliquid, superamur concubitus +dapes. Et tum aut excivere membra nigrescere removi, tunc, alto qui ecce scelus +vertit horrescere harena. # Usage -## +## Getting Started + +_Most simple usage..._ + +Lorem markdownum te rogat alumna, cunasque ora hora Corinthiaci et ire vati: +temerarius dederat tremit purpureo multumque. Subiectaque in *equorum iamdudum +in* mihi si dis committi artus confodit, arbore avem erit, pererrat. Cum fit +luctibus animam retentus adversaque *non* feres duxisses, et. Olivi laedere +capellae cereris et deos tantique: tum tibi inserui **armis**. + +Novoque me oculos nec eripuit vivit carpere, fatus et. Utrique admotis foramina +**alios**, vias *tum vota*, cum auro omnia contrahitur inquit ignes currus +accessit. + +Aquila haerentem matre, causa eo illo undis non sed. Et formam, exstructas +sentirent ovaque cumque, qui caeli Quin Alcides faciunt animans postquam fatur +iuventam concita. Ventusve medium, fuit noviens Iovemque Atlantiades et simplex +quosque? + +## Exporting to Publish (Content and Resources) + +_What are the directories for..._ + +Tamen alto, et tamen: me sed dextra vestrum. Se omnia turris adspexit tamen +[late](http://www.conterminusquam.org/) flemus ubere cogam involvitur est. + + if (website_pretest - download_ssid_kernel <= reader_printer_rpc) { + hdtv_scalable_del.hexadecimalGbps.surface_bios_archie( + barcraft_base_socket.mamp_system_cable(pim, + balancing_bank_gigahertz, url), -2); + ray_troll_up(unfriendInstaller(dvd), pushArchitecture, ios_dashboard); + dslam_modem.virtualTwainHandle += baseband(laptopPeoplewareDesktop, + output_cps, 823152); + } else { + dpiFileBatch = rippingUdp * device_smartphone; + path_bar -= userNetiquette(protector_hoc_graphic, + certificateFinderService + computingMenu); + } + map_windows_youtube += cssPimFlatbed * 1; + var dialogNewlineSequence = wan_vram_word; + if (insertionDpi) { + formula = 1 * 3 / thunderboltRich; + logic -= architecture(-3, word); + dmaUtility(file_meta.room(file, deprecatedIntellectualSector)); + } else { + screenshot += 2 - 4; + system.eupVistaDock = speed_kibibyte_header; + } + +Transit thalamosque moveoque solebant illam superum admiserat galeae Iunonis +Ismenos dum omnes et nondum **cura cavo**. Ense petam, omnia maculoso te +quatiens longo [est hanc](http://me.net/venit-maius.aspx) crinem nivosos corpore +[herboso](http://www.quoqueleves.org/luctus), esse si suffusa. Praevitiat +Bacchus damus, qui *veniam mensas* et taedae vidi citraque +[ditia](http://www.perflorem.io/aeneasmedius.aspx). + +## Importing Resource (i.e. Images) + +_Normal way to _download_ images_ + +Hoc manu *signavit* in sibi resolvit, caelitibus socerum *quidem*. Removit me +doctos in et ventis armigerae dabitur et +[et](http://www.honoreamphitryoniadae.net/) me quos vatum, petit illa, +accinctus. + +Tenet opacae excepto, cum exiguus nobis *te quod*, quaedam moram nunc erat. +Pelagi cessit. **Fuit regis** in **manebo et** miseras cruentas ad est lumina +procerum tempora peccasse Hyacinthe quam, vulnere carmina bello, nam. Et coniunx +parentis tecta inopi erubuit sine hoc templa ut duxque. Temerasse canit felix, +nisi vultus Echion caelo enim cupidine adest orantemque reccidat lege. + +### Copy Resources from Backup + +_Explain how to copy resources if site is down_ + +Ratis alii sed maduisse, in rapit. Nempe crimina harundine nitidum, ad ultimus +veniebat praemia, nunc! Sine iterum triste horrent sidera pectora parvum iam +pariter, hoc nubes ramum me habes munus. Mutat facis rudem tristis et omnes +magnis loricaeque liquidum interea, sibi sunt. + + dial(ospfAta.margin(surge_koffice_party), + gnutellaHtmlIntelligence.rootkit_network(contextualOsd)); + sqlMalware = memory; + card_printer_caps(mouse(server_blob, socket), rw_trinitron); + +Et et impetus incrementa **enim** dis, in et quod vitiasse, agitata in exuere +liquet. Est abit rogavi. + +## Converting Posts to Markdown + +_Explain default is no conversion. Here's how to create MarkdownGenerator._ + +Lorem markdownum Beroe mandabat ignibus, alimentaque servat saeva lotos, aquas +potui. Hanc cui: virides magno! Quodsi quae fugant ait lumina, Gorgenque +cornibus, cognitius magis illo ferrum. Quem terra erat moverat Celadontis erat +imitata sequentis mutentur Iuppiter. Et armis volutant te terra si cruentae +quoque memorata, ne Aeneas trahoque hunc, Primus nitore. + + if (pppoe(fpu, sd_pup_extranet) * servlet * systemDriverPath) { + cell_edutainment.directory(1); + } + if (pcb_social_pdf / windows == dllIvrUser(document, malware)) { + dlc_modifier_tweak(5, mebibyte_video(82, 5012, troll_printer_quad)); + } else { + terminalQbe.installUgcNtfs(264001, busIpvLock); + bookmarkDatabase.rpm += 4 + bank + 5; + code_drag_software.mountBalancing += peripheralKilobit + igpTrashBare + + 1; + } + if (5 + dualOcr) { + directx_us(deprecated_analog_teraflops, 2, 51); + } + if (oasis_disk_soap) { + dataHdv.dslam(ergonomicsVerticalFont, saas_media_plug); + } else { + so_cpc /= requirementsMampCursor; + softwareVoipKey.commerceGraphic += carrierHardCard(dataUnicodeUri, + resources, 19) * bespoke; + } + model_bezel.pharming_transistor_pci(gibibyte, ram_refresh_program); + +Morte stat ingenio mugiat, haec tuentibus divite ora Iasonis ultima fugit +*fatis* odoribus. Capitisque videt. Vixque hippomene ibat, iam sub, te aras, +mundo? + +Here's how to use... + +### Using ShellOut and Pandoc + +_How to use ShellOut and install Pandoc_ + +Lorem markdownum erat patriisque numquamque alto ferrea quibus nam penates +vicit: sine movit occumbere Dianam, imaginis, ab. Rector pharetras at populique +animos, dissuadet felicem, classis: non sine flammaeque, modo species habemus +montes. Sequitur copia, mater anteit fuit fideque victo, in Te nescio, aliquid, +huic cum. Taedae hoc in sudore artificem quidem, in amans obstat tu? + +- Medea nunc mihi hostes socio +- Excutiunt undas leonum plangore tamen +- Quae ignotos satyrique nimium +- A magna Error + +Gerebam simul dorso hospitio coleretur carmine consistere femina rubescere +Enaesimus ineo nunc tum et prensoque debes toto: posset. Per stellatus lumina +Epaphus ego. Non ut et dixere alimentaque dicor, in deos turba, est. **Tecum +in** neque in semine si variarum sepulcrum legerat tetigere omnia pressere +moderatior iacet prolemque miserabile aquilonibus. + +- Confinia iniquo oneri qua primo versasque numen +- Praevalidusque supplex conpositum pater caelumque sensi +- Collum caeleste + +Diversa inutile magna exiguamque sedet Iuppiter curvata generosam, ore supplex. +Vos fatus quam aurora visaque heros. Toto mundumque hic, socia fiet delicta est +manebo nostrae pectore. + +## Filtering Posts + +Clipeum mihi munera ternis; Non funestas *enervet*. Vicinia furiosaque minus. +Quo cruor relinquitur hiatus circumfunditur **sua**: quem tenebas exprimitur +indicet, prius copia; canes quod. Erit acie Procne pigneror et paulatim in +remulus et Thebis superest inclusum ora cannis, nigri [at +fuit](http://pavetque-quanto.org/cyclopumet)! Iunone Mendesius funeribus simus, +*qua*! + +- Modo ait ullum vicit saevisque sua +- Cingere et raptos meas iugo iacuere atque +- Est eripiunt Hecaben inmedicabile rapta intendit cruentum +- Epulis iacuere +- Nepotum oscula et mittere desiluit pennis + +Saxa exuvias, non inde cultores, in Venere robora. Augerem aptamque, fugio +inducit vos abluere nuntiet coniunx praetendat et vocantia est Crete memor +sequentia venis, nox matutina! Et germanae dubie. + +## Redirecting Old URLs + +Rexit terrae mane manumque, cum viscata adicit miles. Vota veluti angustis, si +quis, loqui venerit adspicit, [meque](http://de.org/) suum [fuit +qua](http://luctus.org/sed). Esset invaserat tibique et pudorem totaeque +recentis frena! Dapes ab deinde. Silvamque caelatus quam! + +Arne sed ego regia, una quem, terra, Attis nova tendere ab volucrem feror et +partes utinam, busta. Mitia gemitu secundo? Miseri nomen, via ora abrumpit +dimovit comes enim recens contraria litoris qua pharetrae iussa, species ait? +Per Dixit sed dea pars blandita, [idem patiere animo](http://www.et.net/fruges) +inmansuetusque falsum. + +## Using SwiftArgumentParser for Settings + +Lorem *markdownum procul* dabat nam committe omni sunt puer si nomine, +tremoribus differt ex! Ipse genua studeat: tertia **fidum nobilitate alba** +potentior pisces; quid manus undis transit est. Hortos **ipse** rupit Triptolemo +Talia: utinam exempla, aequora una. + +1. Dicta quid amantem Danaam +2. Pulsa fugant colore +3. Sed flumina atria totis modo Semele cecidit +4. Antiquam tale silvis opus perque +5. Enim frequens caelum + +Porrigit levant, puellae. Abesse de harena enim emisitque haud incultos fuderat +lumina. Onus *fama mensor*. ## Further Documentation diff --git a/Sources/ContributeWordPress/Decoder/WordPressSite+RSSChannel.swift b/Sources/ContributeWordPress/Decoder/WordPressSite+RSSChannel.swift index f345e315..e5482960 100644 --- a/Sources/ContributeWordPress/Decoder/WordPressSite+RSSChannel.swift +++ b/Sources/ContributeWordPress/Decoder/WordPressSite+RSSChannel.swift @@ -17,7 +17,7 @@ extension WordPressSite { public init(channel: RSSChannel) throws { try self.init( channel: channel, - relativeResourcePath: WordPressSite.wpContentUploadsRelativePath + relativeResourcePath: WordPressSite.contentUploadsRelativePath ) } @@ -57,7 +57,7 @@ extension WordPressSite { /// - Throws: An error if the regular expression cannot be created. internal static func defaultAssetURLRegex( forSite site: BaseURLSite, - relativeResourcePath: String = WordPressSite.wpContentUploadsRelativePath + relativeResourcePath: String = WordPressSite.contentUploadsRelativePath ) throws -> NSRegularExpression { try Self.defaultAssetURLRegex( forAssetSiteURL: site.baseURL, @@ -74,7 +74,7 @@ extension WordPressSite { /// - Throws: An error if the regular expression cannot be created. public static func defaultAssetURLRegex( forAssetSiteURL assetSiteURL: URL, - relativeResourcePath: String = WordPressSite.wpContentUploadsRelativePath + relativeResourcePath: String = WordPressSite.contentUploadsRelativePath ) throws -> NSRegularExpression { try NSRegularExpression(pattern: "\(assetSiteURL)/\(relativeResourcePath)([^\"]+)") } diff --git a/Sources/ContributeWordPress/Decoder/WordPressSite.swift b/Sources/ContributeWordPress/Decoder/WordPressSite.swift index d8f490b4..4a342038 100644 --- a/Sources/ContributeWordPress/Decoder/WordPressSite.swift +++ b/Sources/ContributeWordPress/Decoder/WordPressSite.swift @@ -3,7 +3,7 @@ import SyndiKit /// A struct that represents a WordPress site. public struct WordPressSite: BaseURLSite { - public static let wpContentUploadsRelativePath = "wp-content/uploads" + public static let contentUploadsRelativePath = "wp-content/uploads" /// The name of the channel. public let title: String diff --git a/Sources/ContributeWordPress/Images/AssetImport.swift b/Sources/ContributeWordPress/Images/AssetImport.swift index 4e6ec0a4..d7ac61e8 100644 --- a/Sources/ContributeWordPress/Images/AssetImport.swift +++ b/Sources/ContributeWordPress/Images/AssetImport.swift @@ -55,7 +55,7 @@ public struct AssetImport: Hashable { ) { let featuredPath = sourceURL.path .replacingOccurrences( - of: ["", WordPressSite.wpContentUploadsRelativePath].joined(separator: "/"), + of: ["", WordPressSite.contentUploadsRelativePath].joined(separator: "/"), with: assetRoot ) .replacingOccurrences(of: "//", with: "/") diff --git a/Sources/ContributeWordPress/MarkdownProcessor+Starter.swift b/Sources/ContributeWordPress/MarkdownProcessor+Starter.swift index 912bf0c4..c2ad867a 100644 --- a/Sources/ContributeWordPress/MarkdownProcessor+Starter.swift +++ b/Sources/ContributeWordPress/MarkdownProcessor+Starter.swift @@ -7,16 +7,26 @@ import Yams import FoundationNetworking #endif +@available(*, deprecated, message: "Use from Contribute.") +public struct PassthroughMarkdownGenerator: MarkdownGenerator { + private init() {} + public static let shared = PassthroughMarkdownGenerator() + public func markdown(fromHTML htmlString: String) throws -> String { + htmlString + } +} + extension MarkdownProcessor where ContentURLGeneratorType == SectionContentURLGenerator, MarkdownContentBuilderType == MarkdownContentYAMLBuilder< Source, FilteredHTMLMarkdownExtractor, FrontMatterYAMLExporter > { - public static func begin( - importFrom exportsDirectoryURL: URL, + public static func beginImport( + from exportsDirectoryURL: URL, to rootPublishSiteURL: URL, - usingGenerator markdownGenerator: MarkdownGenerator, + usingGenerator markdownGenerator: MarkdownGenerator = + PassthroughMarkdownGenerator.shared, filteringPostsWith postFilters: [PostFilter] = .default, redirectsFormattedUsing redirectFromatter: RedirectFormatter? = nil, importAssetsBy assetImportSetting: AssetImportSetting = .download, @@ -36,8 +46,8 @@ extension MarkdownProcessor where ContentURLGeneratorType == SectionContentURLGe try processor.begin(withSettings: settings) } - public static func begin( - importFrom exportsDirectoryURL: URL, + public static func beginImport( + from exportsDirectoryURL: URL, to rootPublishSiteURL: URL, filteringPostsWith postFilters: [PostFilter] = .default, redirectsFormattedUsing redirectFromatter: RedirectFormatter? = nil, @@ -45,8 +55,8 @@ extension MarkdownProcessor where ContentURLGeneratorType == SectionContentURLGe overwriteAssets: Bool = false, shellOut: @escaping (String, [String]) throws -> String ) throws { - try begin( - importFrom: exportsDirectoryURL, + try beginImport( + from: exportsDirectoryURL, to: rootPublishSiteURL, usingGenerator: PandocMarkdownGenerator(shellOut: shellOut), filteringPostsWith: postFilters, diff --git a/Sources/ContributeWordPress/ProcessorSettings.swift b/Sources/ContributeWordPress/ProcessorSettings.swift index ea060523..2df341b3 100644 --- a/Sources/ContributeWordPress/ProcessorSettings.swift +++ b/Sources/ContributeWordPress/ProcessorSettings.swift @@ -75,7 +75,7 @@ extension ProcessorSettings { /// The relative path for uploads directory of WordPress content. public var uploadsRelativePath: String { - WordPressSite.wpContentUploadsRelativePath + WordPressSite.contentUploadsRelativePath } /// Returns the asset directory path for the given site name. diff --git a/Sources/ContributeWordPress/PublishDefaults.swift b/Sources/ContributeWordPress/PublishDefaults.swift index 33cf6401..d7092325 100644 --- a/Sources/ContributeWordPress/PublishDefaults.swift +++ b/Sources/ContributeWordPress/PublishDefaults.swift @@ -3,4 +3,5 @@ import Foundation public enum PublishDefaults { public static let contentDirectoryName = "Content" public static let resourcesDirectoryName = "Resources" + public static let wpAssetsRelativePath = "media/wp-assets" } diff --git a/Sources/ContributeWordPress/Settings+Init.swift b/Sources/ContributeWordPress/Settings+Init.swift index ff908393..cab34a9c 100644 --- a/Sources/ContributeWordPress/Settings+Init.swift +++ b/Sources/ContributeWordPress/Settings+Init.swift @@ -7,7 +7,7 @@ extension Settings { exportsDirectoryURL: URL, assetImportSetting: AssetImportSetting = .download, overwriteAssets: Bool = false, - assetRelativePath: String = WordPressSite.wpContentUploadsRelativePath, + assetRelativePath: String = PublishDefaults.wpAssetsRelativePath, markdownFromHTML: @escaping (String) throws -> String = { $0 } ) { self.init( @@ -27,10 +27,10 @@ extension Settings { contentPathURL: URL, resourcesPathURL: URL, exportsDirectoryURL: URL, - markdownGenerator: MarkdownGenerator, + markdownGenerator: MarkdownGenerator = PassthroughMarkdownGenerator.shared, assetImportSetting: AssetImportSetting = .download, overwriteAssets: Bool = false, - assetRelativePath: String = WordPressSite.wpContentUploadsRelativePath + assetRelativePath: String = PublishDefaults.wpAssetsRelativePath ) { self.init( contentPathURL: contentPathURL, @@ -46,10 +46,10 @@ extension Settings { public init( rootPublishSiteURL: URL, exportsDirectoryURL: URL, - markdownGenerator: MarkdownGenerator, + markdownGenerator: MarkdownGenerator = PassthroughMarkdownGenerator.shared, assetImportSetting: AssetImportSetting = .download, overwriteAssets: Bool = false, - assetRelativePath: String = WordPressSite.wpContentUploadsRelativePath + assetRelativePath: String = PublishDefaults.wpAssetsRelativePath ) { self.init( contentPathURL: @@ -70,7 +70,7 @@ extension Settings { exportsDirectoryURL: URL, assetImportSetting: AssetImportSetting = .download, overwriteAssets: Bool = false, - assetRelativePath: String = WordPressSite.wpContentUploadsRelativePath, + assetRelativePath: String = PublishDefaults.wpAssetsRelativePath, temporaryFile: @escaping (String) throws -> URL = PandocMarkdownGenerator.Temporary.file(fromContent:), shellOut: @escaping (String, [String]) throws -> String @@ -92,7 +92,7 @@ extension Settings { exportsDirectoryURL: URL, assetImportSetting: AssetImportSetting = .download, overwriteAssets: Bool = false, - assetRelativePath: String = WordPressSite.wpContentUploadsRelativePath, + assetRelativePath: String = PublishDefaults.wpAssetsRelativePath, temporaryFile: @escaping (String) throws -> URL = PandocMarkdownGenerator.Temporary.file(fromContent:), shellOut: @escaping (String, [String]) throws -> String diff --git a/Sources/ContributeWordPress/Settings.swift b/Sources/ContributeWordPress/Settings.swift index be74d901..50168b8f 100644 --- a/Sources/ContributeWordPress/Settings.swift +++ b/Sources/ContributeWordPress/Settings.swift @@ -22,7 +22,7 @@ public struct Settings: ProcessorSettings { exportsDirectoryURL: URL, assetImportSetting: AssetImportSetting = .download, overwriteAssets: Bool = false, - assetRelativePath: String = WordPressSite.wpContentUploadsRelativePath, + assetRelativePath: String = PublishDefaults.wpAssetsRelativePath, markdownFromHTML: @escaping (String) throws -> String = { $0 } ) { self.contentPathURL = contentPathURL