Open graph tag generation for posts

This commit is contained in:
Nathan McCarty 2025-02-12 03:38:55 -05:00
parent 585b2be5ab
commit 2862f45d77
5 changed files with 40 additions and 26 deletions

View file

@ -2,25 +2,15 @@ use v6.e.PREVIEW;
use DB::Post;
use DB::BlogMeta;
use Render::Util;
use XML;
unit module Atom;
# get the link for a post
sub post-link(BlogMeta:D $meta, Int:D $id, Post:D $post --> Str:D) {
my @slugs = $post.all-slugs;
my $base = $meta.get-base-url;
if @slugs.elems {
"$base/posts/by-slug/{@slugs[*-1]}.html"
} else {
"$base/posts/by-id/$id.html"
}
}
#| Convert a single post to an atom item
sub post-to-item(BlogMeta:D $meta, Int:D $id, Post:D $post --> XML::Element) {
my $link = post-link $meta, $id, $post;
my $link = post-link-abs $meta, $id, $post;
my $desc = $post.description;
my $xml = XML::Element.new(:name<entry>);
$xml.append: