回复 8# lxh623
保存为 合并epub.bat,编码ANSI,此脚本放到解包后的文件夹内.- <#*,:
- @echo off
- cd /d "%~dp0"
- set "batchfile=%~f0"
- Powershell -ExecutionPolicy Bypass -C "Set-Location -LiteralPath ([Environment]::CurrentDirectory);. ([ScriptBlock]::Create([IO.File]::ReadAllText($env:batchfile,[Text.Encoding]::GetEncoding(0) )) )"
- pause
- exit /b
- #>
- # 合并epub xhtml css,此脚本放到 解包后 文件夹内
-
- Get-ChildItem -Path . | Where-Object { $_ -is [IO.DirectoryInfo] -and $_.FullName -ne $env:batchfile } | Group-Object -Property @{
- Expression = { $_.Name -replace '第\s+\d+\s+卷' }
- } | ForEach-Object {
- $di1 = $_.Group | Where-Object { $_.Name -match '第\s+(\d+)\s+卷' -and $Matches[1] -eq '1' } | Select-Object -First 1
- if ($null -eq $di1) { return }
- if($_.Group.Count -le 1){return}
- $opf = [IO.Path]::Combine($di1.FullName, 'OEBPS\content.opf')
- $xml = [IO.File]::ReadAllText($opf)
- if (-not $?) { return }
- # 把第一个里面的xhtml后面加001,或者直接改001 。把后面文件夹的,依次复制到第一个那里。并且命名002,003等等。
- # Get-ChildItem -LiteralPath ([IO.Path]::Combine($di1.FullName,'OEBPS\pages')) -Filter *.xhtml|Rename-Item -NewName '001.xhtml'
- $di1.Name | Out-Host
- $_.Group | Where-Object { $_ -ne $di1 } | ForEach-Object {
- # $null = $_.Name -match '第\s+(\d+)\s+卷'
- # $strctr = $Matches[1]
- Get-ChildItem -LiteralPath ([IO.Path]::Combine($_.FullName, 'OEBPS\pages')) -Filter *.xhtml | ForEach-Object {
- $fi2 = $_ | Copy-Item -Destination ([IO.Path]::Combine($di1.FullName, "OEBPS\pages")) -PassThru
- if ($fi2) {
- $xml = $xml.Replace("</manifest>", @"
- <item id="$($fi2.Name)" href="Text/$($fi2.Name)" media-type="application/xhtml+xml"/></manifest>
- "@).Replace("</spine>", @"
- <itemref idref="$($fi2.Name)"/></spine>
- "@)
- }
- }
- Get-ChildItem -LiteralPath ([IO.Path]::Combine($_.FullName, 'OEBPS\style')) -Filter *.css | ForEach-Object {
- $fi2 = $_ | Copy-Item -Destination ([IO.Path]::Combine($di1.FullName, "OEBPS\style")) -PassThru
- if ($fi2) {
- $xml = $xml.Replace("</manifest>", @"
- <item id="$($fi2.Name)" href="Styles/$($fi2.Name)" media-type="text/css"/></manifest>
- "@)
- }
-
- }
- }
- [IO.File]::WriteAllText($opf, $xml)
- }
复制代码
|