From b256cec5a2b80b1b14070094e4ee1c86147b3f90 Mon Sep 17 00:00:00 2001 From: cp-dharti-r Date: Mon, 6 May 2024 15:08:26 +0530 Subject: [PATCH] Exclude unnecessary pages from sitemap --- nuxt-frontend/nuxt.config.js | 1 + post/author.go | 20 +++++++++++--------- post/index.go | 28 +++++++++++++++------------- 3 files changed, 27 insertions(+), 22 deletions(-) diff --git a/nuxt-frontend/nuxt.config.js b/nuxt-frontend/nuxt.config.js index c71ce2ca1..12dd50a13 100644 --- a/nuxt-frontend/nuxt.config.js +++ b/nuxt-frontend/nuxt.config.js @@ -27,6 +27,7 @@ export default defineNuxtConfig({ defaults: { lastmod: new Date(), }, + exclude: ['/unsubscribe', "/thank-you", "/jobs/thank-you"], sources: [config.API_BASE + "/api/sitemap"], xsl: false, xslTips: false, diff --git a/post/author.go b/post/author.go index fb3bf5efc..60b166082 100644 --- a/post/author.go +++ b/post/author.go @@ -63,7 +63,7 @@ func (repository *Repository) GetPostsByAuthor(c *gin.Context) { Count int `json:"count"` } - new_posts := PostData + new_post := PostData for _, post := range posts { var tags []Tag @@ -77,22 +77,24 @@ func (repository *Repository) GetPostsByAuthor(c *gin.Context) { post.Tag = "" post.Tags = tags - new_posts.Posts = append(new_posts.Posts, post) + new_post.Posts = append(new_post.Posts, post) } - new_posts.Posts = repository.PreparePosts(new_posts.Posts) + new_post.Posts = repository.PreparePosts(new_post.Posts) - publishQuery := "" - if isPublished { - publishQuery = "WHERE p.is_published = true" - } + if skip == 0 { + publishQuery := "" + if isPublished { + publishQuery = "WHERE p.is_published = true" + } - err = repository.Db.Get(&new_posts.Count, `SELECT COUNT(p.id) + err = repository.Db.Get(&new_post.Count, `SELECT COUNT(p.id) FROM posts p JOIN posts_author_links pa ON p.id = pa.post_id JOIN authors a ON a.id = pa.author_id AND a.username = $1 `+publishQuery, username) + } - c.JSON(http.StatusOK, new_posts) + c.JSON(http.StatusOK, new_post) } func (repository *Repository) GetAuthorByPostId(id int) (error, Author) { diff --git a/post/index.go b/post/index.go index 291546f32..f117cb8b5 100644 --- a/post/index.go +++ b/post/index.go @@ -53,34 +53,36 @@ func (repository *Repository) Get(c *gin.Context) { Count int `json:"count"` } - new_posts := PostData - err, new_posts.Posts = repository.GetPosts(false, isResource, isPublished, limit, skip) + new_post := PostData + err, new_post.Posts = repository.GetPosts(false, isResource, isPublished, limit, skip) if err != nil { c.AbortWithStatus(http.StatusInternalServerError) return } if isResource && skip == 0 { - err, new_posts.FeaturedPosts = repository.GetPosts(true, isResource, isPublished, 6, 0) + err, new_post.FeaturedPosts = repository.GetPosts(true, isResource, isPublished, 6, 0) if err != nil { c.AbortWithStatus(http.StatusInternalServerError) return } } - resourceQuery := "is_resource = false AND" - if isResource { - resourceQuery = "is_resource = true AND" - } + if skip == 0 { + resourceQuery := "is_resource = false AND" + if isResource { + resourceQuery = "is_resource = true AND" + } - publishQuery := "" - if isPublished { - publishQuery = "AND is_published = true" - } + publishQuery := "" + if isPublished { + publishQuery = "AND is_published = true" + } - err = repository.Db.Get(&new_posts.Count, `SELECT COUNT(id) FROM posts WHERE `+resourceQuery+` is_featured = false `+publishQuery) + err = repository.Db.Get(&new_post.Count, `SELECT COUNT(id) FROM posts WHERE `+resourceQuery+` is_featured = false `+publishQuery) + } - c.JSON(http.StatusOK, new_posts) + c.JSON(http.StatusOK, new_post) } func (repository *Repository) GetPosts(isFeatured, isResource, isPublished bool, limit, skip int) (error, []Post) {