diff --git a/.gitignore b/.gitignore index 48d36d8..03b0b5d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ /wok/*.html /wor/*.html /oathbringer/*.html +/wok-prime/*.html /edgedancer/*.html /books/* diff --git a/README.md b/README.md index e0c0950..25bd500 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ Scripts to generate books from the [Cosmere]() using various public sources. Cur 2. Way of Kings Reread 3. Words of Radiance Reread 4. Edgedancer Reread +5. Way of Kings Prime For obvious reasons, the converted ebooks are not part of this repo. You must download and run the script on your own machine to generate the copies. @@ -40,6 +41,14 @@ Join Alice Arneson and Lyndsey Luther for a reread of Brandon Sanderson’s Cosm More details at https://www.tor.com/series/edgedancer-reread-brandon-sanderson/ +## Way of Kings: Prime + +>For it([Altered Perceptions anthology](https://www.indiegogo.com/projects/altered-perceptions)), I’m letting people see—for the first time—a large chunk of the original version of The Way of Kings, which I wrote in 2002–2003. This version is very different, and involves a different course in life for Kaladin as a character—all due to a simple decision he makes one way in this book, but a completely different way in the published novel. + +>These chapters are quite fun, as I consider what happened in The Way of Kings Prime (as I now call it) to be an "alternate reality" version of the events in the published books. The characters are almost all exactly the same people, but their backstories are different, and that has transformed who they are and how they react to the world around them. Roshar is similar, yet wildly different, as this was before I brought in the spren as a major world element. + +You can read more at the announcement at [BrandonSanderson.com](https://brandonsanderson.com/chapters-from-the-original-draft-of-the-way-of-kings-available-in-anthology-to-benefit-robison-wells/) + ## Requirements - Ruby @@ -87,7 +96,13 @@ To generate the book: ruby edgedancer-reread.rb -All the generated files will be saved with the filename `books/edgedan-reread.{epub|pdf|mobi|html}`. This generation might take a while because it contains a lot of images. It doesn't have the best possible index either, but is still pretty readable. +All the generated files will be saved with the filename `books/edgedancer-reread.{epub|pdf|mobi|html}`. This generation might take a while because it contains a lot of images. It doesn't have the best possible index either, but is still pretty readable. + +## Way of Kings Prime + + ruby wok-prime.rb + +All the generated files will be saved with the filename `books/wok-prime.{epub|pdf|mobi|html}`. This generation might take a while the script attempts to strip out unnecessary HTML. ## Extra diff --git a/covers/wok-prime.jpg b/covers/wok-prime.jpg new file mode 100644 index 0000000..e389380 Binary files /dev/null and b/covers/wok-prime.jpg differ diff --git a/covers/wok-prime.pdf b/covers/wok-prime.pdf new file mode 100644 index 0000000..1bd428c Binary files /dev/null and b/covers/wok-prime.pdf differ diff --git a/metadata/wok-prime.xml b/metadata/wok-prime.xml new file mode 100644 index 0000000..1c174dc --- /dev/null +++ b/metadata/wok-prime.xml @@ -0,0 +1,4 @@ +The Way of Kings Prime +2017-09-18 +en-US +Brandon Sanderson diff --git a/wok-prime.rb b/wok-prime.rb new file mode 100644 index 0000000..28a0374 --- /dev/null +++ b/wok-prime.rb @@ -0,0 +1,56 @@ +require 'date' +require 'fileutils' +require 'nokogiri' +require_relative './methods' + +FileUtils.mkdir_p('wok-prime') + +BASE = 'https://brandonsanderson.com/'.freeze + +links = [ + 'the-way-of-kings-prime-jeksonsonvallano/', + 'altered-perceptions/', + 'way-of-kings-prime-chapter-1-dalenar-1/', + 'way-of-kings-prime-chapter-3-merin-1/', + 'way-of-kings-prime-chapter-5-merin-2/' +] + +episode = 1 + +links.each do |link| + url = BASE + link + puts "Download #{url}" + unless File.exist? "wok-prime/#{episode}.html" + `wget --no-clobber "#{url}" --output-document "wok-prime/#{episode}.html" -o /dev/null` + end + episode += 1 +end + +html = '' +for i in 1..(links.length) + complete_html = Nokogiri::HTML(open("wok-prime/#{i}.html")) + page = complete_html.css('article')[0] + + ending = false + + page.traverse do |e| + whitelist = ['p', 'div', 'span', 'article', 'h1', 'h2', 'h3', 'h4', 'a', 'h5', 'h6', 'i', 'text'] + blacklist = ['.post-meta', '.addthis_toolbox', '.book-links', 'post-nav'] + if (whitelist.include?(e.name) == false) + e.remove + end + + blacklist.each do |selector| + page.css(selector).each do |e| + e.remove + end + end + end + + html += page.inner_html +end + +File.open('books/wok-prime.html', 'w') { |file| file.write(html) } +puts '[html] Generated HTML file' + +generate('wok-prime', :all)