/// <summary> /// Writes the <see cref="PublicationFiles.EpubFileTitle"/> file. /// </summary> public void WriteTitle() { Console.WriteLine("writing Title data..."); var jPublication = _publicationMeta.GetJObject("publication"); var title = jPublication.GetValue <string>("title"); var author = jPublication.GetValue <string>("author"); var xhtml = PublicationNamespaces.Xhtml; var path = ProgramFileUtility.GetCombinedPath(_epubTextDirectory, PublicationFiles.EpubFileTitle, fileIsExpected: true); var titleDocument = XDocument.Load(path); var h1Element = titleDocument.Root .Element(xhtml + "body") .Element(xhtml + "div") .Element(xhtml + "h1"); var spanElement = titleDocument.Root .Element(xhtml + "body") .Element(xhtml + "div") .Element(xhtml + "span"); h1Element.Value = title; spanElement.Value = author; EpubUtility.SaveAsUnicodeWithBom(titleDocument, path); }
/// <summary> /// Generates EPUB chapters /// from <see cref="PublicationFiles.EpubMetadata"/>. /// </summary> public void GenerateChapters() { _chapterSet.ToList().ForEach(pair => { var chapterDirectory = ProgramFileUtility.GetCombinedPath(_markdownDirectory, pair.Value, fileIsExpected: false); Console.WriteLine("looking for {0}...", pair.Key); if (!Directory.Exists(chapterDirectory)) { Throw(string.Format("ERROR: cannot find {0}", chapterDirectory)); } var chapter = new PublicationChapter(pair, _chapterTemplate, chapterDirectory); var xhtml = chapter.GenerateXhtml(); var path = ProgramFileUtility.GetCombinedPath(_epubTextDirectory, string.Format("{0}.xhtml", pair.Key), fileIsExpected: true); Console.WriteLine("writing to {0}...", path); File.WriteAllText(path, xhtml, EpubUtility.GetUnicodeWithBomEncoding()); }); }