@@ -160,36 +160,17 @@ private function handleConfluenceHtml(): int
160
160
$ this ->info ('空间名称: ' . $ space ['name ' ]);
161
161
$ this ->info ('空间标识: ' . $ space ['key ' ]);
162
162
163
- $ divElements = $ this ->document ->getElementById ('content ' )->getElementsByTagName ('div ' );
164
- $ divElement = null ;
165
- foreach ($ divElements as $ divElement ) {
166
- if ($ divElement ->getAttribute ('class ' ) != 'pageSection ' ) {
167
- continue ;
168
- }
169
- $ h2Element = $ divElement ->getElementsByTagName ('h2 ' )[0 ];
170
- if (!empty ($ h2Element ) && $ h2Element ->nodeValue == 'Available Pages: ' ) {
171
- break ;
172
- }
173
- }
174
- if (empty ($ divElement )) {
163
+ $ pages = $ this ->confluence ->parseAvailablePages ($ this ->document );
164
+ if (empty ($ pages ['tree ' ])) {
175
165
$ this ->info ("未发现有效数据 " );
176
166
return 0 ;
177
- }
178
- $ xpath = new \DOMXPath ($ this ->document );
179
- $ firstLevelLiElements = $ xpath ->query ('ul/li ' , $ divElement );
180
- $ this ->info ("发现 {$ firstLevelLiElements ->count ()} 个一级页面 " );
181
- if ($ firstLevelLiElements ->count () == 0 ) {
182
- return 0 ;
167
+ } else {
168
+ $ this ->info ('发现 ' . count ($ pages ['tree ' ]) . ' 个一级页面 ' );
183
169
}
184
170
185
171
$ this ->info ("开始导入 CODING: " );
186
- $ pageTitles = [];
187
- foreach ($ firstLevelLiElements as $ firstLevelLiElement ) {
188
- $ aElement = $ xpath ->query ('a ' , $ firstLevelLiElement )->item (0 );
189
- $ pageTitles [$ aElement ->getAttribute ('href ' )] = $ aElement ->nodeValue ;
190
- }
191
- foreach ($ pageTitles as $ page => $ title ) {
192
- $ this ->info ('标题: ' . $ title );
172
+ foreach ($ pages ['tree ' ] as $ page ) {
173
+ $ this ->info ('标题: ' . $ pages ['titles ' ][$ page ]);
193
174
$ markdown = $ this ->confluence ->htmlFile2Markdown ($ dataPath . $ page );
194
175
$ mdFilename = substr ($ page , 0 , -5 ) . '.md ' ;
195
176
$ zipFilePath = $ this ->coding ->createMarkdownZip ($ markdown , $ dataPath , $ mdFilename );
0 commit comments