diff --git a/CHANGELOG.md b/CHANGELOG.md index 049b0d5..0d1906f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,14 @@ Please: --- +## JSON-LD 0.1.2 + +* Aliasing Url to Uri (#12) +* Supporting direct JSON-LD content links (#27) (Thanks @AniTexs!) +* Generating README.md (#28) + +--- + ## JSON-LD 0.1.1 * Updating Examples (#13) diff --git a/Commands/Get-JsonLD.ps1 b/Commands/Get-JsonLD.ps1 index a7a5b71..23b34c5 100644 --- a/Commands/Get-JsonLD.ps1 +++ b/Commands/Get-JsonLD.ps1 @@ -21,7 +21,7 @@ function Get-JsonLD { param( # The URL that may contain JSON-LD data [Parameter(Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName)] - [Alias('href')] + [Alias('href','uri')] [Uri] $Url, @@ -42,10 +42,8 @@ function Get-JsonLD { [string] $as = 'jsonld', - [switch] - $RawHtml, - # If set, will force the request to be made even if the URL has already been cached. + [Alias('IgnoreCache')] [switch] $Force ) @@ -71,53 +69,140 @@ application/ld\+json # The type that indicates linked d $script:Cache = [Ordered]@{} } + # Construct a filter to match and output + filter matchAndOutput { + + $contentToMatch = $_ + if ($contentToMatch -match '^\s{0,}\{') { + $contentToMatch = "" + } + + if ($as -eq 'html') { + return $contentToMatch + } + + # Find all linked data tags within the response + foreach ($match in $linkedDataRegex.Matches("$($contentToMatch)")) { + # If we want the result as xml + if ($As -eq 'xml') { + # try to cast it + $matchXml ="$match" -as [xml] + if ($matchXml) { + # and output it if found. + $matchXml + continue + } else { + # otherwise, fall back to the `