1- import { Document , Element } from 'parse5' ;
1+ import type { DefaultTreeAdapterTypes } from 'parse5' ;
2+ type Document = DefaultTreeAdapterTypes . Document ;
3+ type Element = DefaultTreeAdapterTypes . Element ;
24import path from 'path' ;
35import picomatch from 'picomatch' ;
46import { findElements , getTagName , getAttribute } from '@web/parse5-utils' ;
5- import { createError } from '../utils.js ' ;
7+ import { createError } from '../utils.ts ' ;
68import { serialize } from 'v8' ;
79
8- const assetLinkRels = [
9- 'icon' ,
10- 'apple-touch-icon' ,
11- 'mask-icon' ,
12- 'stylesheet' ,
13- 'manifest' ,
14- 'preload' ,
15- 'prefetch' ,
16- 'modulepreload' ,
17- ] ;
18- const legacyHashedLinkRels = [ 'stylesheet' ] ;
19- const assetMetaProperties = [ 'og:image' ] ;
10+ const hashedLinkRels = [ 'stylesheet' ] ;
11+ const linkRels = [ ...hashedLinkRels , 'icon' , 'manifest' , 'apple-touch-icon' , 'mask-icon' ] ;
2012
2113function getSrcSetUrls ( srcset : string ) {
2214 if ( ! srcset ) {
@@ -51,14 +43,13 @@ function isAsset(node: Element) {
5143 path = extractFirstUrlOfSrcSet ( node ) ?? '' ;
5244 }
5345 break ;
54- case 'link' : {
55- if ( assetLinkRels . includes ( getAttribute ( node , 'rel' ) ?? '' ) ) {
46+ case 'link' :
47+ if ( linkRels . includes ( getAttribute ( node , 'rel' ) ?? '' ) ) {
5648 path = getAttribute ( node , 'href' ) ?? '' ;
5749 }
5850 break ;
59- }
6051 case 'meta' :
61- if ( assetMetaProperties . includes ( getAttribute ( node , 'property' ) ?? ' ') ) {
52+ if ( getAttribute ( node , 'property' ) === 'og:image' && getAttribute ( node , 'content ') ) {
6253 path = getAttribute ( node , 'content' ) ?? '' ;
6354 }
6455 break ;
@@ -81,24 +72,16 @@ function isAsset(node: Element) {
8172 }
8273}
8374
84- export function isHashedAsset (
85- node : Element ,
86- extractAssets : boolean | 'legacy-html' | 'legacy-html-and-css' ,
87- ) {
75+ export function isHashedAsset ( node : Element ) {
8876 switch ( getTagName ( node ) ) {
8977 case 'img' :
9078 return true ;
9179 case 'source' :
9280 return true ;
9381 case 'script' :
9482 return true ;
95- case 'link' : {
96- if ( extractAssets === 'legacy-html' || extractAssets === 'legacy-html-and-css' ) {
97- return legacyHashedLinkRels . includes ( getAttribute ( node , 'rel' ) ?? '' ) ;
98- } else {
99- return true ;
100- }
101- }
83+ case 'link' :
84+ return hashedLinkRels . includes ( getAttribute ( node , 'rel' ) ! ) ;
10285 case 'meta' :
10386 return true ;
10487 default :
@@ -160,7 +143,7 @@ export function getSourcePaths(node: Element) {
160143 return paths ;
161144}
162145
163- export function findAssets ( document : Document ) {
146+ export function findAssets ( document : Document ) : Element [ ] {
164147 return findElements ( document , isAsset ) ;
165148}
166149
0 commit comments