also remove post from list if unlist is set

Peter Cai 3 years ago
parent c68263a7bd
commit 7de1212993
No known key found for this signature in database
GPG Key ID: 71F5FB4E4F3FD54F

@ -42,10 +42,18 @@ impl PostsList {
if self.has_post(uuid) {
return Ok(());
self.0.insert(0, uuid.into());
store::put_obj_pretty("posts_list", self.0).await
// Remove a post from published list
// may be used when deleting / unpublishing a post
// Does nothing if uuid not found in list
pub async fn remove_post(mut self, uuid: &str) -> MyResult<()> {
store::put_obj_pretty("posts_list", self.0).await
#[derive(Serialize, Deserialize)]

@ -1,3 +1,5 @@
extern crate lazy_static;

@ -75,11 +75,10 @@ async fn get_actions(_req: Request, url: Url) -> MyResult<Response> {
struct CustomMetadata {
// If unlist is set to TRUE upon first publication,
// the post won't be listed publicly on the blog.
// However, this has no effect if set to TRUE after first publication.
// (setting to FALSE after first publication MAY work)
// You will have to first delete the blog before changing this value.
// If unlist is set to TRUE,
// the post won't be listed publicly on the blog,
// and if the post were published, it will
// be removed from the public list
unlist: Option<bool>,
url: Option<String>,
timestamp: Option<String> // Should be something `js_sys::Date::parse` could handle
@ -203,8 +202,11 @@ async fn create_or_update_post(req: Request, url: Url) -> MyResult<Response> {
// As you may have seen by now, the process is far from atomic
// This is fine because we don't expect users to update posts from
// multiple endpoints simultaneously all the time
let list = blog::PostsList::load().await;
if !metadata.unlist {
} else {