@@ -65,18 +65,27 @@ function parseOldPage(document: HTMLDocument): Device[] {
65
65
function parseNewPage ( document : HTMLDocument ) : Device [ ] {
66
66
const MODEL_IDENTIFIER = 'Model Identifier: '
67
67
68
- const names = [ ...document . querySelectorAll ( 'p.gb-paragraph b' ) ] . map ( b => ( b as Element ) . innerText )
68
+ const names = [ ...document . querySelectorAll ( 'p.gb-paragraph b' ) ] . map ( b => ( b as Element ) . innerText . trim ( ) )
69
69
const ids = [ ...document . querySelectorAll ( 'p.gb-paragraph' ) ] . filter ( p => ( p as Element ) . innerText . startsWith ( MODEL_IDENTIFIER ) ) . map ( p => ( p as Element ) . innerText . replace ( MODEL_IDENTIFIER , '' ) )
70
70
71
71
if ( names . length !== ids . length ) {
72
72
throw new Error ( 'names and ids are not matched' )
73
73
}
74
74
75
- const devices : Device [ ] = [ ]
76
- names . forEach ( ( name , i ) => {
77
- const id = ids [ i ]
78
- devices . push ( { id, name } )
79
- } )
75
+ const devices = names . map ( ( name , i ) => {
76
+ let id = ids [ i ]
77
+
78
+ // Apple might have temporarily miswritten the document, as currently, on https://support.apple.com/en-us/102852,
79
+ // there is no line break between Model Identifier and Part Numbers in the description of the Mac mini (2023) model.
80
+ // Therefore, a separate handling for this model has been added
81
+ // (planned to be removed when the document is updated).
82
+ if ( id . includes ( 'Part Numbers:' ) ) {
83
+ id = id . split ( 'Part Numbers:' ) [ 0 ] . trim ( )
84
+ }
85
+
86
+ // some devices have multiple identifiers
87
+ return id . split ( '; ' ) . map ( id => ( { id, name } ) )
88
+ } ) . flat ( )
80
89
81
90
return devices
82
91
}
0 commit comments