X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;ds=inline;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Foutput%2FHtml.java;h=756eb8d328907e3d02eb19cede3c57dd51082ce4;hb=7b71f19ee1664aeec2c5c6061d27841dbac73a5d;hp=29a0f32b6404e6b1c0822e6e45d11b6783601905;hpb=a6395bef99a8e917f67341ef1906917b87df24a4;p=nikiroo-utils.git diff --git a/src/be/nikiroo/fanfix/output/Html.java b/src/be/nikiroo/fanfix/output/Html.java index 29a0f32..756eb8d 100644 --- a/src/be/nikiroo/fanfix/output/Html.java +++ b/src/be/nikiroo/fanfix/output/Html.java @@ -1,36 +1,41 @@ package be.nikiroo.fanfix.output; +import java.io.BufferedWriter; import java.io.File; -import java.io.FileWriter; +import java.io.FileOutputStream; import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStreamWriter; import be.nikiroo.fanfix.Instance; -import be.nikiroo.fanfix.bundles.StringId; +import be.nikiroo.fanfix.bundles.Config; import be.nikiroo.fanfix.data.Chapter; +import be.nikiroo.fanfix.data.MetaData; import be.nikiroo.fanfix.data.Paragraph; import be.nikiroo.fanfix.data.Paragraph.ParagraphType; import be.nikiroo.fanfix.data.Story; +import be.nikiroo.utils.IOUtils; import be.nikiroo.utils.StringUtils; class Html extends BasicOutput { - protected FileWriter writer; + private File dir; + protected BufferedWriter writer; private boolean inDialogue = false; private boolean inNormal = false; @Override public File process(Story story, File targetDir, String targetName) throws IOException { + String targetNameOrig = targetName; + File target = new File(targetDir, targetName); target.mkdir(); + dir = target; - targetName = new File(targetName, "index").getPath(); - - String targetNameOrig = targetName; - targetName += getDefaultExtension(); - - target = new File(targetDir, targetName); + target = new File(targetDir, targetName + getDefaultExtension(true)); - writer = new FileWriter(target); + writer = new BufferedWriter(new OutputStreamWriter( + new FileOutputStream(target), "UTF-8")); try { super.process(story, targetDir, targetNameOrig); } finally { @@ -38,19 +43,65 @@ class Html extends BasicOutput { writer = null; } + // write a copy of the originals inside + InfoCover.writeInfo(dir, targetName, story.getMeta()); + InfoCover.writeCover(dir, targetName, story.getMeta()); + BasicOutput.getOutput(OutputType.TEXT, isWriteInfo(), isWriteCover()) + .process(story, dir, targetNameOrig); + + if (story.getMeta().getCover() != null) { + Instance.getCache().saveAsImage(story.getMeta().getCover(), + new File(dir, "cover"), true); + } + return target; } @Override - public String getDefaultExtension() { - return ".html"; + public String getDefaultExtension(boolean readerTarget) { + if (readerTarget) { + return File.separator + "index.html"; + } + + return ""; } @Override protected void writeStoryHeader(Story story) throws IOException { String title = ""; + String tags = ""; + String author = ""; + Chapter resume = null; if (story.getMeta() != null) { - title = story.getMeta().getTitle(); + MetaData meta = story.getMeta(); + title = meta.getTitle(); + resume = meta.getResume(); + if (meta.getTags() != null) { + for (String tag : meta.getTags()) { + if (!tags.isEmpty()) { + tags += ", "; + } + tags += tag; + } + + if (!tags.isEmpty()) { + tags = "(" + tags + ")"; + } + } + author = meta.getAuthor(); + } + + String format = Instance.getConfig() + .getString(Config.IMAGE_FORMAT_COVER).toLowerCase(); + + InputStream inStyle = getClass().getResourceAsStream("html.style.css"); + if (inStyle == null) { + throw new IOException("Cannot find style.css resource"); + } + try { + IOUtils.write(inStyle, new File(dir, "style.css")); + } finally { + inStyle.close(); } writer.write(""); @@ -58,11 +109,39 @@ class Html extends BasicOutput { writer.write("\n
"); writer.write("\n "); writer.write("\n "); + writer.write("\n "); writer.write("\n