-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
312 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0"?> | ||
<container version="1.0" xmlns="urn:oasis:names:tc:opendocument:xmlns:container"> | ||
<rootfiles> | ||
<rootfile full-path="OEBPS/metadata.opf" media-type="application/oebps-package+xml"/> | ||
</rootfiles> | ||
</container> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<html xmlns="http://www.w3.org/1999/xhtml"> | ||
<head> | ||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> | ||
<title>{{ title }}</title> | ||
<link href="resources/index_0.css" type="text/css" charset="UTF-8" rel="stylesheet"/> | ||
</head> | ||
<body> | ||
<div> | ||
{# <p><img src="resources/{{ fileName }}" width="{{ width }}" height="{{ height }}"/></p> #} | ||
<p><img src="resources/{{ fileName }}" /></p> | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
body { | ||
text-align: left; | ||
text-indent: 0em; | ||
margin-top: 0; | ||
margin-bottom: 0; | ||
margin-left: 0; | ||
margin-right: 0; | ||
Padding-top: 0; | ||
Padding-bottom: 0; | ||
Padding-left: 0; | ||
Padding-right: 0; | ||
} | ||
p { | ||
text-align: left; | ||
text-indent: 0em; | ||
margin-top: 0; | ||
margin-bottom: 0; | ||
margin-left: 0; | ||
margin-right: 0; | ||
Padding-top: 0; | ||
Padding-bottom: 0; | ||
Padding-left: 0; | ||
Padding-right: 0; | ||
} | ||
div { | ||
text-align: left; | ||
text-indent: 0em; | ||
margin-top: 0; | ||
margin-bottom: 0; | ||
margin-left: 0; | ||
margin-right: 0; | ||
Padding-top: 0; | ||
Padding-bottom: 0; | ||
Padding-left: 0; | ||
Padding-right: 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<package xmlns="http://www.idpf.org/2007/opf" version="2.0" unique-identifier="calibre_id"> | ||
<metadata xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf" xmlns:Txt2ePub="http://no722.cocolog-nifty.com/blog/metadata"> | ||
<dc:title>{{ title }}</dc:title> | ||
<dc:creator opf:role="aut" opf:file-as="e-hentai.org">e-hentai.org</dc:creator> | ||
{# <dc:contributor opf:role="bkp" opf:file-as="ChainLP">ChainLP (0.0.40.17) [http://no722.cocolog-nifty.com/blog/]</dc:contributor> #} | ||
{# <dc:date>2021-07-30T05:37:00+00:00</dc:date> #} | ||
<dc:publisher>e-hentai.org</dc:publisher> | ||
<dc:language>{{ language }}</dc:language> | ||
{# <dc:identifier opf:scheme="CHAINLP">254ce15d-dfdf-4fa0-bba0-9dbd232c7854</dc:identifier> #} | ||
<meta content="true" name="fixed-layout"/> | ||
<meta content="comic" name="book-type"/> | ||
<meta name="Txt2ePub:series_index" content="1"/> | ||
<meta name="calibre:title_sort" content="{{ title }}"/> | ||
<meta name="cover" content="cover"/> | ||
</metadata> | ||
<manifest> | ||
{%- for fileName in fileNameList %} | ||
<item id="index{{ fileName.withoutExtension }}" href="content/index_{{ fileName.withoutExtension }}.xhtml" media-type="application/xhtml+xml"/> | ||
{%- endfor %} | ||
{%- for fileName in fileNameList %} | ||
<item id="img_{{ fileName.withoutExtension }}" href="content/resources/{{ fileName.name }}" media-type="image/{{ fileName.extension }}"/> | ||
{%- endfor %} | ||
<item id="ncx" href="toc.ncx" media-type="application/x-dtbncx+xml"/> | ||
<item id="idcss" href="content/resources/index_0.css" media-type="text/css"/> | ||
<item id="cover" href="content/resources/{{ coverName }}" media-type="image/{{ coverExtension }}"/> | ||
</manifest> | ||
<spine> | ||
{%- for fileName in fileNameList %} | ||
<itemref idref="index{{ fileName.withoutExtension }}"/> | ||
{%- endfor %} | ||
</spine> | ||
</package> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE ncx PUBLIC "-//NISO//DTD ncx 2005-1//EN" "http://www.daisy.org/z3986/2005/ncx-2005-1.dtd"> | ||
<ncx xmlns="http://www.daisy.org/z3986/2005/ncx/" version="2005-1" xml:lang="jp"> | ||
<head> | ||
<meta name="dtb:uid" content="{{ uid }}"/> | ||
<meta name="dtb:depth" content="1"/> | ||
<meta name="dtb:generator" content="Txt2ePub"/> | ||
<meta name="dtb:totalPageCount" content="0"/> | ||
<meta name="dtb:maxPageNumber" content="0"/> | ||
</head> | ||
<docTitle><text>Table of Contents</text></docTitle> | ||
<navMap> | ||
</navMap> | ||
</ncx> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
application/epub+zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:fehviewer/store/floor/entity/gallery_task.dart'; | ||
import 'package:fehviewer/utils/logger.dart'; | ||
import 'package:flutter/services.dart' show rootBundle; | ||
import 'package:jinja/jinja.dart'; | ||
import 'package:path/path.dart' as path; | ||
|
||
import '../global.dart'; | ||
|
||
Future<String> buildEpub(GalleryTask task, {String? tempPath}) async { | ||
final _tempPath = tempPath ?? path.join(Global.tempPath, 'export_epub_temp'); | ||
|
||
Directory _tempDir = Directory(_tempPath); | ||
if (_tempDir.existsSync()) { | ||
_tempDir.deleteSync(recursive: true); | ||
} | ||
_tempDir.createSync(recursive: true); | ||
|
||
final metaPath = path.join(_tempPath, 'META-INF'); | ||
_creatDir(metaPath); | ||
|
||
// OEBPS 目录创建 | ||
final oebpsPath = path.join(_tempPath, 'OEBPS'); | ||
_creatDir(oebpsPath); | ||
|
||
final contentPath = path.join(oebpsPath, 'content'); | ||
_creatDir(contentPath); | ||
|
||
final resourcesPath = path.join(contentPath, 'resources'); | ||
_creatDir(resourcesPath); | ||
|
||
// mimetype | ||
final fileMimetype = File(path.join(_tempPath, 'mimetype')); | ||
fileMimetype.writeAsStringSync('application/epub+zip\n'); | ||
|
||
// css 创建 | ||
final cssText = await rootBundle | ||
.loadString('assets/templates/epub/OEBPS/content/resources/index_0.css'); | ||
final fileCss = File(path.join(resourcesPath, 'index_0.css')); | ||
fileCss.writeAsStringSync(cssText); | ||
|
||
// container | ||
final containerText = await rootBundle | ||
.loadString('assets/templates/epub/META-INF/container.xml'); | ||
final fileContainer = File(path.join(metaPath, 'container.xml')); | ||
fileContainer.writeAsStringSync(containerText); | ||
|
||
// 图片复制到 resourcesPath | ||
final _galleryDir = Directory(task.dirPath!); | ||
final _fileList = _galleryDir.listSync(); | ||
for (final _file in _fileList) { | ||
if ((await FileSystemEntity.type(_file.path)) == | ||
FileSystemEntityType.file) { | ||
final srcFile = File(_file.path); | ||
srcFile.copySync(path.join(resourcesPath, path.basename(srcFile.path))); | ||
} | ||
} | ||
|
||
// 模板操作 | ||
final environment = Environment(); | ||
|
||
// index 模板内容读取 | ||
final indexTemplateText = await rootBundle | ||
.loadString('assets/templates/epub/OEBPS/content/index.html.tpl'); | ||
final indexTemplate = environment.fromString(indexTemplateText); | ||
|
||
// metadata 模板内容读取 | ||
final metadataTemplateText = await rootBundle | ||
.loadString('assets/templates/epub/OEBPS/metadata.xml.tpl'); | ||
final metadataTemplate = environment.fromString(metadataTemplateText); | ||
|
||
// toc 模板内容读取 | ||
final tocTemplateText = | ||
await rootBundle.loadString('assets/templates/epub/OEBPS/toc.ncx.tpl'); | ||
final tocTemplate = environment.fromString(tocTemplateText); | ||
|
||
final _fileNameList = _fileList | ||
.map( | ||
(e) => { | ||
'withoutExtension': path.basenameWithoutExtension(e.path), | ||
'name': path.basename(e.path), | ||
'extension': path.extension(e.path) == '.jpg' | ||
? 'jpeg' | ||
: path.extension(e.path).split('.').last.toLowerCase(), | ||
}, | ||
) | ||
.toList() | ||
..sort((a, b) => a['name']!.compareTo(b['name']!)); | ||
|
||
// 写入index | ||
for (final _imgFile in _fileNameList) { | ||
final _xhtml = indexTemplate.render( | ||
fileName: _imgFile['name'], | ||
); | ||
final _xhtmlFile = File( | ||
path.join(contentPath, 'index_${_imgFile['withoutExtension']}.xhtml')); | ||
_xhtmlFile.createSync(recursive: true); | ||
_xhtmlFile.writeAsStringSync('$_xhtml'); | ||
} | ||
|
||
// 写入 metadata.opf | ||
final metadata = metadataTemplate.render( | ||
title: task.title, | ||
fileNameList: _fileNameList, | ||
coverName: _fileNameList.first['name'], | ||
coverExtension: _fileNameList.first['extension'], | ||
); | ||
final metadataFile = File(path.join(oebpsPath, 'metadata.opf')); | ||
metadataFile.createSync(); | ||
metadataFile.writeAsStringSync('$metadata'); | ||
|
||
// 写入 toc.ncx | ||
final toc = tocTemplate.render(); | ||
final tocFile = File(path.join(oebpsPath, 'toc.ncx')); | ||
tocFile.createSync(); | ||
tocFile.writeAsStringSync('$toc'); | ||
|
||
return _tempPath; | ||
} | ||
|
||
void _creatDir(String path) { | ||
final _dir = Directory(path); | ||
if (!_dir.existsSync()) { | ||
_dir.createSync(recursive: true); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters