-
Notifications
You must be signed in to change notification settings - Fork 14
/
scan.js
32 lines (28 loc) · 850 Bytes
/
scan.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
export default function (ignores, limit) {
return `AstroSpa.scan = () => {
const allInternalLinks = Array.from(document.links).filter(
(link) =>
link.host === location.host &&
!link.hash &&
!link.hasAttribute("download") &&
!link.hasAttribute("data-spa-ignore") &&
link.target !== "_blank" ${
ignores.length > 0
? "&& ignores.includes(link.href) && ignores.includes(link.pathname)"
: ""
}
);
const newInternalLinks = allInternalLinks.filter(
(link) => !internalLinks.includes(link)
);
${
limit > 0
? `newInternalLinks.splice(${limit} - internalLinks.length)`
: ""
}
newInternalLinks.forEach((link) => {
AstroSpa.observe(link);
})
internalLinks.push(...newInternalLinks);
};`;
}