From 7f89612023c9dfd03d85334ee4f301aee5a6d41b Mon Sep 17 00:00:00 2001 From: Rawley Fowler Date: Thu, 6 Jul 2023 22:33:00 -0600 Subject: [PATCH] perl :) --- .gitignore | 1 + cpanfile | 3 + index.html => public/index.html | 18 +++-- site.pl | 135 ++++++++++++++++++++++++++++++++ 4 files changed, 152 insertions(+), 5 deletions(-) create mode 100644 cpanfile rename index.html => public/index.html (85%) create mode 100644 site.pl diff --git a/.gitignore b/.gitignore index f5169bb..dce9314 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ posts/*.post \#* .DS_Store bookshelf.txt +site.db* diff --git a/cpanfile b/cpanfile new file mode 100644 index 0000000..94c3a12 --- /dev/null +++ b/cpanfile @@ -0,0 +1,3 @@ +requires 'Text::Markdown'; +requires 'Mojolicious'; +requires 'Mojo::SQLite'; \ No newline at end of file diff --git a/index.html b/public/index.html similarity index 85% rename from index.html rename to public/index.html index b29f64d..f996f35 100644 --- a/index.html +++ b/public/index.html @@ -21,13 +21,21 @@ } - -

Rawley Fowler

+ + +

Rawley Fowler

Hi, I'm Rawley, a Software Engineer from rural Saskatchewan, Canada. I specialize in Perl, and Go development, tackling all areas - of the software life cycle. I also like to dabble in Pure Functional languages. Professionally I develop microservices using Java, SpringBoot, and PostgreSQL. I'm passionate about software performance, - functional programming, and type-systems. If you have a position that you think I'd like (especially focusing on Perl, or Go), please feel free to email me. + of the software life cycle. I also like to dabble in Pure Functional languages. At work I develop microservices using Java, SpringBoot, and PostgreSQL. I'm passionate about software performance, + functional programming, and making programs safer. If you have a position that you think I'd like (especially focusing on Perl, or Go), please feel free to email me. Outside of my professional work, I spend a lot of time contributing to open-source projects. You may or may not have used some of them :)

Skills

@@ -106,7 +114,7 @@
University of Regina: Bachelor of Science in Mathematics. Sept 2020 - Jun 2021

- Studied various mathematical concepts, ultimately did not finish due to extraneous circumstances. Hoping to have the time one day to complete this degree. + Studied various mathematical concepts (mostly Linear Algebra, and Calculus), ultimately did not finish due to extraneous circumstances. Hoping to have the time one day to complete this degree.

diff --git a/site.pl b/site.pl new file mode 100644 index 0000000..bf03e16 --- /dev/null +++ b/site.pl @@ -0,0 +1,135 @@ +#!/usr/bin/env perl +use 5.016; + +use Mojolicious::Lite -signatures; +use Mojo::SQLite; +use Data::Dumper; + +my $sql = Mojo::SQLite->new('sqlite:site.db'); +helper db => sub { state $db = $sql->db }; + +$sql->migrations->name('posts_table')->from_string(<migrate; +-- 1 up +CREATE TABLE IF NOT EXISTS posts ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + title TEXT, + content TEXT, + slug TEXT, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP +); +-- 1 down +DROP TABLE posts; +EOF + +$sql->migrations->name('posts_index')->from_string(<migrate; +-- 2 up +CREATE INDEX IF NOT EXISTS slug_idx ON posts (slug); +-- 2 down +DROP INDEX slug_idx; +EOF + +get '/' => sub { + my $c = shift; + $c->reply->static('index.html'); +}; + +get '/blog' => sub { + my $c = shift; + $c->stash( posts => [ $c->db->select('posts')->hashes->each ] ); + $c->render; +}; + +get '/blog/:post' => sub { + my $c = shift; + my $post = $c->db->select( + 'posts', + [ 'title', 'content', 'slug' ], + { slug => $c->param('post') } + )->hash; + + print( Dumper $post ); + + return $c->render( template => 'not_found' ) unless $post; + + $c->stash( post => $post ); + $c->render( template => 'post' ); +}; + +app->start; + +__DATA__ +@@ not_found.html.ep + + + %= include '_header', title => '404 Not Found' + + %= include '_nav' +

404 - Not Found

+ + + +@@ post.html.ep + % use Text::Markdown qw(markdown); + + + %= include '_header', title => $post->{title} + + %= include '_nav' +

<%= $post->{title} %>

+
+ <%== markdown($post->{content}) %> +
+ + + +@@ blog.html.ep + + + %= include '_header', title => 'Blog' + + %= include '_nav' +

Blog

+

+ This is my blog; it represents my opinions, not that of my employer(s) past, present or future. + My blog is made up of Functional Programming, Perl & Raku, Rants, Politics, and whatever else I dream up. + If you are prone to becoming upset about things, this might not be the best place for you. +

+

+ All content is licensed under the Creative-Commons Attribution-ShareALike 3.0 license unless specified otherwise. +

+
+

Title

+

Publish Date

+
+ % for (@$posts) { +
+ <%= $_->{title} %> +
<%= $_->{created_at} %>
+
+ % } + + + +@@ _header.html.ep + + <%= $title %> + + + + + + + +@@ _nav.html.ep +