]>
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 log
0, 'correct emphesis in some titles'
67 data.map
{|lin
| lin
.gsub!
(/ *\* \\\[/, ' *\[')}
69 # Mark up headings: Very artisanal and suboptimal, but should do the
72 # For every heading, put here the full string and its heading level,
80 # Try to keep this ordered as it appears within the book, as it will
81 # help us spot omissions and mistakes!
82 log
0, 'Mark up headings'
86 [1, 'The Big Picture'],
87 [2, 'The New World of Digital Commons'],
88 [3, 'The Commons, the Market, and the State'],
89 [3, 'The Four Aspects of a Resource'],
90 [4, 'Characteristics'],
91 [4, 'People and processes'],
92 [4, 'Norms and rules'],
94 [3, 'A Short History of the Commons'],
95 [3, 'The Digital Revolution'],
96 [3, 'The Birth of Creative Commons'],
97 [3, 'The Changing Market'],
98 [3, 'Benefits of the Digital Commons'],
99 [3, 'Our Case Studies'],
101 [2, 'How to Be Made with Creative Commons'],
102 [3, 'Problem Zero: Getting Discovered'],
103 [4, 'Use CC to grow a larger audience'],
104 [4, 'Use CC to get attribution and name recognition'],
105 [4, 'Use CC-licensed content as a marketing tool'],
106 [4, 'Use CC to enable hands-on engagement with your work'],
107 [4, 'Use CC to differentiate yourself'],
109 [4, 'Market-based revenue streams'],
110 [4, 'Providing a custom service to consumers of your work *\[MARKET-BASED\]*'],
111 [4, 'Charging for the physical copy *\[MARKET-BASED\]*'],
112 [4, 'Charging for the in-person version *\[MARKET-BASED\]*'],
113 [4, 'Selling merchandise *\[MARKET-BASED\]*'],
114 [4, 'Charging advertisers or sponsors *\[MARKET-BASED\]*'],
115 [4, 'Charging your content creators *\[MARKET-BASED\]*'],
116 [4, 'Charging a transaction fee *\[MARKET-BASED\]*'],
117 [4, 'Providing a service to your creators *\[MARKET-BASED\]*'],
118 [4, 'Licensing a trademark *\[MARKET-BASED\]*'],
119 [4, 'Reciprocity-based revenue streams'],
120 [4, 'Memberships and individual donations *\[RECIPROCITY-BASED\]*'],
121 [4, 'The pay-what-you-want model *\[RECIPROCITY-BASED\]*'],
122 [4, 'Crowdfunding *\[RECIPROCITY-BASED\]*'],
123 [3, 'Making Human Connections'],
125 [4, 'Be open and accountable'],
126 [4, 'Design for the good actors'],
127 [4, 'Treat humans like, well, humans'],
128 [4, 'State your principles and stick to them'],
129 [4, 'Build a community'],
130 [4, 'Give more to the commons than you take'],
131 [4, 'Involve people in what you do'],
133 [2, 'The Creative Commons Licenses'],
135 [1, 'The Case Studies'],
138 [2, 'Blender Institute'],
139 [2, 'Cards Against Humanity'],
140 [2, 'The Conversation'],
141 [2, 'Cory Doctorow'],
144 [2, 'Knowledge Unlatched'],
145 [2, 'Lumen Learning'],
146 [2, 'Jonathan Mann'],
148 [2, 'Open Data Institute'],
151 [2, 'Amanda Palmer'],
152 [2, 'PLOS (Public Library of Science)'],
158 [2, 'Tribe of Noise'],
159 [2, 'Wikimedia Foundation'],
161 [2, 'Acknowledgments'],
164 log
1, item
.join(' -> ')
165 at
= data.index
{|i
| i
== item
[1]}
167 raise RuntimeError
, 'Heading string (level %d) not found: «%s»' % item
169 data[at
] = '%s %s' % ['#' * item
[0], data[at
]]
172 # We have the explicit strings "Part 1" and "Part 2" as structural
173 # elements — They are to be generated upon book compilation. Nuke
175 data.delete("# Part 1")
176 data.delete("# Part 2")
178 # Join erroneously split paragraphs: Write the contents of the line
179 # _preceding_ the unneeded break, the break will be removed.
181 # I'm noting the line number for each _after_ corrections so it's
182 # easier to find them; please keep them sorted! :-P
183 log
0, 'Join erroneously split paragraphs'
184 ['content and, in turn, spend money and', # 1595
185 'still other', # 1662
186 'content functions as a marketing tool for the paid product or', # 1724
187 'lowest-common-denominator solutions and', #2035
188 'to the values symbolized by', # 2145
189 'the kinds of participative communities that drive open', # 2157
191 'At a minimum, a CC-', # 2375
192 'easier to trust a', # 2580
193 'free download, the', # 3086
194 'openness to fans remixing the game—give', # 3087
195 'Attribution-', # 3307
196 'both journal publishers and researchers. Figshare now provides', # 3672
197 'get the “network effect”—', # 4002
198 'access to scholarly books. For Frances, the current scholarly-', # 4033
201 'contributing to the open', # 4438
202 'doesn’t seem like it should be sung about', # 4616
203 'songwriter, and he has found a way to keep it interesting for', # 4624
204 'building trust is the top', # 4793
207 'authors and Shuttleworth; Mark remains incredibly proud of this', # 6452
208 'BY-SA and opting in others with collecting societies like', # 7218
209 'Cecilie Maria, Cedric Howe, Cefn Hoile,', # 7796
210 'Braddlee, Drew Spencer, Duncan', # 7839
211 'Elizabeth Holloway, Ellen Buecher, Ellen Kaye-', # 7844
215 at
= data.index
{|i
| i
== line
}
216 if !at
.nil? and data[at+
1] == ''
221 log
0, 'Mark quote in dedication as quote with attribute in markdown'
222 start
= "“I don’t know a whole lot about nonfiction journalism. . ."
223 stop
= "- David Foster Wallace"
225 data.each_with_index
do |lin
, idx
|
227 lin
.sub!
(/^- /, "> — ")
228 lin
.sub!
("David Foster Wallace", "*David Foster Wallace*")
240 log
0, 'Writing processed file'
241 File
.open(dstfile
, 'w') {|f
| f
.puts
data.join("\n")}