File: use-slugs-in-faq.diff

package info (click to toggle)
ruby-sqlite3 1.3.11-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 444 kB
  • ctags: 740
  • sloc: ruby: 3,822; ansic: 1,198; makefile: 9
file content (37 lines) | stat: -rw-r--r-- 1,190 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
Description: Use slugs in FAQ instead of object_id
 In order to make the FAQ build reproducibly we use “slugs” for
 internal links instead of object ids.
Author: Jérémy Bobbio <lunar@debian.org>
Bug-Debian: https://bugs.debian.org/782884

--- ruby-sqlite3-1.3.9.orig/faq/faq.rb
+++ ruby-sqlite3-1.3.9/faq/faq.rb
@@ -1,6 +1,10 @@
 require 'yaml'
 require 'redcloth'
 
+def slugify( str )
+  str.downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, '')
+end
+
 def process_faq_list( faqs )
   puts "<ul>"
   faqs.each do |faq|
@@ -20,7 +24,7 @@ def process_faq_list_item( faq )
     puts question_text
     process_faq_list answer
   else
-    print "<a href='##{question.object_id}'>#{question_text}</a>"
+    print "<a href='##{slugify(question)}'>#{question_text}</a>"
   end
 
   puts "</li>"
@@ -43,7 +47,7 @@ def process_faq_description( faq, path )
     title = RedCloth.new( path ).to_html.gsub( %r{</?p>}, "" )
     answer = RedCloth.new( answer || "" )
 
-    puts "<a name='#{question.object_id}'></a>"
+    puts "<a name='#{slugify(question)}'></a>"
     puts "<div class='faq-title'>#{title}</div>"
     puts "<div class='faq-answer'>#{add_api_links(answer.to_html)}</div>"
   end