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
21 changes: 5 additions & 16 deletions .github/workflows/OpenGraph-Build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
Install-Module -Name Pester -Repository PSGallery -Force -Scope CurrentUser -MaximumVersion $PesterMaxVersion -SkipPublisherCheck -AllowClobber
Import-Module Pester -Force -PassThru -MaximumVersion $PesterMaxVersion} @Parameters
- name: Check out repository
uses: actions/checkout@v4
uses: actions/checkout@v2
- name: RunPester
id: RunPester
shell: pwsh
Expand Down Expand Up @@ -92,6 +92,9 @@ jobs:
$result =
Invoke-Pester -PassThru -Verbose -OutputFile ".\$moduleName.TestResults.xml" -OutputFormat NUnitXml @codeCoverageParameters

"::set-output name=TotalCount::$($result.TotalCount)",
"::set-output name=PassedCount::$($result.PassedCount)",
"::set-output name=FailedCount::$($result.FailedCount)" | Out-Host
if ($result.FailedCount -gt 0) {
"::debug:: $($result.FailedCount) tests failed"
foreach ($r in $result.TestResult) {
Expand Down Expand Up @@ -490,21 +493,7 @@ jobs:
if: ${{ success() }}
steps:
- name: Check out repository
uses: actions/checkout@v2
- name: GitLogger
uses: GitLogging/GitLoggerAction@main
id: GitLogger
- name: Use PSSVG Action
uses: StartAutomating/PSSVG@main
id: PSSVG
- name: Use PipeScript Action
uses: StartAutomating/PipeScript@main
id: PipeScript
uses: actions/checkout@main
- name: UseEZOut
uses: StartAutomating/EZOut@master
- name: UseHelpOut
uses: StartAutomating/HelpOut@master
- name: Use PSJekyll Action
uses: PowerShellWeb/PSJekyll@main
id: PSJekyll

27 changes: 3 additions & 24 deletions Build/GitHub/Jobs/OpenGraph.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,8 @@
steps = @(
@{
name = 'Check out repository'
uses = 'actions/checkout@v2'
},
@{
name = 'GitLogger'
uses = 'GitLogging/GitLoggerAction@main'
id = 'GitLogger'
},
@{
name = 'Use PSSVG Action'
uses = 'StartAutomating/PSSVG@main'
id = 'PSSVG'
},
@{
name = 'Use PipeScript Action'
uses = 'StartAutomating/PipeScript@main'
id = 'PipeScript'
},
'RunEZOut',
'RunHelpOut',
@{
name = 'Use PSJekyll Action'
uses = 'PowerShellWeb/PSJekyll@main'
id = 'PSJekyll'
}
uses = 'actions/checkout@main'
}
'RunEZOut'
)
}
26 changes: 26 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
Please:

* [Like](https://github.com/PoshWeb/OpenGraph)
* [Share](https://github.com/PoshWeb/OpenGraph)
* [Subscribe](https://github.com/PoshWeb/)
* [Support](https://github.com/sponsors/StartAutomating)

---

## OpenGraph 0.1.1

* Simplified Module Scaffolding (#14)
* Supporting open or closed tags (#15)
* `Get-OpenGraph -Html` supports direct content (#16)
* `Get-OpenGraph -Url` is now positional and pipeable (#17)
* Improving README (#18)

---

## 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)
Expand Down
65 changes: 53 additions & 12 deletions Commands/Get-OpenGraph.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,22 @@ function Get-OpenGraph
'https://msnbc.com/',
'https://fox.com/' |
Get-OpenGraph
.LINK
https://ogp.me/
#>
[Alias('openGraph','ogp')]
[CmdletBinding(PositionalBinding=$false)]
param(
# The URL that may contain Open Graph metadata
[Parameter(ValueFromPipelineByPropertyName)]
[Parameter(Position=0,ValueFromPipeline,ValueFromPipelineByPropertyName)]
[Uri]
$Url,

# Any HTML that may contain open graph metadata.
[Parameter(ValueFromPipelineByPropertyName)]
[string]
$Html,

# A dictionary of additional Open Graph metadata to include in the result
[Parameter(ValueFromPipelineByPropertyName)]
[Collections.IDictionary]
Expand All @@ -40,36 +47,70 @@ function Get-OpenGraph

begin {
# Make a regex to match meta tags
$metaRegex = [Regex]::new('<meta.+?/>','IgnoreCase','00:00:00.1')
if (-not $script:OpenGraphCache) {
$script:OpenGraphCache = [Ordered]@{}
}
# We will match both open and closed tags.
$metaRegex = [Regex]::new('<meta.+?/?>','IgnoreCase','00:00:00.1')
# If we do not have a cache
if (-not $script:Cache) {
# create one.
$script:Cache = [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]
if ($Url -and -not $PSBoundParameters['html']) {
# If the url is an absolute url with a scheme or http or https.
if ($url.Scheme -in 'http', 'https') {
# Get the url (if it is not cached).
if (-not $script:Cache[$url] -or $Force) {
$script:Cache[$url] =try {
Invoke-RestMethod -Uri $Url
} catch { $_ }
}
$html = $script:Cache[$url]
}
# Otherwise, see if the path exists
elseif (Test-Path $url)
{
# and get content from that path.
$html = Get-Content "$url" -Raw
}
$restResponse = Invoke-RestMethod -Uri $Url
foreach ($match in $metaRegex.Matches("$restResponse")) {
}

# If we had any html,
if ($html) {
# find all of the `<meta>` tags.
foreach ($match in $metaRegex.Matches($html)) {
# Try to make them XML
$matchXml = "$match" -as [xml]
# If that fails,
if (-not $matchXml) {
# try once more after explicitly closing the end tag.
$matchXml = $match -replace '>$', '/>' -as [xml]
}
# If the meta tag contained a property and content,
if ($matchXml.meta.property -and $matchXml.meta.content) {
$openGraphMetadata[$matchXml.meta.property] = $matchXml.meta.content
# we will add it to our openGraph metadata.
$openGraphMetadata[
$matchXml.meta.property
] = $matchXml.meta.content
}
}
$script:OpenGraphCache[$url] = $openGraphMetadata
}

# If any data was provided
if ($Data) {
# copy it into open graph metadata
foreach ($key in $Data.Keys) {
$openGraphMetadata[$key] = $Data[$key]
}
}

# If there was no open graph metadata, return nothing.
if (-not $openGraphMetadata.Count) { return }

# Otherwise, return our OpenGraph metadata
[PSCustomObject]$openGraphMetadata
}
}
26 changes: 0 additions & 26 deletions OpenGraph.ps.psm1

This file was deleted.

29 changes: 18 additions & 11 deletions OpenGraph.psd1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@{
RootModule = 'OpenGraph.psm1'
ModuleVersion = '0.1'
ModuleVersion = '0.1.1'
GUID = 'be4e4070-1ea6-4a2e-8b6a-c6b7755e5ace'
Author = 'JamesBrundage'
CompanyName = 'Start-Automating'
Expand All @@ -11,21 +11,28 @@
TypesToProcess = 'OpenGraph.types.ps1xml'
PrivateData = @{
PSData = @{
Tags = @('OpenGraph','SEO','Web','PowerShellWeb' )
ProjectURI = 'https://github.com/PowerShellWeb/OpenGraph'
LicenseURI = 'https://github.com/PowerShellWeb/OpenGraph/blob/main/LICENSE'
Tags = @('OpenGraph','SEO','Web','PoshWeb','OpenGraphProtocol')
ProjectURI = 'https://github.com/PoshWeb/OpenGraph'
LicenseURI = 'https://github.com/PoshWeb/OpenGraph/blob/main/LICENSE'
ReleaseNotes = @'
> Like It? [Star It](https://github.com/PowerShellWeb/OpenGraph)
> Love It? [Support It](https://github.com/sponsors/StartAutomating)
## OpenGraph 0.1.1

## OpenGraph 0.1

* `OpenGraph.ToString()` now returns HTML (#10)
* `Get-OpenGraph` now caches results (#11)
* Simplified Module Scaffolding (#14)
* Supporting open or closed tags (#15)
* `Get-OpenGraph -Html` supports direct content (#16)
* `Get-OpenGraph -Url` is now positional and pipeable (#17)
* Improving README (#18)

---

Additional release notes can be found at [CHANGELOG.md](https://github.com/PowerShellWeb/OpenGraph/blob/main/CHANGELOG.md)
Please:

* [Like](https://github.com/PoshWeb/OpenGraph)
* [Share](https://github.com/PoshWeb/OpenGraph)
* [Subscribe](https://github.com/PoshWeb/)
* [Support](https://github.com/sponsors/StartAutomating)

Additional history found available in the [CHANGELOG.md](https://github.com/PoshWeb/OpenGraph/blob/main/CHANGELOG.md)
'@
}
}
Expand Down
23 changes: 1 addition & 22 deletions OpenGraph.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,6 @@ $commandsPath = Join-Path $PSScriptRoot Commands
. $file.FullName
}

$myModule = $MyInvocation.MyCommand.ScriptBlock.Module
$ExecutionContext.SessionState.PSVariable.Set($myModule.Name, $myModule)
$myModule.pstypenames.insert(0, $myModule.Name)

New-PSDrive -Name $MyModule.Name -PSProvider FileSystem -Scope Global -Root $PSScriptRoot -ErrorAction Ignore

if ($home) {
$MyModuleProfileDirectory = Join-Path ([Environment]::GetFolderPath("LocalApplicationData")) $MyModule.Name
if (-not (Test-Path $MyModuleProfileDirectory)) {
$null = New-Item -ItemType Directory -Path $MyModuleProfileDirectory -Force
}
New-PSDrive -Name "My$($MyModule.Name)" -PSProvider FileSystem -Scope Global -Root $MyModuleProfileDirectory -ErrorAction Ignore
}

# Set a script variable of this, set to the module
# (so all scripts in this scope default to the correct `$this`)
$script:this = $myModule

#region Custom
#endregion Custom

Export-ModuleMember -Alias * -Function * -Variable $myModule.Name
Export-ModuleMember -Alias * -Function *


67 changes: 64 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,71 @@
# OpenGraph
[![OpenGraph](https://img.shields.io/powershellgallery/dt/OpenGraph)](https://www.powershellgallery.com/packages/OpenGraph/)
## Get OpenGraph with PowerShell

[OpenGraph](https://ogp.me) is a protocol for embedding information in a page search optimization and social media.
## Installing and Importing

The OpenGraph module lets you see this information for any page that has it.
You can install OpenGraph from the [PowerShell gallery](https://powershellgallery.com/)

~~~PowerShell
Get-OpenGraph https://abc.com/
Install-Module OpenGraph -Scope CurrentUser -Force
~~~

Once installed, you can import the module with:

~~~PowerShell
Import-Module OpenGraph -PassThru
~~~


You can also clone the repo and import the module locally:

~~~PowerShell
git clone https://github.com/PoshWeb/OpenGraph
cd ./OpenGraph
Import-Module ./ -PassThru
~~~

## Functions
OpenGraph has 1 function
### Get-OpenGraph
#### Gets Open Graph metadata for a given URL.
Gets Open Graph metadata for a given URL.

[Open Graph](https://ogp.me/) is a protocol that enables any web page to become a rich object in a social graph.

It is used many social networks to display rich content when links are shared.

This function retrieves the Open Graph metadata from a given URL and returns it as a custom object.
##### Parameters

|Name|Type|Description|
|-|-|-|
|Url|Uri|The URL that may contain Open Graph metadata|
|Html|String|Any HTML that may contain open graph metadata.|
|Data|IDictionary|A dictionary of additional Open Graph metadata to include in the result|
|Force|SwitchParameter|If set, forces the function to retrieve the Open Graph metadata even if it is already cached.|

##### Examples
###### Example 1
~~~PowerShell
Get-OpenGraph -Url https://abc.com/
~~~
###### Example 2
~~~PowerShell
'https://cnn.com/',
'https://msnbc.com/',
'https://fox.com/' |
Get-OpenGraph
~~~
#### Links
* [https://ogp.me/](https://ogp.me/)
## Types
### OpenGraph
#### Members
|Name|MemberType|
|-|-|
|[ToString](Types/OpenGraph/ToString.ps1)|ScriptMethod|
|[get_HTML](Types/OpenGraph/get_HTML.ps1)|ScriptProperty|
> (c) 2025 Start-Automating

> [LICENSE](https://github.com/PoshWeb/OpenGraph/blob/main/LICENSE)
Loading
Loading