Initial release

This commit is contained in:
Nemo 2020-10-09 15:44:15 +05:30
commit 69ec2870f6
10 changed files with 151 additions and 0 deletions

6
.gitignore vendored Normal file
View File

@ -0,0 +1,6 @@
vendor/
*.epub
html/*
chapters/*
*.html
*.epub

2
Gemfile Normal file
View File

@ -0,0 +1,2 @@
source 'https://rubygems.org'
gem 'nokogiri', '>=1.11.0.rc3'

15
Gemfile.lock Normal file
View File

@ -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

7
LICENSE Normal file
View File

@ -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.

17
README.md Normal file
View File

@ -0,0 +1,17 @@
# Never Say You Cant 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 Cant Survive is a how-to book about the storytelling craft, but its 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 <https://www.tor.com/series/never-say-you-cant-survive-by-charlie-jane-anders/>.
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.

BIN
cover.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

57
generate.rb Normal file
View File

@ -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 Cant Survive" -o never-say-you-cant-survive.epub --epub-metadata=metadata.xml --epub-cover-image=cover.jpg never-say-you-cant-survive.html`

22
generate.sh Executable file
View File

@ -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

5
metadata.xml Normal file
View File

@ -0,0 +1,5 @@
<dc:title>Never Say You Can't Survive </dc:title>
<dc:identifier opf:scheme="ISBN-13">978-1250800015</dc:identifier>
<dc:date>2021-08-17</dc:date>
<dc:language>en-US</dc:language>
<dc:creator opf:role="aut">Charlie Jane Anders</dc:creator>

20
urls.txt Normal file
View File

@ -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/