Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
21 changes: 17 additions & 4 deletions Commands/Get-OpenGraph.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -17,37 +17,50 @@ 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('<meta.+?/>','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]
if ($matchXml.meta.property -and $matchXml.meta.content) {
$openGraphMetadata[$matchXml.meta.property] = $matchXml.meta.content
}
}
$script:OpenGraphCache[$url] = $openGraphMetadata
}
if ($Data) {
foreach ($key in $Data.Keys) {
Expand Down
14 changes: 7 additions & 7 deletions OpenGraph.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -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)
'@
}
}
Expand Down
6 changes: 6 additions & 0 deletions OpenGraph.types.ps1xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
<Type>
<Name>OpenGraph</Name>
<Members>
<ScriptMethod>
<Name>ToString</Name>
<Script>
$this.HTML
</Script>
</ScriptMethod>
<ScriptProperty>
<Name>HTML</Name>
<GetScriptBlock>
Expand Down
1 change: 1 addition & 0 deletions Types/OpenGraph/ToString.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$this.HTML
Loading