Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9c268e3

Browse files
committed
feat:#66 ignore page not found
1 parentbbfb879 commit9c268e3

File tree

4 files changed

+39
-21
lines changed

4 files changed

+39
-21
lines changed

‎app/Commands/WikiImportCommand.php‎

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
useConfluence\Content;
88
useDOMDocument;
99
useException;
10+
useIlluminate\Contracts\Filesystem\FileNotFoundException;
1011
useIlluminate\Support\Str;
1112
useLaravelFans\Confluence\Facades\Confluence;
1213
useLaravelZero\Framework\Commands\Command;
@@ -192,26 +193,13 @@ private function uploadConfluencePages(string $dataPath, array $tree, array $tit
192193
foreach ($treeas$page =>$subPages) {
193194
$title =$titles[$page];
194195
$this->info('标题:' .$title);
195-
$markdown =$this->confluence->htmlFile2Markdown($dataPath .$page);
196-
$attachments =$this->confluence->parseAttachments($dataPath .$page,$markdown);
197-
$codingAttachments =$this->codingDisk->uploadAttachments(
198-
$this->codingToken,
199-
$this->codingProjectUri,
200-
$dataPath,
201-
$attachments
202-
);
203-
foreach ($codingAttachmentsas$attachmentPath =>$codingAttachment) {
204-
if (empty($codingAttachment)) {
205-
$message ='错误:文件上传失败' .$attachmentPath;
206-
$this->error($message);
207-
$this->errors[] =$message;
208-
}
209-
}
210-
$markdown =$this->codingWiki->replaceAttachments($markdown,$codingAttachments);
211-
$mdFilename =substr($page,0, -5) .'.md';
212-
if ($this->option('save-markdown')) {
213-
file_put_contents($dataPath .$mdFilename,$markdown ."\n");
196+
try {
197+
$markdown =$this->confluence->htmlFile2Markdown($dataPath .$page);
198+
}catch (FileNotFoundException$e) {
199+
$this->error('页面不存在:' .$dataPath .$page);
200+
continue;
214201
}
202+
$mdFilename =$this->dealAttachments($dataPath,$page,$markdown);
215203
$zipFilePath =$this->codingWiki->createMarkdownZip($markdown,$dataPath,$mdFilename,$title);
216204
$result =$this->codingWiki->createWikiByUploadZip(
217205
$this->codingToken,
@@ -277,4 +265,28 @@ private function unzipConfluenceHtml(): string
277265
}
278266
returnstr_ends_with($dataPath,'/index.html') ?substr($dataPath,0, -10) : Str::finish($dataPath,'/');
279267
}
268+
269+
privatefunctiondealAttachments(string$dataPath,string$page,string$markdown):string
270+
{
271+
$attachments =$this->confluence->parseAttachments($dataPath .$page,$markdown);
272+
$codingAttachments =$this->codingDisk->uploadAttachments(
273+
$this->codingToken,
274+
$this->codingProjectUri,
275+
$dataPath,
276+
$attachments
277+
);
278+
foreach ($codingAttachmentsas$attachmentPath =>$codingAttachment) {
279+
if (empty($codingAttachment)) {
280+
$message ='错误:文件上传失败' .$attachmentPath;
281+
$this->error($message);
282+
$this->errors[] =$message;
283+
}
284+
}
285+
$markdown =$this->codingWiki->replaceAttachments($markdown,$codingAttachments);
286+
$mdFilename =substr($page,0, -5) .'.md';
287+
if ($this->option('save-markdown')) {
288+
file_put_contents($dataPath .$mdFilename,$markdown ."\n");
289+
}
290+
return$mdFilename;
291+
}
280292
}

‎app/Confluence.php‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
useDOMDocument;
66
useDOMXPath;
7+
useIlluminate\Support\Facades\File;
78
useLeague\HTMLToMarkdown\Converter\TableConverter;
89
useLeague\HTMLToMarkdown\HtmlConverter;
910

@@ -46,7 +47,7 @@ public function htmlFile2Markdown(string $filename): string
4647
'|<img .* src="data:.*/>|',
4748
],
4849
'',
49-
file_get_contents($filename)
50+
File::get($filename)
5051
);
5152
libxml_use_internal_errors(true);
5253
$this->document->loadHTML($html);

‎tests/Feature/WikiImportCommandTest.php‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,10 @@ public function testHandleConfluenceHtmlSuccess()
186186
->expectsQuestion('空间导出的 HTML zip 文件路径',$this->dataDir .'confluence/space1/')
187187
->expectsOutput('空间名称:空间 1')
188188
->expectsOutput('空间标识:space1')
189-
->expectsOutput('发现2 个一级页面')
189+
->expectsOutput('发现3 个一级页面')
190190
->expectsOutput("开始导入 CODING:")
191+
->expectsOutput('标题:Not Found')
192+
->expectsOutput('页面不存在:' .$this->dataDir .'confluence/space1/not-found.html')
191193
->expectsOutput('标题:Image Demo')
192194
->expectsOutput('上传成功,正在处理,任务 ID:a12353fa-f45b-4af2-83db-666bf9f66615')
193195
->expectsOutput('标题:你好世界')

‎tests/data/confluence/space1/index.html‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ <h1 id="title-heading" class="pagetitle">
4444
<h2class="pageSectionTitle">Available Pages:</h2>
4545
</div>
4646
<ul>
47+
<li>
48+
<ahref="not-found.html">Not Found</a>
49+
4750
<li>
4851
<ahref="image-demo_65619.html">Image Demo</a>
4952

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp