commit 69ec2870f6cb1a4d12509e732d5a4f0b34aa03b7 Author: Nemo Date: Fri Oct 9 15:44:15 2020 +0530 Initial release diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..381e71f --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +vendor/ +*.epub +html/* +chapters/* +*.html +*.epub \ No newline at end of file diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..bb5c917 --- /dev/null +++ b/Gemfile @@ -0,0 +1,2 @@ +source 'https://rubygems.org' +gem 'nokogiri', '>=1.11.0.rc3' \ No newline at end of file diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..1ab17d7 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,15 @@ +GEM + remote: https://rubygems.org/ + specs: + mini_portile2 (2.5.0) + nokogiri (1.11.0.rc3) + mini_portile2 (~> 2.5.0) + +PLATFORMS + ruby + +DEPENDENCIES + nokogiri (>= 1.11.0.rc3) + +BUNDLED WITH + 2.1.4 diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..2bd1d6a --- /dev/null +++ b/LICENSE @@ -0,0 +1,7 @@ +Copyright 2020 Abhay Rana + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..fef3326 --- /dev/null +++ b/README.md @@ -0,0 +1,17 @@ +# Never Say You Can’t Survive + +![Book Cover](cover.jpg) + +“You have the power to shape worlds, and the monsters are scared of you.” + +From author Charlie Jane Anders, Never Say You Can’t Survive is a how-to book about the storytelling craft, but it’s also full of memoir, personal anecdote, and insight about how to flourish in the present emergency. + +--- + +The repository contains scripts to generate an ebook in the EPUB format from the posts at tor.com. More details at . + +The book is available for pre-order at [Amazon.com](https://www.amazon.com/Never-Say-You-Cant-Survive-ebook/dp/B08JK8XD1N) or [Indiebound](https://www.indiebound.org/book/9781250800015). + +## License + +Licensed under the [MIT License](https://nemo.mit-license.org/). See LICENSE file for details. \ No newline at end of file diff --git a/cover.jpg b/cover.jpg new file mode 100644 index 0000000..83e55ed Binary files /dev/null and b/cover.jpg differ diff --git a/generate.rb b/generate.rb new file mode 100644 index 0000000..4b3b572 --- /dev/null +++ b/generate.rb @@ -0,0 +1,57 @@ +require 'nokogiri' + +skip_classes = ['ebook-link-wrapper'] + +for i in Dir.glob('html/*.html') + html = "" + puts i + complete_html = Nokogiri::HTML(open(i)) + page = complete_html.css('.entry-content') + title = complete_html.css('.entry-title>a').inner_html[29..] + + started = ended = false + page.children.each do |e| + unless started + if e.class != Nokogiri::XML::Text + unless e.classes.include? 'frontmatter' + puts e.classes + started = true + end + end + end + + if started + trimmed = e.inner_text.gsub(/[[:space:]]/, '') + if trimmed == "" and not ['hr'].include? e.name + next + end + + if e.name == "h3" + if e.inner_text.strip[0..7] == "Section" or e.inner_text.strip[0..12] == "Introduction" + e.name = "h1" + else + e.name = "h2" + end + end + + skip = (e.classes & skip_classes).size > 0 + ended = true if e.matches?('.squib') + + if skip == false and ended == false + html += e.to_s + end + end + end + fn = File.basename(i) + File.write("chapters/#{fn}", html) +end + +html = "" +File.open("urls.txt").each do |url| + title = url.strip.split('/')[-1] + html += File.read("chapters/#{title}.html") + html += "\n\n" +end + +File.write("never-say-you-cant-survive.html", html) +`pandoc --metadata title="Never Say You Can’t Survive" -o never-say-you-cant-survive.epub --epub-metadata=metadata.xml --epub-cover-image=cover.jpg never-say-you-cant-survive.html` \ No newline at end of file diff --git a/generate.sh b/generate.sh new file mode 100755 index 0000000..826b610 --- /dev/null +++ b/generate.sh @@ -0,0 +1,22 @@ +#!/bin/bash +mkdir -p chapters html +INPUT_FILE="urls.txt" +function assert_installed() { + for var in "$@"; do + if ! which $var &> /dev/null; then + echo "Install $var!" + exit 1 + fi + done +} + +assert_installed wget pandoc + +while IFS= read -r line +do + echo $line + FILENAME=$(basename "$line") + wget --no-clobber --no-verbose --output-document="html/$FILENAME.html" --timeout=10 "$line" +done < "$INPUT_FILE" + +bundle exec ruby generate.rb \ No newline at end of file diff --git a/metadata.xml b/metadata.xml new file mode 100644 index 0000000..1703cc1 --- /dev/null +++ b/metadata.xml @@ -0,0 +1,5 @@ +Never Say You Can't Survive +978-1250800015 +2021-08-17 +en-US +Charlie Jane Anders \ No newline at end of file diff --git a/urls.txt b/urls.txt new file mode 100644 index 0000000..a9509b9 --- /dev/null +++ b/urls.txt @@ -0,0 +1,20 @@ +https://www.tor.com/2020/05/12/never-say-you-cant-survive-how-to-get-through-hard-times-by-making-up-stories/ +https://www.tor.com/2020/05/19/never-say-you-cant-survive-imposter-syndrome-is-just-part-of-being-a-writer/ +https://www.tor.com/2020/05/26/never-say-you-cant-survive-embrace-uncertainty-the-joy-of-making-a-giant-mess/ +https://www.tor.com/2020/06/09/never-say-you-cant-survive-everything-is-broken-what-should-i-write-about/ +https://www.tor.com/2020/06/16/never-say-you-cant-survive-dont-be-afraid-to-go-on-lots-of-first-dates-with-story-ideas/ +https://www.tor.com/2020/06/23/never-say-you-cant-survive-the-secret-to-storytelling-just-one-good-scene-and-then-another-and-another/ +https://www.tor.com/2020/06/30/never-say-you-cant-survive-the-most-powerful-thing-a-story-can-do-is-show-how-people-change/ +https://www.tor.com/2020/07/14/never-say-you-cant-survive-a-good-plot-is-made-out-of-two-things/ +https://www.tor.com/2020/07/21/never-say-you-cant-survive-how-to-tell-a-thrilling-story-without-breaking-your-own-heart/ +https://www.tor.com/2020/07/28/never-say-you-cant-survive-the-ending-is-the-beginning/ +https://www.tor.com/2020/08/04/never-say-you-cant-survive-hold-on-to-your-anger-its-a-storytelling-goldmine/ +https://www.tor.com/2020/08/11/never-say-you-cant-survive-people-are-only-as-interesting-as-their-relationships/ +https://www.tor.com/2020/08/18/never-say-you-cant-survive-one-easy-way-to-feel-better-about-the-world/ +https://www.tor.com/2020/08/25/never-say-you-cant-survive-revision-is-the-process-of-turning-fake-emotion-into-real-emotion/ +https://www.tor.com/2020/09/01/never-say-you-cant-survive-twelve-ways-to-keep-the-fun-of-writing-alive/ +https://www.tor.com/2020/09/08/never-say-you-cant-survive-how-to-write-a-political-story-without-falling-on-your-face/ +https://www.tor.com/2020/09/15/never-say-you-cant-survive-good-worldbuilding-shows-how-things-could-be-different/ +https://www.tor.com/2020/09/22/never-say-you-cant-survive-the-unexamined-story-is-not-worth-writing/ +https://www.tor.com/2020/09/29/never-say-you-cant-survive-weirdness-gives-me-the-strength-to-keep-going/ +https://www.tor.com/2020/10/06/never-say-you-cant-survive-when-is-it-okay-to-write-about-someone-elses-culture-or-experience/