Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate Epub #19

Open
michaeltlombardi opened this issue Sep 9, 2021 · 6 comments
Open

Generate Epub #19

michaeltlombardi opened this issue Sep 9, 2021 · 6 comments
Labels

Comments

@michaeltlombardi
Copy link
Contributor

As a writer, it would be useful to generate a single epub file for a game text hosted in a platen site.

@michaeltlombardi
Copy link
Contributor Author

Some ideas:

  • Recurse through the structure of the specified folder to determine correct ordering automatically (weight if specified in front matter, alphabetized if not)
  • Convert shortcodes into valid HTML where possible and approximate markdown where not
    • In particular, this needs careful handling for all default shortcodes
  • Use pandoc to export, passing along metadata as required
  • Standalone CLI tool of some sort, likely a go binary or powershell script?
  • Integrate with VSCode Extension

@binarystargames
Copy link
Contributor

Working on this now (using a go script for now run from command line). My strategy thus far has been to let Hugo do most of the work:

  • Have go execute hugo in the terminal to create the HTML site
  • Use the base index of the site to crawl the TOC within docs and determine locations of pages to pick up based on that (this also picks up the right order)
  • Grab the tag from each of those pages, dump the contents into a string for each doc
  • Dump each doc into an HTML file with a string based on that file.

This works ok to create an HTML dump of each directory in docs and circumvents the shortcodes problem (the site has already been rendered, so the shortcodes will be as well).

Need to refine and automate it further - css doesn't get to the right place on its own, I haven't done the pandoc stuff yet, and my cssClass injection magic isn't working yet. Also it has those anchors for each header and it probably shouldn't. But all in all this seems workable.

@binarystargames
Copy link
Contributor

Followup: The above works great for creating an HTML dump (which can then be Pandoc'd into a standalone HTML page) but that HTML doesn't transfer to ePub worth anything. So I'm going to keep that for HTML export but I've also created a markdown compiler using the same general steps (scrape TOC, use the TOC indexing to pick up markdown files in order, clean and dump into a single markdown document).

Cleanup of Hugo headmatter tags is working, I have a kludge for shortcodes that works (since I only used columns, it just gets rid of columns and displays things sequentially) that I'm going to clean up further. I've also got a general workflow for ePub/HTML creation via pandoc that works ok.

Also the CSS from Platen/Hugo doesn't apply to the ePub doc for reasons of ePub being very particular about formatting, so we're going to have to find a way to export that. Right now I just wrote a very basic version of the CSS but it's not quite as good looking.

@michaeltlombardi
Copy link
Contributor Author

I wonder how much CSS we need to concern ourselves with for the ePub since so much of it can/will be overridden by the reader/app. This is sounding promising as hell.

@binarystargames
Copy link
Contributor

I'm not terribly concerned, it's just that a) it's an extra step and b) some readers do dumb things with tables (like Calibre just ignores any sort of separation lines and they look like shit).

Side note, I tried the resulting ePub on my phone and iBooks doesn't like linebreaks inside tables (it throws an error at that part) so further iteration is required as to what's ok vs. not.

@binarystargames
Copy link
Contributor

Answer: linebreaks need the trailing slash: <br/> vs <br>. This does not break anywhere except tables, for some reason. Either way it's fixed.

Some CSS transference to epub (right now I just have some very basic "make the tables have lines/alternating backgrounds" level stuff, not gonna bother doing like font-embedding, but a CSS file is there in case a user might want to add more) and a more rigorous shortcode eraser are implemented on bsg-site. Prior to VSCode extensions (I have no idea how to go about doing that) and any better shortcode handling that should cover the features for the most part.

I'll document/clean up everything and make a proper PR for it after 36W is released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants