title | published |
---|---|
A Blog Post |
2021-03-21 |
This will appear in the blog because it has a published
field in the frontmatter.
title | published |
---|---|
A Blog Post |
2021-03-21 |
This will appear in the blog because it has a published
field in the frontmatter.
title |
---|
My Site |
This is my site. This page does not appear in the blog because it does not have a published
field in the frontmatter.
use Mojolicious::Lite; | |
plugin Yancy => { | |
backend => 'static:' . app->home, | |
schema => { | |
pages => { | |
properties => { | |
published => { | |
type => 'string', | |
format => 'date-time', | |
}, | |
}, | |
}, | |
}, | |
}; | |
plugin Moai => [ Bootstrap4 => { version => '4.4.1' } ]; | |
plugin 'Export::Git'; | |
get '/blog' => { | |
controller => 'yancy', | |
action => 'list', | |
schema => 'pages', | |
template => 'list', | |
filter => { | |
published => { '!=' => undef }, | |
}, | |
sort_by => { -desc => 'published' }, | |
}; | |
get '/*slug' => { | |
slug => 'index', # Default to index page | |
controller => 'yancy', | |
action => 'get', | |
schema => 'pages', | |
template => 'pages', | |
}; | |
app->start; | |
__DATA__ | |
@@ layouts/default.html.ep | |
<% | |
extends 'layouts/moai/default'; | |
my $site_name = 'Yancy Static Site'; | |
my $menu_items = [ | |
[ Blog => '/blog' ], | |
]; | |
%> | |
% content_for navbar => begin | |
%= include 'moai/menu/navbar', class => { navbar => 'navbar-light bg-light' }, brand => [ $site_name, '/' ], menu => $menu_items | |
% end | |
@@ list.html.ep | |
% layout 'default'; | |
% for my $item ( @$items ) { | |
<article> | |
<h1><%= link_to $item->{title}, "/$item->{slug}" %></h1> | |
%== $item->{html} | |
</article> | |
% } | |
%= include 'moai/pager' | |
@@ pages.html.ep | |
% layout 'default'; | |
<h1><%= $item->{title} %></h1> | |
%== $item->{html} |