website/lib/DB/MarkdownPost.rakumod

35 lines
747 B
Raku
Raw Normal View History

2025-01-22 20:49:27 -05:00
use v6.e.PREVIEW;
use Pandoc;
use JSON::Class:auth<zef:vrurg>;
use DB::Post;
#| A plain markdown post
unit class MarkdownPost does Post is json(:pretty);
2025-01-22 20:49:27 -05:00
#| Marker for disambiguation between post types in json representation, the
#| cheaty way
has Bool:D $.markdown = True;
2025-02-04 16:51:37 -05:00
#| Override the generated description for this post
has Str $.summary;
2025-01-22 20:49:27 -05:00
method title(--> Str:D) {
2025-02-03 21:51:09 -05:00
markdown-title $!source
2025-01-22 20:49:27 -05:00
}
2025-02-03 20:41:31 -05:00
# Simply provide our source file to pandoc
method render-html(--> Str:D) {
2025-02-03 21:51:09 -05:00
markdown-to-html $!source
2025-02-03 20:41:31 -05:00
}
2025-02-04 16:51:37 -05:00
# Return our summary, if we have one, otherwise extract the first paragraph of
# the markdown document
method description(--> Str) {
if $!summary {
$!summary
} else {
markdown-first-paragraph $!source
}
}