Description generation

This commit is contained in:
Nathan McCarty 2025-02-04 16:51:37 -05:00
parent 804b51aaa6
commit ce364c01d8
6 changed files with 102 additions and 33 deletions

View file

@ -14,6 +14,9 @@ unit class IdrisPost does Post is json(:pretty);
#| cheaty way
has Bool:D $.idris is json = True;
#| Override the generated description for this post
has Str $.summary is json;
#| Location of the ipkg for the package containing the post
has IO::Path:D $.ipkg
is required
@ -48,6 +51,16 @@ method render-html(--> Str:D) {
};
}
# 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
}
}
# Run a pack command, erroring on failure
sub pack(*@args) {
my $pack = run 'pack', @args, :out, :err;

View file

@ -11,6 +11,9 @@ unit class MarkdownPost does Post is json(:pretty);
#| cheaty way
has Bool:D $.markdown = True;
#| Override the generated description for this post
has Str $.summary;
method title(--> Str:D) {
markdown-title $!source
}
@ -19,3 +22,13 @@ method title(--> Str:D) {
method render-html(--> Str:D) {
markdown-to-html $!source
}
# 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
}
}

View file

@ -53,3 +53,8 @@ method all-slugs(--> Array[Str:D]) {
#| Render this post to an html body
method render-html(--> Str:D) {...}
#| Get the description for this post, returning nil if there is none
method description(--> Str) {
Nil
}