forked from Stephanevg/PSHTML
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExample6.ps1
138 lines (101 loc) · 4.98 KB
/
Example6.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<#
Tribute to Snover but added CSS styles and bootstrap.
The following example called 'tribute to Snover' grasps information for the 'shellfather' from around the internet, adn generates a html page with the information.
# This example ilustrates how we can leverage the power of powershell, to fetch and filter information on various websites (using invoke-webrequest)
We use foreach to create multiple <p> or <li> elements.
#>
import-module .\pshtml.psd1
$Snover = Html {
head -content {
Title "Tribute to snover"
#Linking to bootstrap
$AllLinks = @()
$AllLinks += @{
"rel" = "stylesheet"
"href" = "https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css"
"Integrity" = "sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB"
"crossorigin"= "anonymous"
}
$AllLinks += @{
"rel" = "stylesheet"
"href" = "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css"
"Integrity" = "sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp"
"crossorigin"= "anonymous"
}
$ScriptParams = @()
$ScriptParams += @{
"src" = "https://code.jquery.com/jquery-3.3.1.slim.min.js"
"integrity"="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
"crossorigin"="anonymous"
}
$ScriptParams += @{
"src" = "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"
"integrity"="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo"
"crossorigin"="anonymous"
}
$scriptParams += @{
"src" = "https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"
"integrity"="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49"
"crossorigin"="anonymous"
}
$scriptParams += @{
"src" = "https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"
"integrity"="sha384-smHYKdLADwkXOn1EmN1qk/HfnUcbVRZyYmZ4qpPea6sjB/pTJ0euyQp0Mk8ck+5T"
"crossorigin"="anonymous"
}
foreach ($link in $AllLinks){
link @link
}
foreach ($ScriptParam in $ScriptParams){
script @ScriptParam
}
link -rel stylesheet -href "MyStyles.css"
}
Body{
div -Class "container" {
div -Class "text-center" {
h1 "Tribute to Jeffrey Snover" -Class "Title"
img -src "https://pbs.twimg.com/profile_images/618804166631145473/2q6yharL_400x400.jpg" -class "rounded-circle" -alt "Jeffrey Snover photo" -height "400" -width "400"
}
div -id "Bio" {
$WikiRootSite = "https://en.wikipedia.org"
$Source = a {"Wikipedia"} -href $WikiRootSite
h2 "Biography"
h4 "Source --> $Source"
#Gathering the biography information from Wikipedia
$wiki = Invoke-WebRequest -Uri ($WikiRootSite + "/wiki/Jeffrey_Snover")
$Output = $Wiki.ParsedHtml.getElementById("mw-content-text").children | Where-Object -FilterScript {$_.ClassName -eq 'mw-parser-output'}
$Bio = $Output.Children | Where-Object -FilterScript {$_.TagName -eq 'p'} | Select-Object -Property Tagname,InnerHtml
foreach ($p in $bio){
if($p.InnerHtml -ne $null){
#The url are relative on Wiki website. Correcting it here so that the Links are still working
$Corrected = $p.innerHTML.Replace("/wiki/","$WikiRootSite/wiki/")
p{
$Corrected
}
}
}
}#End Accomplishements
Div -id "Snoverisms" {
$SnoverismsSite = "http://snoverisms.com/"
h2 "Snoverisms"
h4 "Source --> $SnoverismsSite"
$Page = Invoke-WebRequest -Uri $SnoverismsSite
$Snoverisms = $Page.ParsedHtml.getElementsByTagName("p") | Where-Object -FilterScript {$_.ClassName -ne "site-description"} | Select-Object -Property innerhtml
$Snoverisms += (Invoke-WebRequest -uri "http://snoverisms.com/page/2/").ParsedHtml.getElementsByTagName("p") | Where-Object -FilterScript {$_.ClassName -ne "site-description"} | Select-Object -Property innerhtml
ul -id "snoverism-list" -Content {
Foreach ($snov in $Snoverisms){
li -Class "snoverism" -content {
$snov.innerHTML
}
}
}#end of ul
}
}
}
Footer{
$PSHTMLlink = a {"PSHTML"} -href "https://github.com/Stephanevg/PSHTML"
h6 "Generated with $($PSHTMLlink)"
}
}
$Snover > "Example6.html"