Skip to content

Instantly share code, notes, and snippets.

@preaction
Last active July 7, 2021 12:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save preaction/449580baaa97e045b6e170823ec33a92 to your computer and use it in GitHub Desktop.
Save preaction/449580baaa97e045b6e170823ec33a92 to your computer and use it in GitHub Desktop.
Static Site Generator with Yancy
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}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment