Skip to content

Commit

Permalink
Merge pull request #539 from canopas/update-aws-s3-sync-command
Browse files Browse the repository at this point in the history
Fix: sitemap api and updating sitemap.xml
  • Loading branch information
cp-sumi-k authored Jan 24, 2024
2 parents 68c32a3 + e362cc8 commit dc1883e
Show file tree
Hide file tree
Showing 18 changed files with 109 additions and 75 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy-backend-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/github-actions-backend-access
aws-region: ap-south-1

- name: Build backend and deploy to S3
- name: Build backend and copy zip to S3
run: |
apt-get update && apt-get install -y zip
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o main main.go
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy-backend-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/github-actions-backend-access
aws-region: ap-south-1

- name: Build backend and deploy to S3
- name: Build backend and copy zip to S3
run: |
apt-get update && apt-get install -y zip
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o main main.go
Expand Down
7 changes: 5 additions & 2 deletions .github/workflows/deploy-frontend-dev.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
name: DeployFrontendDev

on:
push:
branches:
workflow_run:
workflows: ["DeployBackendDev"]
types:
- completed
branches:
- "master"

jobs:
Expand Down
7 changes: 5 additions & 2 deletions .github/workflows/deploy-frontend-prod.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
name: DeployFrontendProd

on:
push:
branches:
workflow_run:
workflows: ["DeployBackendProd"]
types:
- completed
branches:
- "master"

jobs:
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ This repository contains the working code of [Canopas website](https://canopas.c

[Here](https://github.com/canopas/canopas-website/blob/master/api-doc.md) is APIs reference used in the website.

### For generating sitemap :
- Add your pages to templates/path.txt

# Canopas website -- Frontend

## Requirements
Expand Down
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
)

//go:embed templates/*.html
//go:embed templates/*.txt
var templateFS embed.FS

var router *gin.Engine
Expand Down Expand Up @@ -55,7 +56,7 @@ func setupRouter() *gin.Engine {
utilsRepo := utils.NewEmail()
contactRepo := contact.New(templateFS, utilsRepo)
jobsRepo := jobs.New(sqlDb, templateFS, utilsRepo)
sitemapRepo := sitemap.New(jobsRepo)
sitemapRepo := sitemap.New(jobsRepo, templateFS)
leaveRepo := leave.New(templateFS, utilsRepo)
notificationRepo := notification.New(templateFS, utilsRepo)
lifePerksImagesRepo := jobs.NewLifePerksImages(sqlDb)
Expand Down
2 changes: 2 additions & 0 deletions nuxt-frontend/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.yml
*.json
6 changes: 3 additions & 3 deletions nuxt-frontend/components/services/WhatWeOfferDesktop.vue
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export default {
title: "Flutter App Development ",
description:
"Bring your multi-platform app vision to life with our Flutter app development services. We excel in crafting high-quality, stunning applications that work flawlessly on Android, iOS, and the web, all from a single codebase, facilitating faster time to market and cost savings.",
url: "/flutter-app-development-ND",
url: "/flutter-app-development",
showServices: config.SHOW_FLUTTER_APP_DEVELOPMENT_PAGE,
},
{
Expand All @@ -106,7 +106,7 @@ export default {
title: "Backend Development",
description:
"The 'behind-the-scenes' backbone of any app, the backend, handles the critical tasks of data management, server configuration, and application logic. Our experts ensure your app is robust, secure, and efficient from its core, enabling it to handle high traffic loads, process data swiftly, and interact flawlessly with front-end requests.",
url: "/backend-development-ND",
url: "/backend-development",
showServices: config.SHOW_BACKEND_DEVELOPMENT_PAGE,
},
{
Expand All @@ -115,7 +115,7 @@ export default {
title: "Frontend Development",
description:
"The front end is the first point of interaction between your users and your app, making its design and functionality crucial. We focus on creating interactive, visually stunning, and easy-to-navigate interfaces that make your digital presence stand out, promoting enhanced user satisfaction and brand loyalty. ",
url: "/frontend-development-ND",
url: "/frontend-development",
showServices: config.SHOW_FRONTEND_DEVELOPMENT_PAGE,
},
],
Expand Down
6 changes: 3 additions & 3 deletions nuxt-frontend/components/services/WhatWeOfferMobile.vue
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export default {
"Bring your multi-platform app vision to life with our Flutter app development services. We excel in crafting high-quality, stunning applications that work flawlessly on Android, iOS, and the web, all from a single codebase, facilitating faster time to market and cost savings.",
class:
"bg-gradient-to-b from-[#E0EDFF] via-[#E0EDFF] to-white bg-gradient-[180deg] ",
url: "/flutter-app-development-ND",
url: "/flutter-app-development",
showServices: config.SHOW_FLUTTER_APP_DEVELOPMENT_PAGE,
},
{
Expand All @@ -106,7 +106,7 @@ export default {
"The 'behind-the-scenes' backbone of any app, the backend, handles the critical tasks of data management, server configuration, and application logic. Our experts ensure your app is robust, secure, and efficient from its core, enabling it to handle high traffic loads, process data swiftly, and interact flawlessly with front-end requests.",
class:
"bg-gradient-to-b from-[#D2D8E3]/[0.95] via-[#D2D8E3]/[0.95] to-white bg-gradient-[180deg] ",
url: "/backend-development-ND",
url: "/backend-development",
showServices: config.SHOW_BACKEND_DEVELOPMENT_PAGE,
},
{
Expand All @@ -116,7 +116,7 @@ export default {
"The front end is the first point of interaction between your users and your app, making its design and functionality crucial. We focus on creating interactive, visually stunning, and easy-to-navigate interfaces that make your digital presence stand out, promoting enhanced user satisfaction and brand loyalty. ",
class:
"bg-gradient-to-b from-[#BBDEFF] via-[#BBDEFF] to-white bg-gradient-[180deg] ",
url: "/frontend-development-ND",
url: "/frontend-development",
showServices: config.SHOW_FRONTEND_DEVELOPMENT_PAGE,
},
],
Expand Down
6 changes: 3 additions & 3 deletions nuxt-frontend/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,23 +116,23 @@ export default Object.freeze({
description:
"We create bespoke Flutter applications known for their supreme performance, unwavering security, and outmost reliability",
type: "Website",
url: "https://dev-stack.canopas.com/flutter-app-development-ND",
url: "https://dev-stack.canopas.com/flutter-app-development",
image: "https://dev-stack.canopas.com/apple-touch-icon.png",
},
BACKEND_DEVELOPMENT_SEO_META_DATA: {
title: "Backend Development Company - Canopas",
description:
"We create bespoke Backend API's known for their supreme performance, unwavering security, and outmost reliability",
type: "Website",
url: "https://dev-stack.canopas.com/backend-development-ND",
url: "https://dev-stack.canopas.com/backend-development",
image: "https://dev-stack.canopas.com/apple-touch-icon.png",
},
FRONTEND_DEVELOPMENT_SEO_META_DATA: {
title: "Frontend Development Company - Canopas",
description:
"We create bespoke Frontend webpages known for their supreme performance, unwavering security, and outmost reliability",
type: "Website",
url: "https://dev-stack.canopas.com/frontend-development-ND",
url: "https://dev-stack.canopas.com/frontend-development",
image: "https://dev-stack.canopas.com/apple-touch-icon.png",
},
IS_PROD: false,
Expand Down
6 changes: 3 additions & 3 deletions nuxt-frontend/config.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,23 +116,23 @@ export default Object.freeze({
description:
"We create bespoke Flutter applications known for their supreme performance, unwavering security, and outmost reliability",
type: "Website",
url: "https://canopas.com/flutter-app-development-ND",
url: "https://canopas.com/flutter-app-development",
image: "https://canopas.com/apple-touch-icon.png",
},
BACKEND_DEVELOPMENT_SEO_META_DATA: {
title: "Backend Development Company - Canopas",
description:
"We create bespoke Backend API's known for their supreme performance, unwavering security, and outmost reliability",
type: "Website",
url: "https://canopas.com/backend-development-ND",
url: "https://canopas.com/backend-development",
image: "https://canopas.com/apple-touch-icon.png",
},
FRONTEND_DEVELOPMENT_SEO_META_DATA: {
title: "Frontend Development Company - Canopas",
description:
"We create bespoke Frontend webpages known for their supreme performance, unwavering security, and outmost reliability",
type: "Website",
url: "https://dev-stack.canopas.com/frontend-development-ND",
url: "https://dev-stack.canopas.com/frontend-development",
image: "https://dev-stack.canopas.com/apple-touch-icon.png",
},
IS_PROD: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export default {
if (!config.SHOW_BACKEND_DEVELOPMENT_PAGE) {
next({
name: "Error404Page",
params: { pathMatch: "/backend-development-ND" },
params: { pathMatch: "/backend-development" },
});
} else {
next();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export default {
if (!config.SHOW_FLUTTER_APP_DEVELOPMENT_PAGE) {
next({
name: "Error404Page",
params: { pathMatch: "/flutter-app-development-ND" },
params: { pathMatch: "/flutter-app-development" },
});
} else {
next();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default {
if (!config.SHOW_FRONTEND_DEVELOPMENT_PAGE) {
next({
name: "Error404Page",
params: { pathMatch: "/frontend-development-ND" },
params: { pathMatch: "/frontend-development" },
});
} else {
next();
Expand Down
84 changes: 40 additions & 44 deletions sitemap/sitemap.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package sitemap

import (
"bytes"
"embed"
"encoding/json"
"encoding/xml"
"io/ioutil"
"io"
"jobs"
"net/http"
"os"
"path/filepath"
"strings"
"text/template"
"time"

log "github.com/sirupsen/logrus"
Expand All @@ -23,10 +25,12 @@ const (

type SitemapRepository struct {
careerRepo *jobs.CareerRepository
templates *template.Template
}

func New(careerRepo *jobs.CareerRepository) *SitemapRepository {
return &SitemapRepository{careerRepo: careerRepo}
func New(careerRepo *jobs.CareerRepository, templateFs embed.FS) *SitemapRepository {
templates := template.Must(template.ParseFS(templateFs, "templates/*.txt"))
return &SitemapRepository{careerRepo: careerRepo, templates: templates}
}

type URL struct {
Expand Down Expand Up @@ -74,24 +78,15 @@ type URLset struct {
URL []URL `xml:"url"`
}

var testFolderPath string

func (repository *SitemapRepository) GenerateSitemap(c *gin.Context) {
baseUrl := c.Query("baseUrl")

sitemapUrls := []URL{
{Loc: baseUrl, Priority: `1`},
{Loc: baseUrl + "/resources", Priority: `0.9`},
}

var folderPath string
if testFolderPath != "" {
folderPath = testFolderPath
} else {
folderPath = "nuxt-frontend/pages"
}

sitemapUrls, err := repository.addPages(baseUrl, sitemapUrls, folderPath)
filePath := "templates/path.txt"
sitemapUrls, err := repository.addPages(baseUrl, sitemapUrls, filePath)
if err != nil {
log.Error(err)
c.AbortWithStatus(http.StatusInternalServerError)
Expand Down Expand Up @@ -126,26 +121,40 @@ func (repository *SitemapRepository) GenerateSitemap(c *gin.Context) {
c.XML(http.StatusOK, urlset)
}

func (repository *SitemapRepository) addPages(baseUrl string, sitemapUrls []URL, folderPath string) ([]URL, error) {
files, err := ioutil.ReadDir(folderPath)
func (repository *SitemapRepository) addPages(baseUrl string, sitemapUrls []URL, file string) ([]URL, error) {
var templateBuffer bytes.Buffer
var input string

err := repository.templates.ExecuteTemplate(&templateBuffer, "path.txt", input)

if err != nil {
return sitemapUrls, err
log.Error(err)
return sitemapUrls, nil
}

for _, file := range files {
if !file.IsDir() {
fileName := file.Name()
fileContent := string(templateBuffer.String())
lines := strings.Split(fileContent, "\n")

// append all pages
for _, fileName := range lines {
sitemapUrls = append(sitemapUrls, URL{Loc: baseUrl + "/" + fileName, Priority: "0.9"})
}

// Check if the file name contains "ND"
if !strings.Contains(fileName, "ND") && !strings.Contains(fileName, "slug") && !strings.Contains(fileName, "index") && !strings.Contains(fileName, "unsubscribe") {
// Extract file name without extension
nameWithoutExt := strings.TrimSuffix(fileName, filepath.Ext(fileName))
// append jobs
jobsUrl := baseUrl + "/jobs"
sitemapUrls = append(sitemapUrls, URL{Loc: jobsUrl, Priority: `1`})

// Create URL and append to sitemapUrls
sitemapUrls = append(sitemapUrls, URL{Loc: baseUrl + "/" + nameWithoutExt, Priority: "0.9"})
}
}
careers, err := repository.careerRepo.GetCareers()
if err != nil {
return sitemapUrls, err
}

for i := range careers {
sitemapUrls = append(sitemapUrls, URL{Loc: jobsUrl + `/` + careers[i].UniqueId, Priority: `0.9`})
sitemapUrls = append(sitemapUrls, URL{Loc: jobsUrl + `/apply/` + careers[i].UniqueId, Priority: `0.9`})
}

// append portfolios
portfolioUrl := baseUrl + "/portfolio"

portfolios := []Portfolio{
Expand All @@ -167,26 +176,13 @@ func (repository *SitemapRepository) addPages(baseUrl string, sitemapUrls []URL,
},
}

sitemapUrls = append(sitemapUrls, URL{Loc: portfolioUrl, Priority: `0.9`})

for i := range portfolios {
sitemapUrls = append(sitemapUrls, URL{Loc: portfolioUrl + `/` + portfolios[i].Name, Priority: `0.9`, Video: portfolios[i].Videos})
}
jobsUrl := baseUrl + "/jobs"
sitemapUrls = append(sitemapUrls, URL{Loc: jobsUrl, Priority: `1`})

careers, err := repository.careerRepo.GetCareers()
if err != nil {
return sitemapUrls, err
}

for i := range careers {
sitemapUrls = append(sitemapUrls, URL{Loc: jobsUrl + `/` + careers[i].UniqueId, Priority: `0.9`})
sitemapUrls = append(sitemapUrls, URL{Loc: jobsUrl + `/apply/` + careers[i].UniqueId, Priority: `0.9`})
}

return sitemapUrls, nil
}

func addPublishedResources(baseUrl string, sitemapUrls []URL) ([]URL, error) {

resourceUrl := os.Getenv("RESOURCES_URL")
Expand All @@ -208,7 +204,7 @@ func addPublishedResources(baseUrl string, sitemapUrls []URL) ([]URL, error) {
}
defer resp.Body.Close()

responseData, err := ioutil.ReadAll(resp.Body)
responseData, err := io.ReadAll(resp.Body)
if err != nil {
log.Error(err)
return sitemapUrls, err
Expand Down
Loading

0 comments on commit dc1883e

Please sign in to comment.