Skip to content

Commit

Permalink
Prep for release - 0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
davorg committed Jul 1, 2024
1 parent b416928 commit b543811
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 4 deletions.
14 changes: 13 additions & 1 deletion Changes.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
# Change Log

## [0.1.2] - 2024-06-16
## [0.1.4] - 2024-07-01

### Added

- Support for redirection pages

## [0.1.3] - 2024-06-14

### Fixed

- Bug in App::Aphra::File::uri

## [0.1.2] - 2024-06-14

### Added

Expand Down
40 changes: 39 additions & 1 deletion bin/aphra
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,44 @@ And you could access that text inside your templates with markup like this:

<h1><% site.name %></h1>

=head2 Special variables in site.yml

There are a few special variables that you can define in your `site.yml` file
which will be used by the program.

=over 4

=item uri, protocol, host, port

These are used to construct the base URL for the site. If you don't define
these, then the program will try to guess them. It will use the value of the
`uri` variable if it is defined. If not, it will use the values of the
`protocol`, `host` and `port` variables. If any of these aren't defined, it
will use the values "https", the result of calling `hostname` and no port
(which is, effectively, port 80) respectively.

=item redirects

This is a list of URLs that should be redirected to other URLs. Each entry in
the list should be a hash containing the keys `from` and `to`. For example:

redirects:
- from: /old/page
to: /new/page

The value of "from" should be the path part of the URL that you want to
redirect and the value of "to" can be either a full URL or a path part of a
URL. If it is a path part, then the base URL of the site will be prepended to
it.

Aphra implements these redirects by creating stub HTML files in the output
directory which contain a meta refresh tag that redirects the browser to the
new URL. Redirects are created before other files are processed, so any files
that have the same URL as a redirect will overwrite the redirect stub HTML
file.

=back

=head1 FRONT MATTER IN INDIVIDUAL PAGES

At the start of the template for a page, you can add a data section which
Expand Down Expand Up @@ -245,7 +283,7 @@ Dave Cross <[email protected]>

=head1 COPYRIGHT AND LICENCE

Copyright (c) 2017-2023, Magnum Solutions Ltd. All Rights Reserved.
Copyright (c) 2017-2024, Magnum Solutions Ltd. All Rights Reserved.

This library is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
Expand Down
42 changes: 40 additions & 2 deletions lib/App/Aphra.pm
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ use URI;

use App::Aphra::File;

our $VERSION = '0.1.2';
our $VERSION = '0.2.0';

has commands => (
isa => 'HashRef',
Expand Down Expand Up @@ -210,6 +210,10 @@ sub build {
-e $src or die "Cannot find $src\n";
-d $src or die "$src is not a directory\n";

if ($self->site_vars->{redirects}) {
$self->make_redirects;
}

find({ wanted => $self->_make_do_this, no_chdir => 1 },
$self->config->{source});
}
Expand All @@ -228,6 +232,40 @@ sub _make_do_this {
};
}

sub make_redirects {
my $self = shift;
my $redirects = $self->site_vars->{redirects};

return if !$redirects;
return if !@$redirects;

my $target = $self->config->{target};

for (@$redirects) {
my $from = $_->{from};
$from .= 'index.html' if $from =~ m|/$|;

my $to = $_->{to};

my $outdir = dirname "$target$from";
mkdir $outdir;

open my $out_fh, '>', "$target$from"
or die "Cannot open '$target$from' for writing: $!\n";

print $out_fh <<EOF;
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="refresh" content="0; url=$to">
</head>
</html>
EOF

close $out_fh;
}
}

sub serve {
my $self = shift;

Expand Down Expand Up @@ -266,7 +304,7 @@ Dave Cross <[email protected]>
=head1 COPYRIGHT AND LICENCE
Copyright (c) 2017-2023, Magnum Solutions Ltd. All Rights Reserved.
Copyright (c) 2017-2024, Magnum Solutions Ltd. All Rights Reserved.
This library is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
Expand Down

0 comments on commit b543811

Please sign in to comment.