Commit 2ce118d9 authored by Naoki OKAMURA's avatar Naoki OKAMURA

improved: rewritten kalaclista protocol handler

parent ed3b338b
......@@ -3,75 +3,74 @@
use strict;
use warnings;
our $basedir = $ENV{'HOME'} . '/local/dev/src/github.com/nyarla/the.kalaclista.com-v2';
sub convert {
my $url = shift;
my ( $website, $path ) = ( $url =~ m{kalaclista:([^/]+?)/([^.]+).md} );
return "src/${website}/content/${path}.md";
}
our $BASE_DIR = $ENV{'HOME'} . '/local/dev/src/github.com/nyarla/the.kalaclista.com-v2';
our $URI_RE = qr{kalaclista:([^/]+?)/([^.]+)\.md};
sub main {
my $path = convert(shift);
system(qq[ echo "${path}" >${basedir}/.edit ]);
my $protocol = shift;
my ( $website, $path ) = ( $protocol =~ $URI_RE );
my $file = join q{/}, ( $BASE_DIR, "src", $website, "content", "${path}.md" );
my $out = '';
if ( ! -e $path ) {
if ( $path =~ m{^src/notes/content/([^\.]+)\.md$} ) {
my $page = $1;
my $date = `date +%Y-%m-%dT%H:%M:%S`;
chomp($date);
if ( ! -e $file ) {
my $out = q{};
$out .= <<"__EOF__";
---
type: notes
title: "${page}"
slug: '${page}'
date: '${date}+09:00'
ads: true
fixme: false
---
if ( $website eq 'notes' ) {
my $slug = $path;
my $date = `date +%Y-%m-%dT%H:%M:%S`;
chomp($date);
__EOF__
$out .= <<~"EOF";
---
type: notes
title: "${slug}"
slug: '${slug}'
date: '${date}+09:00'
ads: true
fixme: false
---
EOF
} else {
system qq{ mkdir -p \$(dirname '${basedir}/${path}') };
my ( $website, $year, $month, $day, $hour, $minute, $second ) = ( $path =~ m{^src/([^/]+)/content/(\d{4})/(\d{2})/(\d{2})/(\d{2})(\d{2})(\d{2})\.md$} );
my ( $year, $month, $day, $hms ) = ( split qr{/}, $path );
my ( $hour, $minute, $second ) = ( $hms =~ m{^(\d{2})(\d{2})(\d{2})$} );
$out .= <<"__EOF__";
---
type: ${website}
title: ""
date: '${year}-${month}-${day}T${hour}:${minute}:${second}+09:00'
slug: '${hour}${minute}${second}'
__EOF__
$out .= <<~"EOF";
---
type: ${website}
title: ""
date: '${year}-${month}-${day}T${hour}:${minute}:${second}+09:00'
slug: '${hms}'
EOF
if ( $website eq 'posts' ) {
$out .= <<'__EOF__';
tags:
-
__EOF__
$out .= <<~'EOF';
tags:
-
EOF
}
$out .= <<'__EOF__';
ads: true
fixme: false
---
__EOF__
$out .= <<~'EOF';
ads: true
fixme: false
---
EOF
}
if ( $website ne 'notes' ) {
my $dir = `dirname ${file}`;
chomp($dir);
system(qw(mkdir -p), $dir);
}
open(my $fh, '>', "${basedir}/${path}");
open(my $fh, '>', $file);
print $fh $out;
close($fh);
}
my $code = system(qw(tmux list-sessions));
if ( $code != 0 ) {
system qq[mlterm -e zsh -c 'cd ${basedir} && tmux-up'];
system(qq< mlterm -e zsh -c 'cd "${BASE_DIR}" && tmux-up' >);
} else {
system qq[tmux new-window -c ${basedir} vim -c NERDTree ${path} ];
system(qq< tmux new-window -a -c "${BASE_DIR}" vim -c NERDTree ${file} >);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment