Compare commits
2 Commits
022b4e54be
...
80ede8b182
Author | SHA1 | Date |
---|---|---|
Hutzdog | 80ede8b182 | |
Hutzdog | 8dae20da39 |
|
@ -144,7 +144,7 @@ cap2site \- Convert a Gemini capsule to a HTML site
|
|||
.IX Header "SYNOPSIS"
|
||||
cap2site [flags] < \s-1INPUT\s0.gmi > \s-1OUTPUT\s0.html
|
||||
.PP
|
||||
.Vb 7
|
||||
.Vb 8
|
||||
\& Options:
|
||||
\& \-help brief help message
|
||||
\& \-hh full help message
|
||||
|
@ -152,6 +152,7 @@ cap2site [flags] < \s-1INPUT\s0.gmi > \s-1OUTPUT\s0.html
|
|||
\& \-(no)\-inline\-video include video in site
|
||||
\& \-(no)\-inline\-image include images in site
|
||||
\& \-standalone include data for headers
|
||||
\& \-replace\-domain replace a Gemini domain with another (possibly non\-gemini) domain
|
||||
.Ve
|
||||
.SH "OPTIONS"
|
||||
.IX Header "OPTIONS"
|
||||
|
@ -164,3 +165,6 @@ Include the respective asset types inline
|
|||
.IP "\fB\-(no)\-standalone\fR" 4
|
||||
.IX Item "-(no)-standalone"
|
||||
Include header and body tags
|
||||
.IP "\fB\-replace\-domain old=new\fR" 4
|
||||
.IX Item "-replace-domain old=new"
|
||||
Replace all Gemini domains at path old with ones based on new
|
||||
|
|
48
cap2site.pl
48
cap2site.pl
|
@ -14,7 +14,7 @@ struct('Config', => {
|
|||
web_schemes => '@',
|
||||
standalone => '$',
|
||||
head => '$',
|
||||
local_domains => '$',
|
||||
local_domains => '%',
|
||||
});
|
||||
|
||||
our $DEFAULT = Config->new(
|
||||
|
@ -30,7 +30,7 @@ our $DEFAULT = Config->new(
|
|||
},
|
||||
web_schemes => ["http", "https", "mailto", "gemini"],
|
||||
standalone => 0,
|
||||
local_domains => [],
|
||||
replace_domains => {},
|
||||
head => <<~'EOF',
|
||||
<meta charset="utf-8"/>
|
||||
<link rel="stylesheet" href="style.css"></link>
|
||||
|
@ -49,12 +49,19 @@ sub isA($$$) {
|
|||
return grep $1, $self->extensions->{type};
|
||||
}
|
||||
|
||||
sub isLocal($$$) {
|
||||
sub handleRedirects($$$) {
|
||||
my ($self,$url,$content) = @_;
|
||||
$url =~ /gemini:\/\/([^\/]+).*/ or return 0;
|
||||
$url =~ /gemini:\/\/([^\/]+)(.+)/ or return $url;
|
||||
my $old_domain = $1;
|
||||
|
||||
return 0 if (index($content, "(gemini)") == 0);
|
||||
return grep $1, $self->{local_domains};
|
||||
# TODO: find more elegant mechanism for non-redirecting links links
|
||||
return $url if (index($content, "(gemini)") == 0);
|
||||
return $url unless exists($self->{replace_domains}->{$old_domain});
|
||||
|
||||
my $res = $2;
|
||||
$res =~ s/\.gmi$/\.html/;
|
||||
|
||||
return $self->{replace_domains}->{$old_domain} . $res;
|
||||
}
|
||||
|
||||
package State;
|
||||
|
@ -82,11 +89,11 @@ my sub escape($) {
|
|||
my $newstr = '';
|
||||
|
||||
foreach my $byte (split '', $str) {
|
||||
if ($byte eq "8") { $newstr .= "&"; continue; }
|
||||
if ($byte eq "<") { $newstr .= "<"; continue; }
|
||||
if ($byte eq ">") { $newstr .= ">"; continue; }
|
||||
if ($byte eq "\"") { $newstr .= """; continue; }
|
||||
if ($byte eq "'") { $newstr .= "'"; continue; }
|
||||
if ($byte eq "8") { $newstr .= "&"; next; }
|
||||
if ($byte eq "<") { $newstr .= "<"; next; }
|
||||
if ($byte eq ">") { $newstr .= ">"; next; }
|
||||
if ($byte eq "\"") { $newstr .= """; next; }
|
||||
if ($byte eq "'") { $newstr .= "'"; next; }
|
||||
$newstr .= $byte;
|
||||
}
|
||||
|
||||
|
@ -173,16 +180,10 @@ sub parse($$$) {
|
|||
}
|
||||
|
||||
elsif ($config->isUrl($uri)) {
|
||||
if ($config->isLocal($uri, $content)) {
|
||||
# TODO: local http
|
||||
$uri =~ s/gemini:/https:/;
|
||||
$uri =~ s/\.gmi$/\.html/;
|
||||
}
|
||||
|
||||
print '<div>', "\n";
|
||||
print '<div>', "\n";
|
||||
print '<span class="link-delim">=></span> ';
|
||||
print '<a href="', escape($uri), '">', escape($content), '</a>', "\n";
|
||||
print '</div>', "\n";
|
||||
print '<a href="', escape($config->handleRedirects($uri, $content)), '">', escape($content), '</a>', "\n";
|
||||
print '</div>', "\n";
|
||||
}
|
||||
|
||||
else {
|
||||
|
@ -223,7 +224,7 @@ GetOptions (
|
|||
'inline-video!' => \$config->inline->{video},
|
||||
'inline-image!' => \$config->inline->{image},
|
||||
'standalone!' => \$config->{standalone},
|
||||
'local-domain=s' => \$config->{local_domains},
|
||||
'replace-domain=s%' => \$config->{replace_domains},
|
||||
) or pod2usage(-exitval => 1, -verbose => 0);
|
||||
|
||||
pod2usage(-verbose => $help) if $help;
|
||||
|
@ -248,6 +249,7 @@ cap2site [flags] < INPUT.gmi > OUTPUT.html
|
|||
-(no)-inline-video include video in site
|
||||
-(no)-inline-image include images in site
|
||||
-standalone include data for headers
|
||||
-replace-domain replace a Gemini domain with another (possibly non-gemini) domain
|
||||
|
||||
=head1 OPTIONS
|
||||
|
||||
|
@ -265,6 +267,10 @@ Include the respective asset types inline
|
|||
|
||||
Include header and body tags
|
||||
|
||||
=item B<-replace-domain old=new>
|
||||
|
||||
Replace all Gemini domains at path old with ones based on new
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
|
Loading…
Reference in New Issue