post tag command
This commit is contained in:
parent
e05269b9a3
commit
7a5ef790f3
2 changed files with 29 additions and 1 deletions
28
blog
28
blog
|
@ -254,3 +254,31 @@ multi MAIN(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#| Add or remove a tag to a post
|
||||||
|
multi MAIN(
|
||||||
|
"post",
|
||||||
|
"tag",
|
||||||
|
#| The id of the post to display information for
|
||||||
|
Int $id,
|
||||||
|
#| The tag to add/remove
|
||||||
|
Str $tag,
|
||||||
|
#| remove the tag instead of adding it
|
||||||
|
Bool :$remove,
|
||||||
|
#| The path of the database directory
|
||||||
|
IO::Path(Str) :$db-dir = $default-db-dir,
|
||||||
|
) {
|
||||||
|
my $db = read-db $db-dir;
|
||||||
|
my $post = $db.posts{$id.Int};
|
||||||
|
if $remove {
|
||||||
|
die "Post did not have requested tag"
|
||||||
|
unless $tag ~~ any($post.tags);
|
||||||
|
my $index = $post.tags.first: $tag;
|
||||||
|
$post.tags.=grep(* ne $tag);
|
||||||
|
} else {
|
||||||
|
die "Post already had requested tag"
|
||||||
|
if $tag ~~ any($post.tags);
|
||||||
|
$post.tags.push: $tag;
|
||||||
|
}
|
||||||
|
$db.write: $db-dir;
|
||||||
|
}
|
||||||
|
|
|
@ -37,7 +37,7 @@ DateTime:D @.edited-at
|
||||||
#| An optional list of extra slugs to use for this post
|
#| An optional list of extra slugs to use for this post
|
||||||
has Str:D @.slugs is json = [];
|
has Str:D @.slugs is json = [];
|
||||||
#| An optional list of tags for this post
|
#| An optional list of tags for this post
|
||||||
has Str:D @.tags is json = [];
|
has Str:D @.tags is rw is json = [];
|
||||||
#| Should the post be hidden from the main list
|
#| Should the post be hidden from the main list
|
||||||
has Bool:D $.hidden is json is rw = False;
|
has Bool:D $.hidden is json is rw = False;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue