[LON-CAPA-cvs] cvs: modules /gerd/Wiki convert.pl

www www at source.lon-capa.org
Wed Dec 14 17:52:50 EST 2011


www		Wed Dec 14 22:52:50 2011 EDT

  Modified files:              
    /modules/gerd/Wiki	convert.pl 
  Log:
  Done with links and relative links
  
  
Index: modules/gerd/Wiki/convert.pl
diff -u modules/gerd/Wiki/convert.pl:1.7 modules/gerd/Wiki/convert.pl:1.8
--- modules/gerd/Wiki/convert.pl:1.7	Wed Dec 14 18:40:26 2011
+++ modules/gerd/Wiki/convert.pl	Wed Dec 14 22:52:49 2011
@@ -1,5 +1,6 @@
 use strict;
 use File::Copy;
+use File::Spec::Unix;
 
 my %residx=();
 my %resdir=();
@@ -103,7 +104,7 @@
       my $redir=&unformat($1);
       unless ($residx{$redir}) {
 # How did that happen? The redirect points nowhere
-         print "*** WARNING: $redir not defined!\n";
+    #     print "*** WARNING: $redir not defined!\n";
       } else {
          my $oldref=$idxres{$idx};
 # Changing $oldref to $redir
@@ -160,27 +161,27 @@
    $ref=~s/[^\w\?\)]+$//gs;
    $ref=~s/\%27/\'/g;
    my $filename;
-   my $filedir;
+   my $filedirectory;
    if ($ref=~/^file\:\s*(.+)$/i) {
       my $link=&unformat($1);
       my $fn=$filereference{$link};
       unless ($fn) {
-         print "WARNING: [$ref] does not exist\n";
+         print "WARNING: missing [$ref]\n";
       }
-      my $returnref;
-      my $returndir;
       if ($filelink{$link}) {
-         $returnref=$filelink{$link};
-         $returndir=$filedir{$link};
+         $filename=$filelink{$link};
+         $filedirectory=$filedir{$link};
       } else {
          my ($fileb,$ext)=($fn=~/^(.+)\.(\w+)$/);
          $ext=lc($ext);
          $fileb=~s/\s/\_/gs;
          $fileb=~s/\W//gs;
          $filename=$fileb.'.'.$ext;
-         $filedir=$srcdir.'/files';
-         mkdir($filedir);
-         copy('dump/'.$fn,$filedir.'/'.$filename);
+         $filedirectory=$srcdir.'/files';
+         mkdir($filedirectory);
+         copy('dump/'.$fn,$filedirectory.'/'.$filename);
+         $filelink{$link}=$filename;
+         $filedir{$link}=$filedirectory;
      }
    } elsif ($ref=~/^wikipedia\:(.+)$/i) {
       $ref=~s/wikipedia\:/http\:en.wikipedia.org\//;
@@ -192,6 +193,11 @@
        unless ($idx) {
           print "WARNING: Unknown index for [$ref]\n";
           return '';
-       } 
-   }
+       }
+       my $dir=$resdir{&unformat($ref)};
+       unless ($dir) { $dir='reference'; }
+       $filedirectory='htmlwiki/'.$dir;
+       $filename=$fileres{$idx}.'.html';
+    }
+    return File::Spec->abs2rel($filedirectory.'/'.$filename, $srcdir); 
 }




More information about the LON-CAPA-cvs mailing list