-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_process.js
33 lines (28 loc) · 927 Bytes
/
_process.js
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
const externalLinkAttributes = [
['.html'],
(page) => {
const links = page.document.getElementsByTagName('a')
Array.from(links).forEach((link) => {
if (/https?:\/\//.test(link.getAttribute('href'))) {
link.setAttribute('target', '_blank')
link.setAttribute('rel', 'noopener')
}
})
}
]
const imageLazyLoading = [
['.html'],
(page) => {
const images = page.document.getElementsByTagName('img')
Array.from(images).forEach((img) => {
img.setAttribute('loading', 'lazy')
// Need to find another way to autogenerate img width and height as this is not supported in Deno :/
// image.setAttribute('width', image.naturalWidth)
// image.setAttribute('height', image.naturalHeight)
})
}
]
export default [
externalLinkAttributes,
imageLazyLoading
]