Skip to content

Commit 14bc87a

Browse files
committed
book(xrefs): maintain question marks that are part of the URL path
We need to be careful to allow for a trailing question mark in the sections' titles; These need to be (URL-)encoded in the URL and not be mistaken for the separator between path and GET parameter(s). While at it, also install redirects for URLs containing a question mark so that incorrect URLs that contain a literal question mark (which is interpreted as separator between the URL path and the `GET` parameter(s)) redirect to the correct ones. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 415636d commit 14bc87a

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

script/book.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def save
107107
sections.append({
108108
"cs_number" => section.cs_number,
109109
"title" => section.title,
110-
"url" => section.relative_url(nil)
110+
"url" => section.relative_url(nil).gsub(/%3F/, '?')
111111
})
112112
end
113113
chapters.append({
@@ -263,7 +263,13 @@ def front_matter
263263
"next" => self.next_section_url
264264
}
265265
if @slug =~ /:|[^-A-Za-z0-9_]/
266-
front_matter["url"] = self.relative_url(@slug)
266+
relative_url = self.relative_url(@slug)
267+
front_matter["url"] = "/#{relative_url.gsub(/%3F/, '?')}.html"
268+
if relative_url =~ /%3F/
269+
front_matter["aliases"] = [
270+
"/#{relative_url.gsub(/%3F.*/, '')}.html"
271+
]
272+
end
267273
end
268274
return front_matter
269275
end
@@ -294,7 +300,7 @@ def relative_url(path)
294300
if path.nil? || path.empty?
295301
path = self.slug
296302
end
297-
return @chapter.relative_url(path)
303+
return @chapter.relative_url(path.gsub(/\?/, '%3F'))
298304
end
299305

300306
def previous_section_url

0 commit comments

Comments
 (0)