def takeDownArticle()

in src/main/scala/managehelpcontentpublisher/PathAndContent.scala [135:157]


  def takeDownArticle(publishingOps: PublishingOps)(path: String): Either[Failure, Seq[PathAndContent]] = {

    def removeFromSitemap(article: Article): Either[Failure, Option[PathAndContent]] =
      for {
        oldSitemap <- publishingOps.fetchSitemap()
        articleUrl = new URI(s"${config.articleUrlPrefix}/${article.path}")
        newSitemap = oldSitemap - articleUrl
        _ <- publishingOps.storeSitemap(newSitemap).tap(_ => pingGoogle())
      } yield Some(PathAndContent(config.aws.sitemapFile, newSitemap.toSeq.sorted.mkString("\n")))

    for {
      optArticleJson <- publishingOps.fetchArticleByPath(path)
      articleJson <- optArticleJson.toRight(NotFoundFailure)
      article <- readArticle(articleJson)
      topicsArticleRemovedFrom <- removeFromTopics(publishingOps)(article, article.topics)
      moreTopicsWithoutArticle <- publishMoreTopics(publishingOps)(Some(article), Nil)
      deletedPath <- publishingOps.deleteArticleByPath(path)
      updatedSitemap <- removeFromSitemap(article)
    } yield (topicsArticleRemovedFrom ++
      moreTopicsWithoutArticle.toSeq :+
      PathAndContent(deletedPath, "")) ++
      updatedSitemap.toSeq
  }