Skip to content

Commit

Permalink
solve fucking img url really
Browse files Browse the repository at this point in the history
  • Loading branch information
ACaiCat committed Jan 31, 2025
1 parent a7c1128 commit cdbaeb5
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 5 deletions.
7 changes: 7 additions & 0 deletions docs/en/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,10 @@ footer: 闽ICP备2024057933号-1 | GPL-3.0 License | TShockPlugin |
---









7 changes: 7 additions & 0 deletions docs/en/guide/get-start.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,10 @@










7 changes: 7 additions & 0 deletions docs/zh/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,10 @@ footer: 闽ICP备2024057933号-1 | GPL-3.0 许可证 | TShockPlugin |
---









7 changes: 7 additions & 0 deletions docs/zh/guide/get-start.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,10 @@
- 如有 bug,请在 GitHub 的 `issue` 页提供相关系统信息、 TShock 版本 以及 bug 复现流程。









7 changes: 7 additions & 0 deletions docs/zh/plugin-dev/get-start.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,10 @@
[UnrealMultiple/TShockPlugin](https://github.com/UnrealMultiple/TShockPlugin)









12 changes: 7 additions & 5 deletions scripts/local_img.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ Get-ChildItem -Path $rootDir -Recurse -Filter *.md | ForEach-Object {

# 清理文件名:替换特殊字符为下划线
$imageFileName = [System.IO.Path]::GetFileName($imageUrl)
$imageFileName = $imageFileName -replace '[^\w\.-]', '_'
if ($imageUrl -match '[\?@=&]') {
Write-Host "跳过图片(包含图片参数): $imageUrl"
continue
}

# 如果链接没有文件后缀,尝试从 URL 中提取
if (-not [System.IO.Path]::HasExtension($imageFileName)) {
Expand All @@ -45,22 +48,21 @@ Get-ChildItem -Path $rootDir -Recurse -Filter *.md | ForEach-Object {
# 下载网络图片
Invoke-WebRequest -Uri $imageUrl -OutFile $localImagePath
} else {
# 复制本地图片
Copy-Item -Path $imageUrl -Destination $localImagePath
continue
}
Write-Host "图片下载成功: $imageUrl -> $localImagePath"

# 替换 Markdown 中的图片链接为本地相对路径
$relativeImagePath = "img/$imageFileName"
$mdContent = $mdContent.Replace($match.Groups[1].Value, $relativeImagePath)
} catch {
Write-Host "Failed to download: $imageUrl"
Write-Host "图片下载失败: $imageUrl"
}
}

# 保存修改后的 Markdown 文件
Set-Content -Path $mdFilePath -Value $mdContent
Write-Host "Markdown file updated: $mdFilePath"
Write-Host "文件图片已处理: $mdFilePath"
}

Write-Host "图片转本地完成!"

0 comments on commit cdbaeb5

Please sign in to comment.