Skip to content

Commit

Permalink
feat: sitemap js
Browse files Browse the repository at this point in the history
  • Loading branch information
osslgtm authored and simboonlong committed Jun 21, 2023
1 parent 8196281 commit 7c38069
Show file tree
Hide file tree
Showing 9 changed files with 1,702 additions and 1,732 deletions.
3,077 changes: 1,573 additions & 1,504 deletions package-lock.json

Large diffs are not rendered by default.

13 changes: 4 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"build:prod": "cross-env NODE_ENV=production NET=mainnet npm run build",
"build:css": "postcss src/tailwind.css -o src/index.css",
"build:app": "webpack --progress --mode production",
"build:sitemap": "babel-node sitemap/sitemap.ts",
"build:sitemap": "npx ts-node --compiler-options '{\"module\":\"commonjs\"}' sitemap.ts",
"check-types": "tsc --sourceMap false --noEmit",
"credits": "npx @opengovsg/credits-generator && npx mdpdf ./CREDITS.md ./public/static/common/credits.pdf",
"dev": "run-p dev:*",
Expand All @@ -41,8 +41,7 @@
"test:coverage": "npm run test -- --collectCoverage",
"test:watch": "npm run test -- --watchAll",
"test:update": "npm run test -- -u",
"wait": "wait-on -l -i 1000 tcp:8545 http-get://localhost:3000",
"sitemap": "sitemap http://localhost:3000"
"wait": "wait-on -l -i 1000 tcp:8545 http-get://localhost:3000"
},
"dependencies": {
"@govtechsg/address-identity-resolver": "^1.4.1",
Expand Down Expand Up @@ -73,7 +72,6 @@
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-dropzone": "^14.2.1",
"react-dynamic-sitemap": "^1.2.1",
"react-feather": "^2.0.9",
"react-helmet": "^6.1.0",
"react-markdown": "^6.0.2",
Expand All @@ -82,14 +80,11 @@
"react-tooltip": "^4.2.21",
"redux": "^4.1.0",
"redux-saga": "^1.1.3",
"super-simple-sitemap-generator": "^1.0.5",
"swiper": "^8.4.2",
"use-persisted-state": "^0.3.3"
},
"devDependencies": {
"@babel/cli": "^7.21.5",
"@babel/core": "^7.21.8",
"@babel/node": "^7.20.7",
"@babel/core": "^7.14.5",
"@babel/preset-env": "^7.14.5",
"@babel/preset-react": "^7.14.5",
"@babel/preset-typescript": "^7.14.5",
Expand Down Expand Up @@ -148,7 +143,7 @@
"prettier": "^2.3.1",
"redux-devtools-extension": "^2.13.9",
"shelljs": "^0.8.5",
"sitemap-webpack-plugin": "^1.1.1",
"sitemap": "^7.1.1",
"style-loader": "^2.0.0",
"tailwindcss": "^3.0.23",
"testcafe": "^2.3.0",
Expand Down
2 changes: 1 addition & 1 deletion public/static/sitemap.xml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
asd
<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1"><url><loc>https://www.tradetrust.io/</loc><changefreq>monthly</changefreq><priority>0.6</priority></url><url><loc>https://www.tradetrust.io/verify</loc><changefreq>monthly</changefreq><priority>0.6</priority></url><url><loc>https://www.tradetrust.io/viewer</loc><changefreq>monthly</changefreq><priority>0.6</priority></url><url><loc>https://www.tradetrust.io/faq</loc><changefreq>monthly</changefreq><priority>0.6</priority></url><url><loc>https://www.tradetrust.io/faq/general-faq</loc><changefreq>monthly</changefreq><priority>0.6</priority></url><url><loc>https://www.tradetrust.io/faq/product-faq</loc><changefreq>monthly</changefreq><priority>0.6</priority></url><url><loc>https://www.tradetrust.io/eta</loc><changefreq>monthly</changefreq><priority>0.6</priority></url><url><loc>https://www.tradetrust.io/settings</loc><changefreq>monthly</changefreq><priority>0.6</priority></url><url><loc>https://www.tradetrust.io/settings/address-resolver</loc><changefreq>monthly</changefreq><priority>0.6</priority></url><url><loc>https://www.tradetrust.io/settings/address-book</loc><changefreq>monthly</changefreq><priority>0.6</priority></url><url><loc>https://www.tradetrust.io/news</loc><changefreq>monthly</changefreq><priority>0.6</priority></url><url><loc>https://www.tradetrust.io/learn</loc><changefreq>monthly</changefreq><priority>0.6</priority></url><url><loc>https://www.tradetrust.io/event</loc><changefreq>monthly</changefreq><priority>0.6</priority></url><url><loc>https://www.tradetrust.io/guidelines</loc><changefreq>monthly</changefreq><priority>0.6</priority></url><url><loc>https://www.tradetrust.io/privacy-policy</loc><changefreq>monthly</changefreq><priority>0.6</priority></url><url><loc>https://www.tradetrust.io/terms-of-use</loc><changefreq>monthly</changefreq><priority>0.6</priority></url><url><loc>https://www.tradetrust.io/cost</loc><changefreq>monthly</changefreq><priority>0.6</priority></url><url><loc>https://www.tradetrust.io/partners</loc><changefreq>monthly</changefreq><priority>0.6</priority></url><url><loc>https://www.tradetrust.io/news/adoption-of-uncitral-model-law-heralds-a-quiet-revolution-in-digital-trade</loc><changefreq>monthly</changefreq><priority>0.5</priority></url><url><loc>https://www.tradetrust.io/news/singapore-leading-the-way-in-promoting-digital-trade</loc><changefreq>monthly</changefreq><priority>0.5</priority></url><url><loc>https://www.tradetrust.io/news/trade-finance-talks-issue-7-autumn-2021</loc><changefreq>monthly</changefreq><priority>0.5</priority></url><url><loc>https://www.tradetrust.io/news/tradetrust-newsletter-issue-06</loc><changefreq>monthly</changefreq><priority>0.5</priority></url><url><loc>https://www.tradetrust.io/news/tradetrust-newsletter-issue-1</loc><changefreq>monthly</changefreq><priority>0.5</priority></url><url><loc>https://www.tradetrust.io/news/tradetrust-newsletter-issue-10</loc><changefreq>monthly</changefreq><priority>0.5</priority></url><url><loc>https://www.tradetrust.io/news/tradetrust-newsletter-issue-2</loc><changefreq>monthly</changefreq><priority>0.5</priority></url><url><loc>https://www.tradetrust.io/news/tradetrust-newsletter-issue-3</loc><changefreq>monthly</changefreq><priority>0.5</priority></url><url><loc>https://www.tradetrust.io/news/tradetrust-newsletter-issue-4</loc><changefreq>monthly</changefreq><priority>0.5</priority></url><url><loc>https://www.tradetrust.io/news/tradetrust-newsletter-issue-5</loc><changefreq>monthly</changefreq><priority>0.5</priority></url><url><loc>https://www.tradetrust.io/news/tradetrust-newsletter-issue-7</loc><changefreq>monthly</changefreq><priority>0.5</priority></url><url><loc>https://www.tradetrust.io/news/tradetrust-newsletter-issue-8</loc><changefreq>monthly</changefreq><priority>0.5</priority></url><url><loc>https://www.tradetrust.io/news/tradetrust-newsletter-issue-9</loc><changefreq>monthly</changefreq><priority>0.5</priority></url><url><loc>https://www.tradetrust.io/news/r3-partners-with-tram%C3%A9s-and-imda-to-develop-new-solutions-to-bridge-r3-corda-ebl-and-tradetrust</loc><changefreq>monthly</changefreq><priority>0.5</priority></url><url><loc>https://www.tradetrust.io/news/australia-and-singapore%E2%80%99s-blockchain-trial-shows-promising-results-for-reducing-transaction-costs</loc><changefreq>monthly</changefreq><priority>0.5</priority></url><url><loc>https://www.tradetrust.io/news/eight-mous-signed-at-the-third-singapore-china-shenzhen-smart-city-initiative-joint-implementation-committee-meeting</loc><changefreq>monthly</changefreq><priority>0.5</priority></url><url><loc>https://www.tradetrust.io/news/electronic-transactions-act-amended-to-facilitate-electronic-transactions-providing-convenience-and-strengthening-singapore%E2%80%99s-trade-competitiveness-in-the-digital-economy</loc><changefreq>monthly</changefreq><priority>0.5</priority></url><url><loc>https://www.tradetrust.io/news/singapore-and-australia-sign-digital-economy-agreement</loc><changefreq>monthly</changefreq><priority>0.5</priority></url><url><loc>https://www.tradetrust.io/news/singapore-chile-and-new-zealand-sign-digital-economy-partnership-agreement-electronically</loc><changefreq>monthly</changefreq><priority>0.5</priority></url><url><loc>https://www.tradetrust.io/news/singapore-strengthens-digital-collaboration-and-linkages-with-shenzhen-to-create-new-market-opportunities</loc><changefreq>monthly</changefreq><priority>0.5</priority></url><url><loc>https://www.tradetrust.io/news/swift-and-singapores-imda-join-forces-to-drive-global-trade-digitalisation</loc><changefreq>monthly</changefreq><priority>0.5</priority></url><url><loc>https://www.tradetrust.io/news/three-successful-digital-cross-border-trade-trials-completed-businesses-will-be-able-to-benefit-from-faster-and-more-secured-transactions</loc><changefreq>monthly</changefreq><priority>0.5</priority></url><url><loc>https://www.tradetrust.io/news/worlds-largest-business-organisation-joins-singapore-government-and-major-industry-partners-to-drive-global-digitalisation</loc><changefreq>monthly</changefreq><priority>0.5</priority></url><url><loc>https://www.tradetrust.io/news/world%E2%80%99s-first-digital-trade-financing-pilot-between-mletr-harmonised-jurisdictions</loc><changefreq>monthly</changefreq><priority>0.5</priority></url><url><loc>https://www.tradetrust.io/news/launch-of-tradetrust-announced-by-mr-s-iswaran-minister-for-communications-and-information-at-the-committee-of-supply-debate-on-4-march-2019</loc><changefreq>monthly</changefreq><priority>0.5</priority></url><url><loc>https://www.tradetrust.io/news/remarks-by-mr-s-iswaran-minister-for-communications-and-information-at-the-international-chamber-of-commerce-taking-trade-digital-forum-in-davos-on-22-jan-2020</loc><changefreq>monthly</changefreq><priority>0.5</priority></url><url><loc>https://www.tradetrust.io/event/10th-asia-pacific-trade-facilitation-forum-aptff-next-generation-trade-facilitation-for-sustainable-development</loc><changefreq>monthly</changefreq><priority>0.5</priority></url><url><loc>https://www.tradetrust.io/event/digitalise-your-supply-chains-to-save-cost-improve-efficiency-overall-profitability-with-trames</loc><changefreq>monthly</changefreq><priority>0.5</priority></url><url><loc>https://www.tradetrust.io/event/hack-singapore-the-grand-finale-asia-tech-x-singapore</loc><changefreq>monthly</changefreq><priority>0.5</priority></url><url><loc>https://www.tradetrust.io/event/joining-forces-for-trade-digitisation-swift-the-united-nations-and-the-singapore-government</loc><changefreq>monthly</changefreq><priority>0.5</priority></url><url><loc>https://www.tradetrust.io/event/leveraging-on-data-to-grow-a-competitive-resilient-borderless-business</loc><changefreq>monthly</changefreq><priority>0.5</priority></url><url><loc>https://www.tradetrust.io/event/maritime-perspective-series-digital-connectivity-and-data-standards</loc><changefreq>monthly</changefreq><priority>0.5</priority></url><url><loc>https://www.tradetrust.io/event/rethink-retell-and-restart</loc><changefreq>monthly</changefreq><priority>0.5</priority></url><url><loc>https://www.tradetrust.io/event/sbf-digital-economy-series-trade-digitalisation-lowering-costs-improving-efficiency-through-paperless-trade</loc><changefreq>monthly</changefreq><priority>0.5</priority></url><url><loc>https://www.tradetrust.io/event/singapore-enterprise-blockchain-summit-2022</loc><changefreq>monthly</changefreq><priority>0.5</priority></url><url><loc>https://www.tradetrust.io/event/singapore-maritime-network-2022-1</loc><changefreq>monthly</changefreq><priority>0.5</priority></url><url><loc>https://www.tradetrust.io/event/swift-community-event-digitising-trade-now-or-never</loc><changefreq>monthly</changefreq><priority>0.5</priority></url><url><loc>https://www.tradetrust.io/event/tc307-plenary</loc><changefreq>monthly</changefreq><priority>0.5</priority></url><url><loc>https://www.tradetrust.io/event/the-journey-to-paperless-trade-industry-initiatives-for-interoperability</loc><changefreq>monthly</changefreq><priority>0.5</priority></url><url><loc>https://www.tradetrust.io/event/tradetrust-community-event-2023</loc><changefreq>monthly</changefreq><priority>0.5</priority></url><url><loc>https://www.tradetrust.io/event/world-cio-200-apac-singapore-on-3-dec-and-world-cio-200-summit-grand-finale</loc><changefreq>monthly</changefreq><priority>0.5</priority></url></urlset>
55 changes: 55 additions & 0 deletions sitemap.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
const path = require("path");
const fs = require("fs");
const { SitemapStream, streamToPromise } = require("sitemap");
const { paths } = require("./src/config/routes-config");

// https://github.com/ekalinin/sitemap.js/blob/master/api.md#sitemap-item-options
interface SitemapRecord {
url: string;
changefreq?: string;
priority?: number;
}

const mainPages: SitemapRecord[] = [];
const pathArray: string[] = Object.values(paths);
Object.values(pathArray).reduce((accumulator, currentPath) => {
if (!currentPath.includes("*") && !currentPath.includes(":slug")) {
accumulator.push({
url: currentPath,
changefreq: "monthly",
priority: 0.6,
});
}
return accumulator;
}, mainPages);

const cmsDetailPages: SitemapRecord[] = [];
const populateCmsPages = (prefix: string, srcDirectory: string) => {
fs.readdirSync(srcDirectory).forEach((file: string) => {
const name = path.parse(file).name;
if (name !== ".DS_Store") {
cmsDetailPages.push({
url: `${prefix}${name}`,
changefreq: "monthly",
priority: 0.5,
});
}
});
};
populateCmsPages("/news/", `${__dirname}/cms/article`);
populateCmsPages("/news/", `${__dirname}/cms/newsletter`);
populateCmsPages("/news/", `${__dirname}/cms/partner-news`);
populateCmsPages("/news/", `${__dirname}/cms/press-release`);
populateCmsPages("/news/", `${__dirname}/cms/speech`);
populateCmsPages("/event/", `${__dirname}/cms/event`);

const allPages = [...mainPages, ...cmsDetailPages];

const sitemap = new SitemapStream({ hostname: "https://www.tradetrust.io" });
const writeStream = fs.createWriteStream(`public/static/sitemap.xml`);

sitemap.pipe(writeStream);
allPages.forEach((page) => {
sitemap.write(page);
});
sitemap.end();
147 changes: 0 additions & 147 deletions sitemap/sitemap-generator.ts

This file was deleted.

42 changes: 0 additions & 42 deletions sitemap/sitemap.ts

This file was deleted.

23 changes: 23 additions & 0 deletions src/config/routes-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
export const paths: Record<string, string> = {
home: "/",
verify: "/verify",
viewer: "/viewer",
faq: "/faq",
generalFaq: "/faq/general-faq",
productFaq: "/faq/product-faq",
eta: "/eta",
settings: "/settings",
addressResolver: "/settings/address-resolver",
addressBook: "/settings/address-book",
news: "/news",
newsDetail: "/news/:slug",
learn: "/learn",
event: "/event",
eventDetail: "/event/:slug",
guidelines: "/guidelines",
privacyPolicy: "/privacy-policy",
termsOfUse: "/terms-of-use",
cost: "/cost",
partners: "/partners",
notFound: "*",
};
Loading

0 comments on commit 7c38069

Please sign in to comment.