App-LinkSite

 view release on metacpan or  search on metacpan

lib/App/LinkSite.pm  view on Meta::CPAN

=head1 NAME

App::LinkSite - Create a website listing all of your links

=head1 SYNOPIS

(You probably want to just look at the L<linksite> application.)

=head1 DESCRIPTION

The main driver class for App::LinkSite.

=cut

use Feature::Compat::Class;

class App::LinkSite {
  our $VERSION = '0.1.3';
  use strict;
  use warnings;
  use feature qw[say signatures];
  no if $] >= 5.038, 'warnings', qw[experimental::signatures experimental::class];

  use Template;
  use JSON;
  use Path::Tiny;
  use File::Find;
  use File::Basename;
  use FindBin '$Bin';
  use File::ShareDir 'dist_dir';

  use App::LinkSite::Site;
  use App::LinkSite::Link;
  use App::LinkSite::Social;
  use App::LinkSite::Section;

  field $file :reader :param = 'links.json';
  # Where to look for the templates.
  # If we've been installed from CPAN, then File::Share::dist_name
  # gives us the correct directory. Otherwise, just look in the local
  # src directory. Note that dist_name() dies if the directory is not
  # found - hence the use of eval.
  field $src :reader :param = eval { dist_dir("App-LinkSite") } || "$Bin/../src";
  field $out :reader :param = 'docs';
  field $ga4 :reader :param = undef;
  field $site :reader :param = undef;

  field $tt;

  ADJUST {
    my $json = path($file)->slurp;
    my $data = JSON->new->decode($json);

    $ga4 = $data->{ga4} // '';

    $tt = Template->new({
      # Templates in the CPAN distro directory
      INCLUDE_PATH => $src,
      # Output in the data directory
      OUTPUT_PATH  => $out,
      VARIABLES    => {
        ga4        => $ga4,
        version    => $VERSION,
      }
    });

    my $socials = [ map {
      $_->{handle} //= $data->{handle};
      App::LinkSite::Social->new(%$_)
    } $data->{social}->@* ];

    my $links = [ map { App::LinkSite::Link->new(%$_) } $data->{links}->@* ];

    my $sections = [];
    if ($data->{sections}) {
      $sections = [ map {
        my $section_links = [ map { App::LinkSite::Link->new(%$_) } $_->{links}->@* ];
        App::LinkSite::Section->new(
          title => $_->{title},
          links => $section_links,
        )



( run in 3.121 seconds using v1.01-cache-2.11-cpan-f0ff5d10edf )