Skip to content

OpenGraph Initial Release #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Mar 16, 2025
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
510 changes: 510 additions & 0 deletions .github/workflows/OpenGraph-Build.yml

Large diffs are not rendered by default.

32 changes: 32 additions & 0 deletions Build/GitHub/Jobs/OpenGraph.psd1
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
@{
"runs-on" = "ubuntu-latest"
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'
},
'RunEZOut',
'RunHelpOut',
@{
name = 'Use PSJekyll Action'
uses = 'PowerShellWeb/PSJekyll@main'
id = 'PSJekyll'
}
)
}
10 changes: 10 additions & 0 deletions Build/GitHub/Steps/PublishTestResults.psd1
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@{
name = 'PublishTestResults'
uses = 'actions/upload-artifact@main'
with = @{
name = 'PesterResults'
path = '**.TestResults.xml'
}
if = '${{always()}}'
}

12 changes: 12 additions & 0 deletions Build/OpenGraph.GitHubWorkflow.PSDevOps.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#requires -Module PSDevOps
Import-BuildStep -SourcePath (
Join-Path $PSScriptRoot 'GitHub'
) -BuildSystem GitHubWorkflow

Push-Location ($PSScriptRoot | Split-Path)
New-GitHubWorkflow -Name "OpenGraph Module Build" -On Push,
PullRequest,
Demand -Job TestPowerShellOnLinux,
TagReleaseAndPublish, OpenGraph -OutputPath .\.github\workflows\OpenGraph-Build.yml

Pop-Location
39 changes: 39 additions & 0 deletions Build/OpenGraph.ezout.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#requires -Module EZOut
# Install-Module EZOut or https://github.com/StartAutomating/EZOut
$myFile = $MyInvocation.MyCommand.ScriptBlock.File
$myRoot = $myFile | Split-Path | Split-Path
$myModuleName = $myFile | Split-Path | Split-Path | Split-Path -Leaf
Push-Location $myRoot
$formatting = @(
# Add your own Write-FormatView here,
# or put them in a Formatting or Views directory
foreach ($potentialDirectory in 'Formatting','Views','Types') {
Join-Path $myRoot $potentialDirectory |
Get-ChildItem -ea ignore |
Import-FormatView -FilePath {$_.Fullname}
}
)

$destinationRoot = $myRoot

if ($formatting) {
$myFormatFilePath = Join-Path $destinationRoot "$myModuleName.format.ps1xml"
# You can also output to multiple paths by passing a hashtable to -OutputPath.
$formatting | Out-FormatData -Module $MyModuleName -OutputPath $myFormatFilePath
}

$types = @(
# Add your own Write-TypeView statements here
# or declare them in the 'Types' directory
Join-Path $myRoot Types |
Get-Item -ea ignore |
Import-TypeView

)

if ($types) {
$myTypesFilePath = Join-Path $destinationRoot "$myModuleName.types.ps1xml"
# You can also output to multiple paths by passing a hashtable to -OutputPath.
$types | Out-TypeData -OutputPath $myTypesFilePath
}
Pop-Location
26 changes: 26 additions & 0 deletions OpenGraph.ps.psm1
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
$commandsPath = Join-Path $PSScriptRoot Commands
[include('*-*')]$commandsPath

$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

33 changes: 33 additions & 0 deletions OpenGraph.psd1
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
@{
RootModule = 'OpenGraph.psm1'
ModuleVersion = '0.0.1'
GUID = 'be4e4070-1ea6-4a2e-8b6a-c6b7755e5ace'
Author = 'JamesBrundage'
CompanyName = 'Start-Automating'
Copyright = '(c) 2025 Start-Automating'
Description = 'Get OpenGraph with PowerShell'
FunctionsToExport = 'Get-OpenGraph'
AliasesToExport = 'OpenGraph', 'ogp'
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'
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.0.1

* Initial Release of OpenGraph Module (#1)
* `Get-OpenGraph` gets open graph information (#2)
* OpenGraph objects can get `.HTML` (#8)
'@
}
}
}

36 changes: 36 additions & 0 deletions OpenGraph.psm1
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
$commandsPath = Join-Path $PSScriptRoot Commands
:ToIncludeFiles foreach ($file in (Get-ChildItem -Path "$commandsPath" -Filter "*-*" -Recurse)) {
if ($file.Extension -ne '.ps1') { continue } # Skip if the extension is not .ps1
foreach ($exclusion in '\.[^\.]+\.ps1$') {
if (-not $exclusion) { continue }
if ($file.Name -match $exclusion) {
continue ToIncludeFiles # Skip excluded files
}
}
. $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


35 changes: 35 additions & 0 deletions OpenGraph.types.ps1xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!-- Generated with EZOut 2.0.6: Install-Module EZOut or https://github.com/StartAutomating/EZOut -->
<Types>
<Type>
<Name>OpenGraph</Name>
<Members>
<ScriptProperty>
<Name>HTML</Name>
<GetScriptBlock>
@(if ($this -is [Management.Automation.PSModuleInfo]) {
if ($this.Description) {
"&lt;meta name='description' content='$([Web.HttpUtility]::HtmlAttributeEncode($this.Description))' /&gt;"
}
if ($this.Author) {
"&lt;meta name='article:author' content='$([Web.HttpUtility]::HtmlAttributeEncode($this.Author))' /&gt;"
}
if ($this.PrivateData.PSData.IconUri) {
"&lt;meta property='og:image' content='$([Web.HttpUtility]::HtmlAttributeEncode($this.PrivateData.PSData.IconUri))' /&gt;"
}
} else {
foreach ($property in $this.PSObject.Properties) {
if ($property.Name -match ':') {
$value = $property.Value
if ($value -is [DateTime]) {
$value = $value.ToUniversalTime().ToString('o')
}
"&lt;meta property='$($property.Name)' content='$([Web.HttpUtility]::HtmlAttributeEncode($value))' /&gt;"
}
}
}) -join [Environment]::Newline

</GetScriptBlock>
</ScriptProperty>
</Members>
</Type>
</Types>
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
# OpenGraph
Get OpenGraph with PowerShell

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

The OpenGraph module lets you see this information for any page that has it.

~~~PowerShell
Get-OpenGraph https://abc.com/
~~~

21 changes: 21 additions & 0 deletions Types/OpenGraph/get_HTML.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
@(if ($this -is [Management.Automation.PSModuleInfo]) {
if ($this.Description) {
"<meta name='description' content='$([Web.HttpUtility]::HtmlAttributeEncode($this.Description))' />"
}
if ($this.Author) {
"<meta name='article:author' content='$([Web.HttpUtility]::HtmlAttributeEncode($this.Author))' />"
}
if ($this.PrivateData.PSData.IconUri) {
"<meta property='og:image' content='$([Web.HttpUtility]::HtmlAttributeEncode($this.PrivateData.PSData.IconUri))' />"
}
} else {
foreach ($property in $this.PSObject.Properties) {
if ($property.Name -match ':') {
$value = $property.Value
if ($value -is [DateTime]) {
$value = $value.ToUniversalTime().ToString('o')
}
"<meta property='$($property.Name)' content='$([Web.HttpUtility]::HtmlAttributeEncode($value))' />"
}
}
}) -join [Environment]::Newline
Loading