Skip to content

Commit

Permalink
added sitemap
Browse files Browse the repository at this point in the history
  • Loading branch information
Riley1101 committed Dec 7, 2023
1 parent 88136c3 commit 1c45402
Show file tree
Hide file tree
Showing 4 changed files with 226 additions and 83 deletions.
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ ARG PUBLIC_ALGOLIA_ID
ARG PUBLIC_FORMSPREE_ID
ARG VITE_ALGOLIA_ID
ARG VITE_ALGOLIA_API
ARG VITE_PUBLIC_DOMAIN
ENV NODE_ENV="production"
ENV PUBLIC_ALGOLIA_API=$PUBLIC_ALGOLIA_API
ENV PUBLIC_ALGOLIA_ID=$PUBLIC_ALGOLIA_ID
ENV PUBLIC_FORMSPREE_ID=$PUBLIC_FORMSPREE_ID
ENV VITE_ALGOLIA_API=$VITE_ALGOLIA_API
ENV VITE_ALGOLIA_ID=$VITE_ALGOLIA_ID
ENV VITE_PUBLIC_DOMAIN=$VITE_PUBLIC_DOMAIN

# Install pnpm
ARG PNPM_VERSION=8.9.0
Expand Down
136 changes: 68 additions & 68 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,70 +1,70 @@
{
"name": "shaniit",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node build",
"dev": "vite dev",
"build": "vite build",
"preview": "vite preview",
"check": "svelte-kit sync && svelte-check --tsconfig ./jsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./jsconfig.json --watch",
"lint": "prettier --plugin-search-dir . --check . && eslint .",
"format": "prettier --plugin-search-dir . --write .",
"dev-prepare": "husky install"
},
"devDependencies": {
"@flydotio/dockerfile": "^0.4.11",
"@portabletext/svelte": "^2.1.4",
"@sveltejs/adapter-auto": "^2.1.1",
"@sveltejs/adapter-cloudflare": "^2.3.4",
"@sveltejs/adapter-node": "^1.3.1",
"@sveltejs/kit": "^1.27.7",
"@tailwindcss/typography": "^0.5.10",
"@types/prismjs": "^1.26.3",
"autoprefixer": "^10.4.16",
"carbon-components-svelte": "^0.75.1",
"carbon-icons-svelte": "^11.4.0",
"eslint": "^8.55.0",
"eslint-config-prettier": "^8.10.0",
"eslint-plugin-svelte": "^2.35.1",
"husky": "^8.0.3",
"postcss": "^8.4.32",
"prettier": "^2.8.8",
"prettier-plugin-svelte": "^2.10.1",
"sass": "^1.69.5",
"svelte": "^3.59.2",
"svelte-check": "^3.6.2",
"tailwindcss": "^3.3.6",
"typescript": "^5.3.3",
"vite": "^4.5.1"
},
"type": "module",
"dependencies": {
"@algolia/autocomplete-js": "^1.12.2",
"@algolia/autocomplete-theme-classic": "^1.12.2",
"@carbon/charts-svelte": "^1.13.8",
"@carbon/styles": "^1.44.0",
"@sanity/client": "^6.9.2",
"@sanity/code-input": "^4.1.1",
"@sanity/color-input": "^3.1.0",
"@sanity/icons": "^2.7.0",
"@sanity/image-url": "^1.0.2",
"@sanity/vision": "^3.21.0",
"algoliasearch": "^4.20.0",
"carbon-preprocess-svelte": "^0.9.1",
"d3": "^7.8.5",
"d3-cloud": "^1.2.7",
"d3-sankey": "^0.12.3",
"instantsearch.js": "^4.62.0",
"moment": "^2.29.4",
"prismjs": "^1.29.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-icons": "^4.12.0",
"sanity": "^3.21.0",
"sanity-plugin-asset-source-unsplash": "^1.1.2",
"sanity-plugin-graph-view": "^2.0.1",
"svelte-preprocess": "^5.1.1"
}
"name": "shaniit",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node build",
"dev": "vite dev",
"build": "vite build",
"preview": "vite preview",
"check": "svelte-kit sync && svelte-check --tsconfig ./jsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./jsconfig.json --watch",
"lint": "prettier --plugin-search-dir . --check . && eslint .",
"format": "prettier --plugin-search-dir . --write .",
"dev-prepare": "husky install"
},
"devDependencies": {
"@flydotio/dockerfile": "^0.4.11",
"@portabletext/svelte": "^2.1.4",
"@sveltejs/adapter-auto": "^2.1.1",
"@sveltejs/adapter-cloudflare": "^2.3.4",
"@sveltejs/adapter-node": "^1.3.1",
"@sveltejs/kit": "^1.27.7",
"@tailwindcss/typography": "^0.5.10",
"@types/prismjs": "^1.26.3",
"autoprefixer": "^10.4.16",
"carbon-components-svelte": "^0.75.1",
"carbon-icons-svelte": "^11.4.0",
"eslint": "^8.55.0",
"eslint-config-prettier": "^8.10.0",
"eslint-plugin-svelte": "^2.35.1",
"husky": "^8.0.3",
"postcss": "^8.4.32",
"prettier": "^2.8.8",
"prettier-plugin-svelte": "^2.10.1",
"sass": "^1.69.5",
"svelte": "^3.59.2",
"svelte-check": "^3.6.2",
"tailwindcss": "^3.3.6",
"typescript": "^5.3.3",
"vite": "^4.5.1"
},
"type": "module",
"dependencies": {
"@algolia/autocomplete-js": "^1.12.2",
"@algolia/autocomplete-theme-classic": "^1.12.2",
"@carbon/charts-svelte": "^1.13.8",
"@carbon/styles": "^1.44.0",
"@sanity/client": "^6.9.2",
"@sanity/code-input": "^4.1.1",
"@sanity/color-input": "^3.1.0",
"@sanity/icons": "^2.7.0",
"@sanity/image-url": "^1.0.2",
"@sanity/vision": "^3.21.0",
"algoliasearch": "^4.20.0",
"carbon-preprocess-svelte": "^0.9.1",
"d3": "^7.8.5",
"d3-cloud": "^1.2.7",
"d3-sankey": "^0.12.3",
"instantsearch.js": "^4.62.0",
"moment": "^2.29.4",
"prismjs": "^1.29.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-icons": "^4.12.0",
"sanity": "^3.21.0",
"sanity-plugin-asset-source-unsplash": "^1.1.2",
"sanity-plugin-graph-view": "^2.0.1",
"svelte-preprocess": "^5.1.1"
}
}
140 changes: 140 additions & 0 deletions src/routes/sitemap.xml/+server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
const DOMAIN = 'https://shaniit.org';
import { getPageData } from '$lib/sanity/query';
type Page = {
loc: string;
changefreq: string;
priority: number;
lastmod: string;
};
const pages = [
{
loc: '/',
changefreq: 'daily',
priority: 1,
lastmod: new Date().toISOString()
},
{
loc: '/blogs',
changefreq: 'daily',
priority: 1,
lastmod: new Date().toISOString()
},
{
loc: '/events',
changefreq: 'daily',
priority: 1,
lastmod: new Date().toISOString()
},

{
loc: '/userguides',
changefreq: 'daily',
priority: 1,
lastmod: new Date().toISOString()
},

{
loc: '/faqs',
changefreq: 'daily',
priority: 1,
lastmod: new Date().toISOString()
},

{
loc: '/fonts',
changefreq: 'daily',
priority: 1,
lastmod: new Date().toISOString()
},
{
loc: '/natural-language-processing',
changefreq: 'daily',
priority: 1,
lastmod: new Date().toISOString()
},
{
loc: '/terms',
changefreq: 'daily',
priority: 1,
lastmod: new Date().toISOString()
},
{
loc: '/about',
changefreq: 'daily',
priority: 1,
lastmod: new Date().toISOString()
},

{
loc: '/donate',
changefreq: 'daily',
priority: 1,
lastmod: new Date().toISOString()
},
{
loc: '/contact',
changefreq: 'daily',
priority: 1,
lastmod: new Date().toISOString()
}
];

let query = `{
"blogs" :*[_type == "news"][0...1000]{
"loc":slug.current,
"lastmod":_updatedAt,
},
"events":*[_type == "events"][0...1000]{
"loc":slug.current,
"lastmod":_updatedAt,
},
}`;

export async function GET() {
const { events, blogs }: { events: Page[]; blogs: Page[] } = await getPageData(query);
return new Response(
`
<?xml version="1.0" encoding="UTF-8" ?>
<urlset
xmlns="https://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:xhtml="https://www.w3.org/1999/xhtml"
xmlns:mobile="https://www.google.com/schemas/sitemap-mobile/1.0"
xmlns:news="https://www.google.com/schemas/sitemap-news/0.9"
xmlns:image="https://www.google.com/schemas/sitemap-image/1.1"
xmlns:video="https://www.google.com/schemas/sitemap-video/1.1"
>
<!-- <url> elements go here -->
${pages.map(
(page) => `
<url>
<loc>${DOMAIN}${page.loc}</loc>
<changefreq>${page.changefreq}</changefreq>
<priority>${page.priority}</priority>
</url>`
)}
${blogs.map(
(page) => `
<url>
<loc>${DOMAIN}/events/${page.loc}</loc>
<changefreq>weekly</changefreq>
<priority>0.7</priority>
</url>
`
)}
${blogs.map(
(page) => `
<url>
<loc>${DOMAIN}/blogs/${page.loc}</loc>
<changefreq>weekly</changefreq>
<priority>0.5</priority>
</url>
`
)}
</urlset>`.trim(),
{
headers: {
'Content-Type': 'application/xml'
}
}
);
}
31 changes: 16 additions & 15 deletions svelte.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,22 @@ import sveltePreprocess from 'svelte-preprocess';

/** @type {import('@sveltejs/kit').Config} */
const config = {
preprocess: [
sveltePreprocess({
scss: true
}),
optimizeImports()
],
kit: {
adapter: adapter({
// See below for an explanation of these options
routes: {
include: ['/*'],
exclude: ['<all>']
}
})
}
preprocess: [
sveltePreprocess({
scss: true,
preserve: ['ld+json']
}),
optimizeImports()
],
kit: {
adapter: adapter({
// See below for an explanation of these options
routes: {
include: ['/*'],
exclude: ['<all>']
}
})
}
};

export default config;

0 comments on commit 1c45402

Please sign in to comment.