Skip to content

Commit 065c1e4

Browse files
feat: README.md.ps1 ( Fixes #28 )
1 parent 2162022 commit 065c1e4

3 files changed

Lines changed: 298 additions & 25 deletions

File tree

JSON-LD.psd1

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@{
22
RootModule = 'JSON-LD.psm1'
3-
ModuleVersion = '0.1.1'
3+
ModuleVersion = '0.1.2'
44
GUID = '4e65477c-012c-4077-87c7-3e07964636ce'
55
Author = 'James Brundage'
66
CompanyName = 'Start-Automating'
@@ -16,22 +16,24 @@
1616
# A URL to the license for this module.
1717
ProjectURI = 'https://github.com/PoshWeb/JSON-LD'
1818
LicenseURI = 'https://github.com/PoshWeb/JSON-LD/blob/main/LICENSE'
19+
PSIntro = @'
20+
Get JSON Linked Data with PowerShell
21+
22+
Gets information stored in a page's [json-ld](https://json-ld.org/) (json linked data)
23+
24+
Many pages expose this information for search engine optimization.
25+
26+
This module lets you easily get and work with JSON-LD objects.
27+
'@
1928
ReleaseNotes = @'
2029
---
2130
22-
## JSON-LD 0.1.1
31+
## JSON-LD 0.1.2
32+
33+
* Aliasing Url to Uri (#12)
34+
* Supporting direct JSON-LD content links (#27)
2335
24-
* Updating Examples (#13)
25-
* Simplfiying module scaffolding (#15)
26-
* Building types with EZOut (#5)
27-
* Supporting file input (#23)
28-
* `Get-JSONLD -as`
29-
* `Get-JSONLD -as json` (#16)
30-
* `Get-JSONLD -as html` (#17)
31-
* `Get-JSONLD -as script` (#18)
32-
* `Get-JSONLD -as xml` (#19)
33-
* Adding conversion to JsonSchema (#21)
34-
* Adding conversion to At Protocol Lexicons (#22)
36+
Thanks @AniTexs for the suggestion!
3537
3638
---
3739
@@ -45,5 +47,4 @@ Additional History in [CHANGELOG](https://github.com/PoshWeb/JSON-LD/blob/main/C
4547
}
4648
}
4749

48-
}
49-
50+
}

README.md

Lines changed: 53 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,69 @@
11
# JSON-LD
2-
2+
[![JSON-LD](https://img.shields.io/powershellgallery/dt/JSON-LD)](https://www.powershellgallery.com/packages/JSON-LD/)
3+
## Get JSON Linked Data with PowerShell
34
Get JSON Linked Data with PowerShell
45

56
Gets information stored in a page's [json-ld](https://json-ld.org/) (json linked data)
67

7-
Many pages expose this information for search engine optimization.
8+
Many pages expose this information for search engine optimization.
89

9-
## JSON-LD in PowerShell
10+
This module lets you easily get and work with JSON-LD objects.
1011

11-
JSON-LD is one of a number of ways you can get more information about a page.
12+
## Installing and Importing
1213

13-
This information can be useful in any number of fun and useful PowerShell scenarios
14+
You can install JSON-LD from the [PowerShell gallery](https://powershellgallery.com/)
1415

15-
For example, let's get information about a movie.
16+
~~~PowerShell
17+
Install-Module JSON-LD -Scope CurrentUser -Force
18+
~~~
19+
20+
Once installed, you can import the module with:
1621

1722
~~~PowerShell
18-
Get-JsonLD -Url https://letterboxd.com/film/amelie/
23+
Import-Module JSON-LD -PassThru
24+
~~~
25+
26+
27+
You can also clone the repo and import the module locally:
28+
29+
~~~PowerShell
30+
git clone https://github.com/PoshWeb/JSON-LD
31+
cd ./JSON-LD
32+
Import-Module ./ -PassThru
1933
~~~
2034

21-
Let's take things a step further, and get the information we can know about any movie:
35+
## Functions
36+
JSON-LD has 1 function
37+
### Get-JsonLD
38+
#### Gets JSON-LD data from a given URL.
39+
Gets JSON Linked Data from a given URL.
2240

41+
This is a format used by many websites to provide structured data about their content.
42+
##### Examples
43+
###### Example 1
44+
Want to get information about a movie? Linked Data to the rescue!
2345
~~~PowerShell
24-
JsonLD https://schema.org/Movie
46+
Get-JsonLD -Url https://letterboxd.com/film/amelie/
2547
~~~
26-
48+
###### Example 2
49+
Want information about an article? Lots of news sites use this format.
50+
~~~PowerShell
51+
Get-JsonLD https://www.thebulwark.com/p/mahmoud-khalil-immigration-detention-first-amendment-free-speech-rights
52+
~~~
53+
###### Example 3
54+
Want to get information about a schema?
55+
~~~PowerShell
56+
jsonld https://schema.org/Movie
57+
# Get-JSONLD will output the contents of a `@Graph` object if no `@type` is found.
58+
~~~
59+
##### Parameters
60+
61+
|Name|Type|Description|
62+
|-|-|-|
63+
|Url|Uri|The URL that may contain JSON-LD data|
64+
|as|String|If set, will the output as:<br/><br/>|as|is|<br/>|-|-|<br/>|html|the response as text|<br/>|json|the match as json|<br/>|*jsonld`|ld`|linkedData*|the match as linked data|'<br/>|script|the script tag|<br/>|xml|the script tag, as xml||
65+
|Force|SwitchParameter|If set, will force the request to be made even if the URL has already been cached.|
66+
67+
> (c) 2025-2026 Start-Automating.
68+
69+
> [LICENSE](https://github.com/PoshWeb/JSON-LD/blob/main/LICENSE)

README.md.ps1

Lines changed: 229 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
1+
<#
2+
.SYNOPSIS
3+
README.md.ps1
4+
.DESCRIPTION
5+
README.md.ps1 makes README.md
6+
7+
This is a simple and helpful scripting convention for writing READMEs.
8+
9+
`./README.md.ps1 > ./README.md`
10+
11+
Feel free to copy and paste this code.
12+
13+
Please document your parameters, and add NOTES.
14+
.NOTES
15+
This README.md.ps1 is used to generate help for a module.
16+
17+
It:
18+
19+
* Outputs the name and description
20+
* Provides installation instructions
21+
* Lists commands
22+
* Lists parameters
23+
* Lists examples
24+
.EXAMPLE
25+
./README.md.ps1 > ./README.md
26+
.EXAMPLE
27+
Get-Help ./README.md.ps1
28+
#>
29+
param(
30+
# The name of the module
31+
[string]$ModuleName = $($PSScriptRoot | Split-Path -Leaf),
32+
33+
# The domains that serve git repositories.
34+
# If the project uri links to this domain,
35+
# installation instructions will show how to import the module locally.
36+
[string[]]
37+
$GitDomains = @(
38+
'github.com', 'tangled.org', 'tangled.sh', 'codeberg.org'
39+
),
40+
41+
# If set, we don't need no badges.
42+
[switch]
43+
$NoBadge,
44+
45+
# If set, will not display gallery instructions or badges
46+
[switch]
47+
$NotOnGallery
48+
)
49+
50+
Push-Location $PSScriptRoot
51+
52+
# Import the module
53+
$module = Import-Module "./$ModuleName.psd1" -PassThru
54+
55+
# And output a header
56+
"# $module"
57+
58+
if (-not $NoBadge) {
59+
# If it is on the gallery, show the downloads badge.
60+
if (-not $NotOnGallery) {
61+
@(
62+
"[!"
63+
"[$ModuleName](https://img.shields.io/powershellgallery/dt/$ModuleName)"
64+
"](https://www.powershellgallery.com/packages/$ModuleName/)"
65+
) -join ''
66+
}
67+
}
68+
69+
# Show the module description
70+
"## $($module.Description)"
71+
72+
# Show any intro section defined in the manifest
73+
$module.PrivateData.PSData.PSIntro
74+
75+
#region Boilerplate installation instructions
76+
if (-not $NotOnGallery) {
77+
@"
78+
79+
## Installing and Importing
80+
81+
You can install $ModuleName from the [PowerShell gallery](https://powershellgallery.com/)
82+
83+
~~~PowerShell
84+
Install-Module $($ModuleName) -Scope CurrentUser -Force
85+
~~~
86+
87+
Once installed, you can import the module with:
88+
89+
~~~PowerShell
90+
Import-Module $ModuleName -PassThru
91+
~~~
92+
93+
"@
94+
}
95+
#endregion Gallery installation instructions
96+
97+
#region Git installation instructions
98+
$projectUri = $module.PrivateData.PSData.ProjectURI -as [uri]
99+
100+
if ($projectUri.DnsSafeHost -in $GitDomains) {
101+
@"
102+
103+
You can also clone the repo and import the module locally:
104+
105+
~~~PowerShell
106+
git clone $projectUri
107+
cd ./$ModuleName
108+
Import-Module ./ -PassThru
109+
~~~
110+
111+
"@
112+
}
113+
#endregion Git installation instructions
114+
115+
#region Exported Functions
116+
$exportedFunctions = $module.ExportedFunctions
117+
if ($exportedFunctions) {
118+
119+
"## Functions"
120+
121+
"$($ModuleName) has $($exportedFunctions.Count) function$(
122+
if ($exportedFunctions.Count -gt 1) { "s"}
123+
)"
124+
125+
foreach ($export in $exportedFunctions.Keys | Sort-Object) {
126+
# Get help if it there is help to get
127+
$help = Get-Help $export
128+
# If the help is a string,
129+
if ($help -is [string]) {
130+
# make it preformatted text
131+
"~~~"
132+
"$export"
133+
"~~~"
134+
} else {
135+
# Otherwise, add list the export
136+
"### $($export)"
137+
138+
# And make it's synopsis a header
139+
"#### $($help.SYNOPSIS)"
140+
141+
# put the description below that
142+
"$($help.Description.text -join [Environment]::NewLine)"
143+
144+
if ($help.examples.example) {
145+
# Show our examples
146+
"##### Examples"
147+
}
148+
149+
150+
$exampleNumber = 0
151+
foreach ($example in $help.examples.example) {
152+
$markdownLines = @()
153+
$exampleNumber++
154+
$nonCommentLine = $false
155+
"###### Example $exampleNumber"
156+
157+
# Combine the code and remarks
158+
$exampleLines =
159+
@(
160+
$example.Code
161+
foreach ($remark in $example.Remarks.text) {
162+
if (-not $remark) { continue }
163+
$remark
164+
}
165+
) -join ([Environment]::NewLine) -split '(?>\r\n|\n)' # and split into lines
166+
167+
# Go thru each line in the example as part of a loop
168+
$codeBlock = @(foreach ($exampleLine in $exampleLines) {
169+
# Any comments until the first uncommentedLine are markdown
170+
if ($exampleLine -match '^\#' -and -not $nonCommentLine) {
171+
$markdownLines += $exampleLine -replace '^\#\s{0,1}'
172+
} else {
173+
$nonCommentLine = $true
174+
$exampleLine
175+
}
176+
}) -join [Environment]::NewLine
177+
178+
$markdownLines
179+
"~~~PowerShell"
180+
$CodeBlock
181+
"~~~"
182+
}
183+
184+
$relatedUris = foreach ($link in $help.relatedLinks.navigationLink) {
185+
if ($link.uri) {
186+
$link.uri
187+
}
188+
}
189+
if ($relatedUris) {
190+
"#### Links"
191+
foreach ($related in $relatedUris) {
192+
"* [$related]($related)"
193+
}
194+
}
195+
196+
# Make a table of parameters
197+
if ($help.parameters.parameter) {
198+
"##### Parameters"
199+
200+
""
201+
202+
"|Name|Type|Description|"
203+
"|-|-|-|"
204+
foreach ($parameter in $help.Parameters.Parameter) {
205+
"|$($parameter.Name)|$($parameter.type.name)|$(
206+
$parameter.description.text -replace '(?>\r\n|\n)', '<br/>'
207+
)|"
208+
}
209+
210+
""
211+
}
212+
213+
}
214+
}
215+
}
216+
#endregion Exported Functions
217+
218+
#region Copyright Notice
219+
if ($module.Copyright) {
220+
"> $($module.Copyright)"
221+
}
222+
223+
if ($module.PrivateData.PSData.LicenseUri) {
224+
""
225+
"> [LICENSE]($($module.PrivateData.PSData.LicenseUri))"
226+
}
227+
#endregion Copyright Notice
228+
229+
Pop-Location

0 commit comments

Comments
 (0)