]>
pere.pagekite.me Git - text-madewithcc.git/blob - fixup.rb
4 raise ArgumentError
, 'Source/destination files not specified' if ARGV.size !
= 2
8 data=File
.open(srcfile
).readlines
.map
{|l
| l
.chomp!
}
10 data.map
{|lin
| lin
.gsub!
(/\[\]{#anchor-?\d*}/, '')}
13 indicators
= %w(! •
# -)
15 print indicators
[level
]
17 print
"\n%s %s\n" % ['*' * (level+
1), what
]
21 # There are several titles that are spread in more than one line. Make
22 # them into translatable sentences.
23 log
0, 'Merging multiline sentences '
24 [ ['Made', '', 'with', '', 'Creative', '', 'Commons'],
25 ['The New','', 'World of', '', 'Digital', '', 'Commons'],
26 ['How', '', 'to Be', '', 'Made with', '', 'Creative', '', 'Commons'],
27 ['Providing a custom service to consumers of your work *', '\[MARKET-BASED\]*'],
28 ['Memberships and individual donations', '*\[RECIPROCITY-BASED\]*'],
29 ['The', '', 'Creative', '', 'Commons', '', 'Licenses'],
30 ['jonathanmann.net and', '', 'jonathanmann.bandcamp.com'],
31 ['PLOS','', '(Public Library of Science)']
33 # This should be done more generic, more robust... But before
34 # burning brain cells, verify if it's needed!
37 data.each_with_index
do |lin
, idx
|
43 raise RuntimeError
, 'Anchor string («%s» for «%s») not found' %
44 [str
[0], str
.reject
{|word
| word
==''}.join(' ')]
45 elsif matches
.size
> 1
46 raise RuntimeError
, 'Anchor string (%s) appears multiple times: %s' %
47 [str
[0], matches
.map
{|i
| i
.to_s
}.join(', ')]
49 log
2, 'Matches %s: %d - %s' % [str
.join(' '), matches
.size
, matches
.join(',')]
52 at
= data.index(str
[0])
53 joined
= str
.reject
{|word
| word
==''}.join(' ')
55 if str
[offset
] !
= data[at+offset
]
57 'Warning: String does not match ("%s" of "%s", offset %d, book at %d)' %
58 [str
[offset
], joined
, offset
, at+offset
]
63 (str
.size
- 1).times
{ data.delete_at(at+
1) }
66 # Mark up headings: Very artisanal and suboptimal, but should do the
69 # For every heading, put here the full string and its heading level,
77 # Try to keep this ordered as it appears within the book, as it will
78 # help us spot omissions and mistakes!
79 log
0, 'Mark up headings'
83 [1, 'The Big Picture'],
84 [2, 'The New World of Digital Commons'],
85 [3, 'The Commons, the Market, and the State'],
86 [3, 'The Four Aspects of a Resource'],
87 [4, 'Characteristics'],
88 [4, 'People and processes'],
89 [4, 'Norms and rules'],
91 [3, 'A Short History of the Commons'],
92 [3, 'The Digital Revolution'],
93 [3, 'The Birth of Creative Commons'],
94 [3, 'The Changing Market'],
95 [3, 'Benefits of the Digital Commons'],
96 [3, 'Our Case Studies'],
98 [2, 'How to Be Made with Creative Commons'],
99 [3, 'Problem Zero: Getting Discovered'],
100 [4, 'Use CC to grow a larger audience'],
101 [4, 'Use CC to get attribution and name recognition'],
102 [4, 'Use CC-licensed content as a marketing tool'],
103 [4, 'Use CC to enable hands-on engagement with your work'],
104 [4, 'Use CC to differentiate yourself'],
106 [4, 'Market-based revenue streams'],
107 [4, 'Providing a custom service to consumers of your work * \[MARKET-BASED\]*'],
108 [4, 'Charging for the physical copy * \[MARKET-BASED\]*'],
109 [4, 'Charging for the in-person version * \[MARKET-BASED\]*'],
110 [4, 'Selling merchandise * \[MARKET-BASED\]*'],
111 [4, 'Charging advertisers or sponsors * \[MARKET-BASED\]*'],
112 [4, 'Charging your content creators * \[MARKET-BASED\]*'],
113 [4, 'Charging a transaction fee * \[MARKET-BASED\]*'],
114 [4, 'Providing a service to your creators* \[MARKET-BASED\]*'],
115 [4, 'Licensing a trademark* \[MARKET-BASED\]*'],
116 [4, 'Reciprocity-based revenue streams'],
117 [4, 'Memberships and individual donations *\[RECIPROCITY-BASED\]*'],
118 [4, 'The pay-what-you-want model *\[RECIPROCITY-BASED\]*'],
119 [4, 'Crowdfunding *\[RECIPROCITY-BASED\]*'],
120 [3, 'Making Human Connections'],
122 [4, 'Be open and accountable'],
123 [4, 'Design for the good actors'],
124 [4, 'Treat humans like, well, humans'],
125 [4, 'State your principles and stick to them'],
126 [4, 'Build a community'],
127 [4, 'Give more to the commons than you take'],
128 [4, 'Involve people in what you do'],
130 [2, 'The Creative Commons Licenses'],
132 [1, 'The Case Studies'],
135 [2, 'Blender Institute'],
136 [2, 'Cards Against Humanity'],
137 [2, 'The Conversation'],
138 [2, 'Cory Doctorow'],
141 [2, 'Knowledge Unlatched'],
142 [2, 'Lumen Learning'],
143 [2, 'Jonathan Mann'],
145 [2, 'Open Data Institute'],
148 [2, 'Amanda Palmer'],
149 [2, 'PLOS (Public Library of Science)'],
155 [2, 'Tribe of Noise'],
156 [2, 'Wikimedia Foundation'],
158 [2, 'Acknowledgments'],
161 log
1, item
.join(' -> ')
162 at
= data.index
{|i
| i
== item
[1]}
164 raise RuntimeError
, 'Heading string (level %d) not found: «%s»' % item
166 data[at
] = '%s %s' % ['#' * item
[0], data[at
]]
169 # We have the explicit strings "Part 1" and "Part 2" as structural
170 # elements — They are to be generated upon book compilation. Nuke
172 data.delete("# Part 1")
173 data.delete("# Part 2")
175 # Join erroneously split paragraphs: Write the contents of the line
176 # _preceding_ the unneeded break, the break will be removed.
178 # I'm noting the line number for each _after_ corrections so it's
179 # easier to find them; please keep them sorted! :-P
180 log
0, 'Join erroneously split paragraphs'
181 ['content and, in turn, spend money and', # 1595
182 'still other', # 1662
183 'content functions as a marketing tool for the paid product or', # 1724
184 'lowest-common-denominator solutions and', #2035
185 'to the values symbolized by', # 2145
186 'the kinds of participative communities that drive open', # 2157
188 'At a minimum, a CC-', # 2375
189 'easier to trust a', # 2580
190 'free download, the', # 3086
191 'openness to fans remixing the game—give', # 3087
192 'Attribution-', # 3307
193 'both journal publishers and researchers. Figshare now provides', # 3672
194 'get the “network effect”—', # 4002
195 'access to scholarly books. For Frances, the current scholarly-', # 4033
198 'contributing to the open', # 4438
199 'doesn’t seem like it should be sung about', # 4616
200 'songwriter, and he has found a way to keep it interesting for', # 4624
201 'building trust is the top', # 4793
204 'authors and Shuttleworth; Mark remains incredibly proud of this', # 6452
205 'BY-SA and opting in others with collecting societies like', # 7218
206 'Cecilie Maria, Cedric Howe, Cefn Hoile,', # 7796
207 'Braddlee, Drew Spencer, Duncan', # 7839
208 'Elizabeth Holloway, Ellen Buecher, Ellen Kaye-', # 7844
212 at
= data.index
{|i
| i
== line
}
213 if !at
.nil? and data[at+
1] == ''
218 log
0, 'Mark quote in dedication as quote with attribute in markdown'
219 start
= "“I don’t know a whole lot about nonfiction journalism. . ."
220 stop
= "- David Foster Wallace"
222 data.each_with_index
do |lin
, idx
|
224 lin
.sub!
(/^- /, "> — ")
225 lin
.sub!
("David Foster Wallace", "*David Foster Wallace*")
237 log
0, 'Writing processed file'
238 File
.open(dstfile
, 'w') {|f
| f
.puts
data.join("\n")}