diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..8720e84 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,5 @@ +## OpenGraph 0.0.1 + +* Initial Release of OpenGraph Module (#1) + * `Get-OpenGraph` gets open graph information (#2) + * OpenGraph objects can get `.HTML` (#8) diff --git a/Commands/Get-OpenGraph.ps1 b/Commands/Get-OpenGraph.ps1 index db226bc..e21598c 100644 --- a/Commands/Get-OpenGraph.ps1 +++ b/Commands/Get-OpenGraph.ps1 @@ -17,30 +17,42 @@ function Get-OpenGraph 'https://cnn.com/', 'https://msnbc.com/', 'https://fox.com/' | - Get-OpenGraph + Get-OpenGraph #> [Alias('openGraph','ogp')] - param( + [CmdletBinding(PositionalBinding=$false)] + param( # The URL that may contain Open Graph metadata - [Parameter(ValueFromPipeline, ValueFromPipelineByPropertyName)] + [Parameter(ValueFromPipelineByPropertyName)] [Uri] $Url, # A dictionary of additional Open Graph metadata to include in the result [Parameter(ValueFromPipelineByPropertyName)] [Collections.IDictionary] - $Data + $Data, + + # If set, forces the function to retrieve the Open Graph metadata even if it is already cached. + [Parameter(ValueFromPipelineByPropertyName)] + [switch] + $Force ) begin { # Make a regex to match meta tags $metaRegex = [Regex]::new('','IgnoreCase','00:00:00.1') + if (-not $script:OpenGraphCache) { + $script:OpenGraphCache = [Ordered]@{} + } } process { # Declare an empty object to hold the Open Graph metadata $openGraphMetadata = [Ordered]@{PSTypeName='OpenGraph'} if ($Url) { + if ($script:OpenGraphCache[$url] -and -not $Force) { + return $script:OpenGraphCache[$url] + } $restResponse = Invoke-RestMethod -Uri $Url foreach ($match in $metaRegex.Matches("$restResponse")) { $matchXml = "$match" -as [xml] @@ -48,6 +60,7 @@ function Get-OpenGraph $openGraphMetadata[$matchXml.meta.property] = $matchXml.meta.content } } + $script:OpenGraphCache[$url] = $openGraphMetadata } if ($Data) { foreach ($key in $Data.Keys) { diff --git a/OpenGraph.psd1 b/OpenGraph.psd1 index e1e7bea..ff3ec4b 100644 --- a/OpenGraph.psd1 +++ b/OpenGraph.psd1 @@ -1,6 +1,6 @@ @{ RootModule = 'OpenGraph.psm1' - ModuleVersion = '0.0.1' + ModuleVersion = '0.1' GUID = 'be4e4070-1ea6-4a2e-8b6a-c6b7755e5ace' Author = 'JamesBrundage' CompanyName = 'Start-Automating' @@ -11,21 +11,21 @@ TypesToProcess = 'OpenGraph.types.ps1xml' PrivateData = @{ PSData = @{ - Tags = @('OpenGraph','SEO', 'Web','PowerShellWeb') + Tags = @('OpenGraph','SEO','Web','PowerShellWeb' ) ProjectURI = 'https://github.com/PowerShellWeb/OpenGraph' LicenseURI = 'https://github.com/PowerShellWeb/OpenGraph/blob/main/LICENSE' ReleaseNotes = @' - > Like It? [Star It](https://github.com/PowerShellWeb/OpenGraph) > Love It? [Support It](https://github.com/sponsors/StartAutomating) -Embed content from anywhere on the internet +## OpenGraph 0.1 + +* `OpenGraph.ToString()` now returns HTML (#10) +* `Get-OpenGraph` now caches results (#11) -## OpenGraph 0.0.1 +--- -* Initial Release of OpenGraph Module (#1) - * `Get-OpenGraph` gets open graph information (#2) - * OpenGraph objects can get `.HTML` (#8) +Additional release notes can be found at [CHANGELOG.md](https://github.com/PowerShellWeb/OpenGraph/blob/main/CHANGELOG.md) '@ } } diff --git a/OpenGraph.types.ps1xml b/OpenGraph.types.ps1xml index e3f8c5c..2297999 100644 --- a/OpenGraph.types.ps1xml +++ b/OpenGraph.types.ps1xml @@ -3,6 +3,12 @@ OpenGraph + + ToString + + HTML diff --git a/Types/OpenGraph/ToString.ps1 b/Types/OpenGraph/ToString.ps1 new file mode 100644 index 0000000..3e4d43a --- /dev/null +++ b/Types/OpenGraph/ToString.ps1 @@ -0,0 +1 @@ +$this.HTML \ No newline at end of file