From 403aeb48fedbe12148b45bd226a6fda3e68739ad Mon Sep 17 00:00:00 2001 From: Sumita Canopas Date: Wed, 21 Feb 2024 16:22:19 +0530 Subject: [PATCH] Add dynamic sitemap --- .github/workflows/deploy-backend-dev.yml | 2 - .github/workflows/deploy-frontend-dev.yml | 3 +- .github/workflows/deploy-frontend-prod.yml | 7 +- nuxt-frontend/nuxt.config.js | 15 +- nuxt-frontend/package.json | 1 + nuxt-frontend/pages/author/[slug].vue | 25 +- nuxt-frontend/pages/tag/[slug].vue | 20 +- nuxt-frontend/stores/author/index.js | 36 +- nuxt-frontend/stores/tags/index.js | 38 +- nuxt-frontend/yarn.lock | 656 ++++++++++++++++++++- sitemap/sitemap.go | 112 ++-- sitemap/sitemap_test.go | 20 +- 12 files changed, 771 insertions(+), 164 deletions(-) diff --git a/.github/workflows/deploy-backend-dev.yml b/.github/workflows/deploy-backend-dev.yml index ee523bd36..f6c335c3a 100644 --- a/.github/workflows/deploy-backend-dev.yml +++ b/.github/workflows/deploy-backend-dev.yml @@ -2,8 +2,6 @@ name: DeployBackendDev on: push: - branches: - - "master" jobs: deploy-backend-dev: diff --git a/.github/workflows/deploy-frontend-dev.yml b/.github/workflows/deploy-frontend-dev.yml index 1f906729e..b77aa3252 100644 --- a/.github/workflows/deploy-frontend-dev.yml +++ b/.github/workflows/deploy-frontend-dev.yml @@ -6,7 +6,7 @@ on: types: - completed branches: - - "master" + - "add-dynamic-sitemap" jobs: deploy-frontend-dev: @@ -37,6 +37,7 @@ jobs: sh ./../deploy/generate-sitemap.sh https://dev-stack.canopas.com https://dev-stack-api.canopas.com yarn install --frozen-lockfile && yarn build cd .output/server && zip canopas_website_SSR_dev_${{ github.sha }}-${{ github.run_attempt }}.zip -r . && aws s3 cp canopas_website_SSR_dev_${{ github.sha }}-${{ github.run_attempt }}.zip s3://canopas-lambda-handlers && cd ../.. + aws s3 rm s3://canopas-website-ssr-dev --recursive aws s3 sync --cache-control 'max-age=604800' --exclude *.html ./.output/public s3://canopas-website-ssr-dev aws s3 sync ./.output/public s3://canopas-website-ssr-dev aws cloudfront create-invalidation --distribution-id ${{ secrets.CLOUDFRONT_DISTRIBUTION_ID_DEV }} --paths "/sitemap.xml" diff --git a/.github/workflows/deploy-frontend-prod.yml b/.github/workflows/deploy-frontend-prod.yml index fcc852870..f2d64d27f 100644 --- a/.github/workflows/deploy-frontend-prod.yml +++ b/.github/workflows/deploy-frontend-prod.yml @@ -5,7 +5,7 @@ on: workflows: ["DeployBackendProd"] types: - completed - branches: + branches: - "master" jobs: @@ -38,6 +38,7 @@ jobs: sh ./../deploy/generate-sitemap.sh https://canopas.com https://prod-stack-api.canopas.com yarn install --frozen-lockfile && yarn build cd .output/server && zip canopas_website_SSR_prod_${{ github.sha }}-${{ github.run_attempt }}.zip -r . && aws s3 cp canopas_website_SSR_prod_${{ github.sha }}-${{ github.run_attempt }}.zip s3://canopas-lambda-handlers && cd ../.. + aws s3 rm s3://canopas-website-ssr-dev --recursive aws s3 sync --cache-control 'max-age=604800' --exclude *.html ./.output/public s3://canopas-website-ssr-prod aws s3 sync ./.output/public s3://canopas-website-ssr-prod aws cloudfront create-invalidation --distribution-id ${{ secrets.CLOUDFRONT_DISTRIBUTION_ID_PROD }} --paths "/sitemap.xml" @@ -52,5 +53,5 @@ jobs: timeout-in-minutes: "10" no-fail-on-empty-changeset: "1" parameter-overrides: >- - EnvName=prod, - ZipFileName=canopas_website_SSR_prod_${{ github.sha }}-${{ github.run_attempt }}.zip + EnvName=prod, + ZipFileName=canopas_website_SSR_prod_${{ github.sha }}-${{ github.run_attempt }}.zip diff --git a/nuxt-frontend/nuxt.config.js b/nuxt-frontend/nuxt.config.js index 21fd53075..141d6ecc6 100644 --- a/nuxt-frontend/nuxt.config.js +++ b/nuxt-frontend/nuxt.config.js @@ -18,7 +18,16 @@ export default defineNuxtConfig({ "nuxt-icon", "@canopassoftware/blog-components", "nuxt-lazy-hydrate", + "@nuxtjs/sitemap", ], + sitemap: { + defaults: { + lastmod: new Date(), + }, + sources: [config.API_BASE + "/api/sitemap"], + xsl: false, + xslTips: false, + }, css: ["~/assets/css/global.css", "~/assets/css/app.css"], generate: { fallback: true }, imports: { @@ -49,9 +58,9 @@ export default defineNuxtConfig({ "/android-app-development": { prerender: true }, "/ios-app-development": { prerender: true }, "/mobile-app-development": { prerender: true }, - "/backend-app-development": { prerender: true }, - "/flutter-app-development": { prerender: true }, - "/frontend-development": { prerender: true }, + "/backend-development": { prerender: true, sitemap: !config.IS_PROD }, + "/flutter-app-development": { prerender: true, sitemap: !config.IS_PROD }, + "/frontend-development": { prerender: true, sitemap: !config.IS_PROD }, "/thank-you": { prerender: true }, "/unsubscribe": { prerender: true }, }, diff --git a/nuxt-frontend/package.json b/nuxt-frontend/package.json index b8b520364..12bc2c455 100644 --- a/nuxt-frontend/package.json +++ b/nuxt-frontend/package.json @@ -14,6 +14,7 @@ "@canopassoftware/blog-components": "^1.2.4", "@ivanv/vue-collapse-transition": "^1.0.2", "@nuxt/devtools": "latest", + "@nuxtjs/sitemap": "^5.1.0", "@types/lozad": "^1.16.4", "@vue/cli-plugin-babel": "^5.0.8", "@vue/cli-plugin-eslint": "^5.0.8", diff --git a/nuxt-frontend/pages/author/[slug].vue b/nuxt-frontend/pages/author/[slug].vue index 911308c71..37e43d510 100644 --- a/nuxt-frontend/pages/author/[slug].vue +++ b/nuxt-frontend/pages/author/[slug].vue @@ -1,8 +1,15 @@