tips:autolink
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
tips:autolink [2010-03-23 14:52] – 192.54.144.229 | tips:autolink [2015-01-29 16:46] (current) – [Sample of link page] 84.204.72.82 | ||
---|---|---|---|
Line 3: | Line 3: | ||
author : Vincent Fleury\\ | author : Vincent Fleury\\ | ||
mail : fleury.vincent[at]gmail.com\\ | mail : fleury.vincent[at]gmail.com\\ | ||
- | status : **experimental script** (used into my compagny) | + | status : **experimental script** (used at my company) |
+ | |||
+ | ===== Usage ===== | ||
+ | |||
+ | this script can be used to: | ||
+ | |||
+ | * automatically add links to a word | ||
+ | * change one link to another | ||
===== Script ===== | ===== Script ===== | ||
- | | + | <code perl autolink.pl> |
- | + | #!/ | |
- | sub substi | + | |
- | { | + | sub substi |
- | | + | { |
- | + | local $file = $_[0]; | |
- | | + | |
- | | + | local $str = $_[1]; |
- | + | local $ns = $_[2]; | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | { |
- | | + | |
- | print FD_TEMP; | + | if(/==+/ || / *[^*]/) |
- | | + | |
- | | + | print FD_TEMP; |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | $in_link = 0; |
- | | + | $ignore = 0; |
+ | | ||
+ | | ||
+ | | ||
{ | { | ||
| | ||
- | { | + | { |
| | ||
if ($f eq " | if ($f eq " | ||
} | } | ||
elsif (($f eq " | elsif (($f eq " | ||
- | { | + | { |
- | $ignore = 0; | + | |
if ($f eq " | if ($f eq " | ||
} | } | ||
+ | |||
+ | |||
if ($ignore == 1) | if ($ignore == 1) | ||
- | { | + | { |
| | ||
- | { | + | { |
$f =~ / | $f =~ / | ||
$l = $1; | $l = $1; | ||
$w = $2; | $w = $2; | ||
if($w =~ /$str/i) | if($w =~ /$str/i) | ||
- | { | + | { |
- | print FD_TEMP $ns." | + | print FD_TEMP $ns." |
} | } | ||
else | else | ||
- | { | + | { |
print FD_TEMP $f; | print FD_TEMP $f; | ||
} | } | ||
- | } | + | } |
else | else | ||
- | { | + | { |
print FD_TEMP $f; | print FD_TEMP $f; | ||
} | } | ||
- | | + | } |
else | else | ||
- | { | + | { |
- | if($f =~ /$str/i) | + | if($f =~ /($str)/i) |
- | | + | { |
- | $f =~ s/([., : | + | $f =~ s/([\(\"\)., :\*{2}\_{2}])($str)([\)\(., :\"\*{2}\_{2}])/ |
- | $f =~ s/ | + | $f =~ s/^($str)([\)\(., : |
- | $f =~ s/ | + | $f =~ s/([\(\)., : |
- | | + | |
+ | #print $f."< | ||
+ | } | ||
print FD_TEMP $f; | print FD_TEMP $f; | ||
- | | + | } |
- | + | ||
- | | + | |
} | } | ||
- | | + | |
- | } | + | } |
close(FD_TEMP); | close(FD_TEMP); | ||
- | close(FD); | + | close(FD); |
unlink ($file); | unlink ($file); | ||
- | rename (' | + | rename (' |
- | chmod (0770, | + | chmod (0770,$file); |
+ | |||
+ | } | ||
+ | |||
+ | sub apply_to | ||
+ | { | ||
+ | local $ns = $_[0]; | ||
+ | local $str = $_[1]; | ||
+ | local $link = $_[2]; | ||
+ | |||
+ | local $fp = $ns . " | ||
+ | if(-f $fp) | ||
+ | { | ||
+ | substi($fp, | ||
} | } | ||
- | | + | |
- | | + | |
+ | my @files = readdir(DIR); | ||
+ | closedir(DIR); | ||
+ | |||
+ | foreach my $file (@files) | ||
{ | { | ||
- | local $ns = $_[0]; | ||
- | local $str = $_[1]; | ||
- | local $link = $_[2]; | ||
- | local $fp = $ns . " | ||
- | | ||
- | if(-f $fp) | ||
- | { | ||
- | substi($fp, | ||
- | return; | ||
- | } | ||
- | | ||
- | opendir(DIR, | ||
- | my @files = readdir(DIR); | ||
- | closedir(DIR); | ||
- | | ||
- | foreach my $file (@files) | ||
- | { | ||
next if $file =~ /^\.\.?$/; | next if $file =~ /^\.\.?$/; | ||
+ | next if $file =~ / | ||
$file = $ns."/" | $file = $ns."/" | ||
+ | |||
+ | |||
if (-f $file) | if (-f $file) | ||
- | { | + | |
+ | #print $file." | ||
substi($file, | substi($file, | ||
} | } | ||
- | elsif (-d $file) | + | elsif (-d $file) |
- | { | + | { |
& | & | ||
} | } | ||
- | } | ||
} | } | ||
- | | + | } |
- | sub autolink | + | |
+ | |||
+ | sub autolink | ||
+ | { | ||
+ | local $link_file = $_[0]; | ||
+ | local $data_dir | ||
+ | |||
+ | |||
+ | open(FD_L, | ||
+ | while(< | ||
{ | { | ||
- | | + | |
- | | + | |
- | + | ||
- | open(FD_LINK, | + | |
- | while(< | + | |
{ | { | ||
- | @sub = split(/ | + | |
- | if($sub[1] ne "" | + | if (substr($data_dir, |
- | { | + | {$data_dir .= "/"; |
- | | + | & |
- | if (substr($data_dir, | + | |
- | {$data_dir .= "/"; | + | |
- | & | + | |
- | } | + | |
} | } | ||
- | close(FD_LINK); | ||
- | } | ||
- | | ||
- | | ||
- | | ||
- | if($#ARGV != 1) | ||
- | { | ||
- | print " | ||
- | | ||
- | where link_file | ||
- | is a txt formated like this | ||
- | |< | ||
- | ... | ||
- | sample | ||
- | |eng|toto|eng: | ||
- | | ||
- | where data_directory | ||
- | id the main dokuwiki page directory to apply rules | ||
- | | ||
- | "; | ||
- | } | ||
- | else | ||
- | { | ||
- | autolink($ARGV[0], | ||
} | } | ||
+ | close(FD_L); | ||
+ | |||
+ | |||
+ | |||
+ | } | ||
+ | |||
+ | |||
+ | |||
+ | if($#ARGV != 1) | ||
+ | { | ||
+ | print " | ||
+ | |||
+ | where link_file | ||
+ | is a txt formated like this | ||
+ | |< | ||
+ | ... | ||
+ | sample | ||
+ | |eng|toto|eng: | ||
+ | |||
+ | where data_directory | ||
+ | id the main dokuwiki page directory to apply rules | ||
+ | |||
+ | "; | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | autolink($ARGV[0], | ||
+ | } | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | </ | ||
- | ===== Deployement | + | ===== Deployment |
- copy script into your web directory | - copy script into your web directory | ||
Line 176: | Line 206: | ||
===== The link page ===== | ===== The link page ===== | ||
- | * **Only line started with ' | + | * **Only line started with ' |
+ | * **no space into table line**, except if you want to match spaces | ||
+ | * it's **case insensitive matching**, " | ||
+ | * **autolink.txt pages are ignored** | ||
+ | * for matchin whole wiki directory ':' | ||
+ | |||
__The analysed line format is :__ | __The analysed line format is :__ | ||
|< | |< | ||
- | * this script : **remplace existings links** to new one | ||
- | * ignore : title, image | ||
==== Sample of link page ==== | ==== Sample of link page ==== | ||
Line 211: | Line 244: | ||
* **apple** to **fruits: | * **apple** to **fruits: | ||
* **flute** to **instruments: | * **flute** to **instruments: | ||
- | * ... | + | * ... |
+ | |||
tips/autolink.1269352379.txt.gz · Last modified: 2010-03-23 14:52 by 192.54.144.229