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 {
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 |
Original file line number Diff line number Diff line change 1
1
@ {
2
2
RootModule = ' JSON-LD.psm1'
3
- ModuleVersion = ' 0.0. 1'
3
+ ModuleVersion = ' 0.1'
4
4
GUID = ' 4e65477c-012c-4077-87c7-3e07964636ce'
5
- Author = ' JamesBrundage '
5
+ Author = ' James Brundage '
6
6
CompanyName = ' Start-Automating'
7
7
Copyright = ' (c) 2025 Start-Automating.'
8
8
Description = ' Get JSON Linked Data with PowerShell'
9
9
FunctionsToExport = ' Get-JsonLD'
10
- AliasesToExport = ' jsonLD' , ' json-ld'
10
+ AliasesToExport = ' jsonLD' , ' json-ld'
11
11
PrivateData = @ {
12
12
PSData = @ {
13
13
# Tags applied to this module. These help with module discovery in online galleries.
20
20
> Like It? [Star It](https://github.com/PowerShellWeb/JSON-LD)
21
21
> Love It? [Support It](https://github.com/sponsors/StartAutomating)
22
22
23
+ ## JSON-LD 0.1
24
+
25
+ Caching JSON-LD requests
26
+
23
27
Get Linked Data from any page
24
28
25
29
## JSON-LD 0.0.1
You can’t perform that action at this time.
0 commit comments