FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
patternfly-java/showcase/images.mjs at main · patternfly-java/patternfly-java · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
patternfly-java
/
patternfly-java
Public
Notifications
You must be signed in to change notification settings
Fork
5
Star
34
Code
Issues
39
Pull requests
2
Discussions
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
patternfly-java
/
showcase
/
images.mjs
Copy path
More file actions
More file actions
Latest commit
History
History
History
64 lines (57 loc) · 2.22 KB
Breadcrumbs
patternfly-java
/
showcase
/
images.mjs
Copy path
File metadata and controls
64 lines (57 loc) · 2.22 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
/*
* Copyright 2023 Red Hat
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import
*
as
fs
from
'fs'
;
import
*
as
path
from
'path'
;
import
{
fileURLToPath
}
from
'url'
;
import
https
from
'https'
;
import
puppeteer
from
'puppeteer'
;
const
__filename
=
fileURLToPath
(
import
.
meta
.
url
)
;
const
__dirname
=
path
.
dirname
(
__filename
)
;
const
url
=
'https://www.patternfly.org/components/all-components'
;
const
selector
=
'.pf-v6-l-gallery .pf-v6-c-card__body img'
;
const
imageDir
=
path
.
join
(
__dirname
,
'src'
,
'web'
,
'images'
)
;
if
(
!
fs
.
existsSync
(
imageDir
)
)
{
fs
.
mkdirSync
(
imageDir
,
{
recursive
:
true
}
)
;
}
(
async
(
)
=>
{
const
browser
=
await
puppeteer
.
launch
(
)
;
const
page
=
await
browser
.
newPage
(
)
;
console
.
log
(
`Loading
${
url
}
`
)
;
await
page
.
goto
(
url
,
{
waitUntil
:
'networkidle0'
}
)
;
console
.
log
(
'Extracting images'
)
;
const
imageUrls
=
await
page
.
$$eval
(
selector
,
imgs
=>
imgs
.
map
(
img
=>
img
.
src
)
)
;
await
browser
.
close
(
)
;
console
.
log
(
`Found
${
imageUrls
.
length
}
images`
)
;
let
downloaded
=
0
;
imageUrls
.
forEach
(
(
imgUrl
)
=>
{
let
fileName
=
path
.
basename
(
imgUrl
.
split
(
'?'
)
[
0
]
)
;
fileName
=
fileName
.
replace
(
/
\.
[
a
-
f
0
-
9
]
+
(
\.
\w
+
)
$
/
,
'$1'
)
;
const
filePath
=
path
.
join
(
imageDir
,
fileName
)
;
https
.
get
(
imgUrl
,
(
imgRes
)
=>
{
const
fileStream
=
fs
.
createWriteStream
(
filePath
)
;
imgRes
.
pipe
(
fileStream
)
;
fileStream
.
on
(
'finish'
,
(
)
=>
{
fileStream
.
close
(
)
;
downloaded
++
;
console
.
log
(
`Downloaded:
${
fileName
}
(
${
downloaded
}
/
${
imageUrls
.
length
}
)`
)
;
}
)
;
}
)
.
on
(
'error'
,
(
err
)
=>
{
console
.
error
(
`Error downloading
${
imgUrl
}
:`
,
err
.
message
)
;
}
)
;
}
)
;
}
)
(
)
;
Back
|
FazBrowse Home
|
New Git URL