File tree Expand file tree Collapse file tree 1 file changed +18
-2
lines changed Expand file tree Collapse file tree 1 file changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -22,10 +22,15 @@ function Get-JsonLD {
22
22
# The URL that may contain JSON-LD data
23
23
[Parameter (Mandatory , ValueFromPipeline , ValueFromPipelineByPropertyName )]
24
24
[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
26
30
)
27
31
28
32
begin {
33
+ # Create a pattern to match the JSON-LD script tag
29
34
$linkedDataRegex = [Regex ]::new(@'
30
35
(?<HTML_LinkedData>
31
36
<script # Match <script tag
@@ -39,10 +44,21 @@ application/ld\+json # The type that indicates linked d
39
44
(?<JsonContent>(?:.|\s){0,}?(?=\z|</script>)) # Anything until the end tag is JSONContent
40
45
)
41
46
'@ , ' 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
+ }
42
52
}
43
53
44
54
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
+ }
46
62
foreach ($match in $linkedDataRegex.Matches (" $restResponse " )) {
47
63
foreach ($jsonObject in
48
64
$match.Groups [' JsonContent' ].Value |
You can’t perform that action at this time.
0 commit comments