aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xpastebin/new.sh23
-rwxr-xr-xpastebin/website-pastebin90
-rwxr-xr-xwebsite92
-rwxr-xr-xwebsite.pl63
4 files changed, 182 insertions, 86 deletions
diff --git a/pastebin/new.sh b/pastebin/new.sh
deleted file mode 100755
index b792e33..0000000
--- a/pastebin/new.sh
+++ /dev/null
@@ -1,23 +0,0 @@
-#!/usr/bin/env bash
-set -eo pipefail
-cd "$(dirname ${BASH_SOURCE[0]})"
-
-OUTDIR="../site/pastebin"
-
-# Taken from:
-# https://stackoverflow.com/a/49035906
-slugify () {
- echo "$1" | iconv -t ascii//TRANSLIT | sed -r s/[~\^]+//g | sed -r s/[^a-zA-Z0-9]+/-/g | sed -r s/^-+\|-+$//g | tr A-Z a-z
-}
-
-if [[ -z "$1" ]]; then
- printf "Type the pastebin title: "
- read title
-else
- title="$1"
-fi
-
-slug=$(slugify "$title")
-
-export title
-cat skeleton.org | envsubst > "$OUTDIR/$slug.org"
diff --git a/pastebin/website-pastebin b/pastebin/website-pastebin
new file mode 100755
index 0000000..6dacdfe
--- /dev/null
+++ b/pastebin/website-pastebin
@@ -0,0 +1,90 @@
+#!/usr/bin/env nix-shell
+#!nix-shell -i perl -p gettext less perl --pure -I nixpkgs=https://github.com/NixOS/nixpkgs-channels/archive/nixos-18.09.tar.gz
+
+=head1 NAME
+
+website pastebin - Create new pastebins from the org-mode template.
+
+=head1 SYNOPSIS
+
+website pastebin [options]
+
+ Options:
+ --help Show the manpage.
+ --title Title of the pastebin.
+
+=head1 OPTIONS
+
+=over 4
+
+=item B<-h, --help>
+
+Prints the manual page and exits.
+
+=item B<-t, --title>
+
+The title of the pastebin. This string will be slugified and the output is used to create the pastebin file name. Special characters are simplified or discarded.
+
+=back
+
+=head1 DESCRIPTION
+
+B<website pastebin> creates pastebin org-mode text files, that are later processed to produce HTML to be deployed statically.
+
+=cut
+
+use strict;
+use warnings;
+use Getopt::Long qw(:config no_ignore_case bundling);
+use Pod::Usage qw(pod2usage);
+use Unicode::Normalize;
+use File::Basename;
+
+my $help = 0;
+my $title = '';
+GetOptions(
+ 'help|h|?' => \$help,
+ 'title|t=s' => \$title
+) or pod2usage(-verbose => 1, -exitval => 2);
+pod2usage(-verbose => 2, -exitval => 0) if $help;
+
+if (!$title) {
+ die "Missing required --title argument.";
+}
+
+# Taken from:
+# https://stackoverflow.com/a/4009519
+sub slugify {
+ my $input = shift;
+ $input = NFKD($input); # Normalize (decompose) the Unicode string
+ $input =~ tr/\000-\177//cd; # Strip non-ASCII characters (>127)
+ $input =~ s/[^\w\s-]//g; # Remove all characters that are not word characters (includes _), spaces, or hyphens
+ $input =~ s/^\s+|\s+$//g; # Trim whitespace from both ends
+ $input = lc($input);
+ $input =~ s/[-\s]+/-/g; # Replace all occurrences of spaces and hyphens with a single hyphen
+ return $input;
+}
+
+
+our $dirname = dirname(__FILE__);
+our $in = "$dirname/skeleton.org";
+our $out;
+my %ENV = (title => $title);
+# Derived from both:
+# https://unix.stackexchange.com/a/294836
+# https://stackoverflow.com/a/47664214
+sub envsubst {
+ open(IN, '<'.$in) or die $!;
+ open(OUT, '>'.$out) or die $!;
+ while(<IN>) {
+ $_ =~ s/\$([_a-zA-Z]+)/$ENV{$1}/g;
+ print OUT $_;
+ }
+ close(IN);
+ close(OUT);
+}
+
+my $slug = slugify($title);
+$out = "$dirname/../site/pastebin/$slug.org";
+
+envsubst();
diff --git a/website b/website
new file mode 100755
index 0000000..89d47b7
--- /dev/null
+++ b/website
@@ -0,0 +1,92 @@
+#!/usr/bin/env nix-shell
+#!nix-shell -i perl -p perl less nix --pure -I nixpkgs=https://github.com/NixOS/nixpkgs-channels/archive/nixos-18.09.tar.gz
+
+=head1 NAME
+
+website - Website repository CLI manager.
+
+=head1 SYNOPSIS
+
+website <subcommand> [options]
+
+ Subcommands:
+ pastebin Create a new pastebin from the org-mode template.
+ slides Create a new HTML slideshow from the existing templates.
+ test Run internal CLI tests.
+
+ Options:
+ --help Show the manpage.
+
+=head1 OPTIONS
+
+=over 4
+
+=item B<-h, --help>
+
+Prints the manual page and exits.
+
+=back
+
+=head1 DESCRIPTION
+
+B<website> is the top-level coordinator of subtasks inside the website repo.
+
+=cut
+
+use strict;
+use warnings;
+use Getopt::Long qw(:config no_ignore_case bundling pass_through);
+use Pod::Usage qw(pod2usage);
+
+my $help = 0;
+my $title = '';
+sub getopts {
+ GetOptions(
+ 'help|h|?' => \$help
+ );
+}
+
+sub test {
+ die "FIXME";
+}
+
+sub dispatch {
+ my $action = shift;
+ my @args = @_;
+ my @sub_args = grep { $_ ne $action } @args;
+ if (!defined $action && $help) {
+ pod2usage(
+ -verbose => 2,
+ -exitval => 0
+ );
+ } elsif (!defined $action) {
+ print "Missing subcomand.\n";
+ pod2usage(
+ -verbose => 1,
+ -exitval => 2
+ );
+ } elsif ($action eq 'pastebin') {
+ print `./pastebin/website-pastebin @sub_args`;
+ exit $? >> 8;
+ } elsif ($action eq 'slides') {
+ print `./pastebin/website-slides @sub_args`;
+ exit $? >> 8;
+ } elsif ($action eq 'test') {
+ test();
+ } else {
+ print "Unknown subcommand: $action.\n";
+ pod2usage(
+ -verbose => 1,
+ -exitval => 2
+ );
+ }
+}
+
+sub main {
+ my @orig_args=@ARGV;
+ getopts();
+ my $action=shift @ARGV;
+ dispatch($action, @orig_args);
+}
+
+main();
diff --git a/website.pl b/website.pl
deleted file mode 100755
index cb81ff3..0000000
--- a/website.pl
+++ /dev/null
@@ -1,63 +0,0 @@
-#!/usr/bin/env nix-shell
-#!nix-shell -i perl -p perl less --pure
-
-=head1 NAME
-
-cli.pl - Using GetOpt::Long and Pod::Usage
-
-=head1 SYNOPSIS
-
-sample [options] [file ...]
-
- Options:
- --help brief help message
- --man full documentation
-
-=head1 OPTIONS
-
-=over 4
-
-=item B<-h, --help>
-
-Print a brief help message and exits.
-
-=item B<--man>
-
-Prints the manual page and exits.
-
-=back
-
-=head1 DESCRIPTION
-
-B<This program> will read the given input file(s) and do something
-useful with the contents thereof.
-
-=cut
-
-use strict;
-use warnings;
-use Getopt::Long qw(:config no_ignore_case bundling auto_help auto_version);
-use Pod::Usage qw(pod2usage);
-
-my $help = 0;
-my $title = '';
-GetOptions(
- "t|title=s" => \$title,
- 'help|h|?' => \$help
-) or pod2usage(-verbose => 1);
-pod2usage(
- -verbose => 2,
- -exitval => 0
-) if $help || (defined $ARGV[0] and $ARGV[0] eq "help");
-
-## If no arguments were given, then allow STDIN to be used only
-## if it's not connected to a terminal (otherwise print usage)
-pod2usage("$0: No files given.") if ((@ARGV == 0) && (-t STDIN));
-
-print `fd sh`;
-print `find . -type f -name '*sh*'`;
-
-
-# FIXME: add tests (inline + bats)
-
-