Switched to Template::Mustache
This commit is contained in:
parent
2f440817c4
commit
0506335a52
|
@ -2,7 +2,7 @@
|
||||||
"name": "Hyperlink-Redirect",
|
"name": "Hyperlink-Redirect",
|
||||||
"depends": [
|
"depends": [
|
||||||
"Humming-Bird",
|
"Humming-Bird",
|
||||||
"Template6",
|
"Template::Mustache",
|
||||||
"Base64",
|
"Base64",
|
||||||
"Libarchive::Filter"
|
"Libarchive::Filter"
|
||||||
],
|
],
|
||||||
|
|
|
@ -42,8 +42,6 @@ A "useful" tool for turning hyperlinks into redirects in the name of shortening
|
||||||
|
|
||||||
## TODO
|
## TODO
|
||||||
|
|
||||||
1. Switch templates to
|
|
||||||
[Template::Mustache](https://github.com/softmoth/raku-Template-Mustache)
|
|
||||||
1. Make button to do a [meta element redirect]
|
1. Make button to do a [meta element redirect]
|
||||||
(https://www.w3docs.com/snippets/html/how-to-redirect-a-web-page-in-html.html)
|
(https://www.w3docs.com/snippets/html/how-to-redirect-a-web-page-in-html.html)
|
||||||
1. Why does Libarchive choke on strings like
|
1. Why does Libarchive choke on strings like
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use Humming-Bird::Core;
|
use Humming-Bird::Core;
|
||||||
use Humming-Bird::Middleware;
|
use Humming-Bird::Middleware;
|
||||||
use Humming-Bird::Advice;
|
use Humming-Bird::Advice;
|
||||||
use Template6;
|
use Template::Mustache;
|
||||||
use Base64;
|
use Base64;
|
||||||
use Libarchive::Filter :gzip;
|
use Libarchive::Filter :gzip;
|
||||||
|
|
||||||
|
@ -9,8 +9,7 @@ use Libarchive::Filter :gzip;
|
||||||
# what not but keeping it simple for now...
|
# what not but keeping it simple for now...
|
||||||
|
|
||||||
# Set things up (config stuff would go here?)
|
# Set things up (config stuff would go here?)
|
||||||
my $templates = Template6.new;
|
my $template = Template::Mustache.new: :from<../templates>;
|
||||||
$templates.add-path: 'templates';
|
|
||||||
|
|
||||||
# Logging
|
# Logging
|
||||||
middleware &middleware-logger;
|
middleware &middleware-logger;
|
||||||
|
@ -20,7 +19,9 @@ advice &advice-logger;
|
||||||
my $router = Router.new(root => '/');
|
my $router = Router.new(root => '/');
|
||||||
|
|
||||||
$router.get(-> $request, $response {
|
$router.get(-> $request, $response {
|
||||||
$response.html($templates.process: 'index');
|
my Str %stash = title => 'Create new hyperlink';
|
||||||
|
|
||||||
|
$response.html($template.render: 'index', %stash);
|
||||||
});
|
});
|
||||||
|
|
||||||
$router.post(-> $request, $response {
|
$router.post(-> $request, $response {
|
||||||
|
@ -29,8 +30,11 @@ $router.post(-> $request, $response {
|
||||||
my Str $url-host = $request.headers.{'Host'};
|
my Str $url-host = $request.headers.{'Host'};
|
||||||
my Str $base-url = $url-scheme ~ '://' ~ $url-host ~ '/';
|
my Str $base-url = $url-scheme ~ '://' ~ $url-host ~ '/';
|
||||||
my Str $hyperlink = $base-url ~ encode-base64(gzip($return-url), :str);
|
my Str $hyperlink = $base-url ~ encode-base64(gzip($return-url), :str);
|
||||||
|
my Str %stash =
|
||||||
|
title => 'New hyperlink created',
|
||||||
|
hyperlink => $hyperlink;
|
||||||
|
|
||||||
$response.html($templates.process: 'index', :$hyperlink);
|
$response.html($template.render: 'index', %stash);
|
||||||
});
|
});
|
||||||
|
|
||||||
# Try a wildcard to catch 'all' path
|
# Try a wildcard to catch 'all' path
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<title>[% title %]</title>
|
<title>{{title}}</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>[% title %]</h1>
|
<h1>{{title}}</h1>
|
|
@ -1,12 +1,11 @@
|
||||||
[% INCLUDE 'header'
|
{{> header}}
|
||||||
title = 'Create new hyperlink' %]
|
{{#hyperlink}}
|
||||||
[% IF hyperlink %]
|
<p>Your hyperlink is: <a href="{{hyperlink}}">{{hyperlink}}</a></p>
|
||||||
<p>Your hyperlink is: <a href="[% hyperlink %]">[% hyperlink %]</a></p>
|
{{/hyperlink}}
|
||||||
[% END %]
|
|
||||||
<form method="post">
|
<form method="post">
|
||||||
<label for="hyperlink">Hyperlink</label>
|
<label for="hyperlink">Hyperlink</label>
|
||||||
<input id="hyperlink" name="hyperlink" type="text" minlength="4"
|
<input id="hyperlink" name="hyperlink" type="text" minlength="4"
|
||||||
maxlength="2097152" required>
|
maxlength="2097152" required>
|
||||||
<button type="submit">Process</button>
|
<button type="submit">Process</button>
|
||||||
</form>
|
</form>
|
||||||
[% INCLUDE 'footer' %]
|
{{> footer}}
|
Loading…
Reference in a new issue