File tree Expand file tree Collapse file tree 3 files changed +39
-5
lines changed Expand file tree Collapse file tree 3 files changed +39
-5
lines changed Original file line number Diff line number Diff line change 1+ > Like It? [ Star It] ( https://github.com/PowerShellWeb/JSON-LD )
2+ > Love It? [ Support It] ( https://github.com/sponsors/StartAutomating )
3+
4+ ## JSON-LD 0.1
5+
6+ Caching JSON-LD requests
7+
8+ ## JSON-LD 0.0.1
9+
10+ Get Linked Data from any page
11+
12+ * Initial Release of JSON-LD Module (#1 )
13+ * ` Get-JsonLD ` gets linked data (#2 )
14+ * ` Get-JsonLD ` is aliased to ` jsonLD ` and ` json-ld `
Original file line number Diff line number Diff line change @@ -22,10 +22,15 @@ function Get-JsonLD {
2222 # The URL that may contain JSON-LD data
2323 [Parameter (Mandatory , ValueFromPipeline , ValueFromPipelineByPropertyName )]
2424 [Uri ]
25- $Url
25+ $Url ,
26+
27+ # If set, will force the request to be made even if the URL has already been cached.
28+ [switch ]
29+ $Force
2630 )
2731
2832 begin {
33+ # Create a pattern to match the JSON-LD script tag
2934 $linkedDataRegex = [Regex ]::new(@'
3035(?<HTML_LinkedData>
3136<script # Match <script tag
@@ -39,10 +44,21 @@ application/ld\+json # The type that indicates linked d
3944(?<JsonContent>(?:.|\s){0,}?(?=\z|</script>)) # Anything until the end tag is JSONContent
4045)
4146'@ , ' IgnoreCase,IgnorePatternWhitespace' , ' 00:00:00.1' )
47+
48+ # Initialize the cache for JSON-LD requests
49+ if (-not $script :JsonLDRequestCache ) {
50+ $script :JsonLDRequestCache = [Ordered ]@ {}
51+ }
4252 }
4353
4454 process {
45- $restResponse = Invoke-RestMethod - Uri $Url
55+ $restResponse =
56+ if ($Force -or -not $script :JsonLDRequestCache [$url ]) {
57+ $script :JsonLDRequestCache [$url ] = Invoke-RestMethod - Uri $Url
58+ $script :JsonLDRequestCache [$url ]
59+ } else {
60+ $script :JsonLDRequestCache [$url ]
61+ }
4662 foreach ($match in $linkedDataRegex.Matches (" $restResponse " )) {
4763 foreach ($jsonObject in
4864 $match.Groups [' JsonContent' ].Value |
Original file line number Diff line number Diff line change 11@ {
22 RootModule = ' JSON-LD.psm1'
3- ModuleVersion = ' 0.0. 1'
3+ ModuleVersion = ' 0.1'
44 GUID = ' 4e65477c-012c-4077-87c7-3e07964636ce'
5- Author = ' JamesBrundage '
5+ Author = ' James Brundage '
66 CompanyName = ' Start-Automating'
77 Copyright = ' (c) 2025 Start-Automating.'
88 Description = ' Get JSON Linked Data with PowerShell'
99 FunctionsToExport = ' Get-JsonLD'
10- AliasesToExport = ' jsonLD' , ' json-ld'
10+ AliasesToExport = ' jsonLD' , ' json-ld'
1111 PrivateData = @ {
1212 PSData = @ {
1313 # Tags applied to this module. These help with module discovery in online galleries.
2020> Like It? [Star It](https://github.com/PowerShellWeb/JSON-LD)
2121> Love It? [Support It](https://github.com/sponsors/StartAutomating)
2222
23+ ## JSON-LD 0.1
24+
25+ Caching JSON-LD requests
26+
2327Get Linked Data from any page
2428
2529## JSON-LD 0.0.1
You can’t perform that action at this time.
0 commit comments