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

www www at source.lon-capa.org
Tue Dec 13 17:29:28 EST 2011


www		Tue Dec 13 22:29:28 2011 EDT

  Modified files:              
    /modules/gerd/Wiki	convert.pl 
  Log:
  Introduce second level directory structure
  
  
Index: modules/gerd/Wiki/convert.pl
diff -u modules/gerd/Wiki/convert.pl:1.2 modules/gerd/Wiki/convert.pl:1.3
--- modules/gerd/Wiki/convert.pl:1.2	Tue Dec 13 18:09:52 2011
+++ modules/gerd/Wiki/convert.pl	Tue Dec 13 22:29:27 2011
@@ -1,11 +1,39 @@
 use strict;
-# Read the article index file
 my %residx=();
+my %resdir=();
 my %idxres=();
 my %resfile=();
 my %fileres=();
 my %titleres=();
 my %duplicatecnt=();
+
+# Read the copy/paste of the treemenu source code
+
+open(IN,'dump/treemenu.dat');
+my $currentdir='';
+while (my $line=<IN>) {
+   chomp($line);
+   my ($res)=($line=~/title=\\\"([^\\]+)\\/);
+   if ($res=~/\s[\-\–]+\s/) {
+      my ($dir,$remainder)=split(/\s+[\-\–]+\s+/,$res);
+      $dir=~s/\W//g;
+      my $thisdir;
+      if ($dir=~/^Unit/) {
+         $currentdir=$dir;
+         $thisdir=$dir;
+      } elsif ($dir!~/^Module/) {
+         $currentdir='';
+         $thisdir=$currentdir;
+      } else {
+         $thisdir=$currentdir.'/'.$dir;
+      }
+      $resdir{$res}=$thisdir;
+   }
+}
+close(IN);
+
+# Reading Index File
+
 open(IN,'dump/articles.dat');
 while (my $line=<IN>) {
    chomp($line);
@@ -16,21 +44,16 @@
    my $title;
    if ($res=~/\s[\-\–]+\s/) {
       my ($dir,$remainder)=split(/\s+[\-\–]+\s+/,$res);
-      $dir=~s/\W//g;
+      $file=$remainder;
       $title=$remainder;
-      $remainder=~s/\,/\_/g;
-      $remainder=~s/\s/\_/g;
-      $remainder=~s/\W//g;
-      $remainder=substr($remainder,0,20);
-      $file=$dir.'/'.$remainder;
    } else {
       $file=$res;
       $title=$res;
-      $file=~s/\,/\_/g;
-      $file=~s/\s/\_/g;
-      $file=~s/\W//g;
-      $file=substr($file,0,20);
    }
+   $file=~s/\,/\_/g;
+   $file=~s/\s/\_/g;
+   $file=~s/\W//g;
+   $file=substr($file,0,20);
    $file=~s/\_+$//;
    if ($resfile{$file}) {
       $duplicatecnt{$file}++;
@@ -43,6 +66,7 @@
 }
 close(IN);
 # So far:
+# resdir: Wiki-reference -> directory this should go into
 # residx: Wiki-reference -> index
 # idxres: index -> Wiki-reference
 # resfile: filename -> index
@@ -71,3 +95,22 @@
    }
 }
 # We are now only left with real files that need translation
+#
+
+mkdir('htmlwiki');
+foreach my $idx (keys(%idxres)) {
+   my $targetfile=$fileres{$idx}.'.html';
+   print $idxres{$idx}." ---> ".$resdir{$idxres{$idx}}."\n"; 
+   my $targetdir='htmlwiki';
+   if ($targetfile=~/\//) {
+      my ($dir,$res)=split(/\//,$targetfile);
+      $targetdir.='/'.$dir;
+#      mkdir($targetdir);
+   }
+#   open(IN,'dump/'.$idx.'.wikitext');
+#   while (my $line=<IN>) {
+#      chomp($line);
+#   }
+#   close(IN);
+}
+




More information about the LON-CAPA-cvs mailing list