Author: jsirois
Date: Tue Apr 19 17:16:24 2016
New Revision: 1739964

URL: http://svn.apache.org/viewvc?rev=1739964&view=rev
Log:
Fixup Rakefile to handle a full doc tree.

This addresses https://issues.apache.org/jira/browse/AURORA-1668

Modified:
    aurora/site/Rakefile

Modified: aurora/site/Rakefile
URL: 
http://svn.apache.org/viewvc/aurora/site/Rakefile?rev=1739964&r1=1739963&r2=1739964&view=diff
==============================================================================
--- aurora/site/Rakefile (original)
+++ aurora/site/Rakefile Tue Apr 19 17:16:24 2016
@@ -72,6 +72,7 @@ task :generate_docs, [:title, :git_tag]
   is_master = ['master', 'HEAD'].include? git_tag
   archive_root = if is_master then "aurora-#{git_tag}" else 
"aurora-rel-#{git_tag}" end
   archive_rel_url = if is_master then zip_name else "rel/#{zip_name}" end
+  full_tag = if is_master then git_tag else "rel/#{git_tag}" end
 
   Dir.chdir(tmp_dir) {
     if File.exist?(zip_name) and not is_master
@@ -80,7 +81,8 @@ task :generate_docs, [:title, :git_tag]
       puts "Fetching archive of #{git_tag}"
       system("wget https://github.com/apache/aurora/archive/#{archive_rel_url} 
-O #{zip_name}")
     end
-    system("unzip -o #{zip_name} '#{archive_root}/docs/*'")
+    system("unzip -o #{zip_name} '#{archive_root}/docs/*' 
'#{archive_root}/CONTRIBUTING.md'")
+    FileUtils.mv(File.join(archive_root, 'CONTRIBUTING.md'), 
File.join(archive_root, 'docs/CONTRIBUTING.md'))
   }
 
   docs_in_dir = File.join(tmp_dir, archive_root, 'docs')
@@ -101,21 +103,28 @@ task :generate_docs, [:title, :git_tag]
       FileUtils.mv(contributing_doc, contributing_doc.downcase)
     end
 
-    Dir.glob('*.md').each { |doc|
+    Dir.glob('**/*.md').each { |doc|
       puts "working on: #{doc}"
 
       # Hacks to make markdown intended for GitHub work.
       IO.write(doc, File.open(doc, :encoding => 'utf-8') { |f|
+        # Add an extra .. to account for middleman s/page/dir/ for a link in 
any page except the top-level index.
+        rel_prefix = if File.dirname(f.path) == "." then "" else "../" end
+
         f.read.
             # Rewrite links to '../CONTRIBUTING.md'.
             gsub(/\.\.\/CONTRIBUTING\.md/, 'contributing/').
-            # Rewrite links pointing to source files in the repository.
-            gsub(/\]\(\.\.\/([^\)]+\))/, 
'](https://github.com/apache/aurora/blob/#{git_tag}/\1)').
-            # Remove .md extension in links.
-            gsub(/\(([A-Za-z0-9-]+)\.md(#[^\)]+)?\)/, 
"(/documentation/#{title}/\\1/\\2)").
+            
+            # Rewrite source links pointing to source files in the repository.
+            
gsub(/\]\((?:\.\.\/)+([^\)]+\.(?:java|py|js|thrift|xml|json|conf))\)/, 
"](https://github.com/apache/aurora/blob/#{full_tag}/\\1)").
+            
+            # For relative links, remove .md extension (We have no absolute 
links and we do not try to handle those here).
+            gsub(/\(((?:[._A-Za-z0-9-]+\/)*[_A-Za-z0-9-]+)\.md(#[^\)]+)?\)/, 
"(#{rel_prefix}\\1/\\2)").
+
             # Fix anchor links and names, which GitHub prefixes with 
'user-content-'
             # See AURORA-726.
             gsub(/#user-content\-/, '#').
+
             # Fix image links.  This is necessary because middleman turns each 
markdown page
             # into a directory name.  During this process, relative image tags 
in HTML are not
             # adjusted accordingly.


Reply via email to