Skip to content

Commit

Permalink
Exclude unnecessary pages from sitemap
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-dharti-r committed May 6, 2024
1 parent 864cca6 commit b256cec
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 22 deletions.
1 change: 1 addition & 0 deletions nuxt-frontend/nuxt.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
20 changes: 11 additions & 9 deletions post/author.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand Down
28 changes: 15 additions & 13 deletions post/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit b256cec

Please sign in to comment.