Skip to content

Commit

Permalink
fix: 💫 update static assets
Browse files Browse the repository at this point in the history
  • Loading branch information
rodneylab committed Nov 16, 2022
1 parent 286ca11 commit bd16004
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 161 deletions.
90 changes: 0 additions & 90 deletions generate-sitemap.js

This file was deleted.

55 changes: 26 additions & 29 deletions src/routes/sitemap.xml/+server.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import website from '$lib/config/website';
import { BLOG_PATH, getPosts, getPostsContent } from '$lib/utilities/blog';
import path from 'path';
import { error } from '@sveltejs/kit';

export const prerender = true;

Expand All @@ -25,49 +24,47 @@ const render = (pages, posts) => `<?xml version="1.0" encoding="UTF-8" ?>
<url>
<loc>${element}</loc>
<lastmod>${`${process.env.VITE_BUILD_TIME}`}</lastmod>
<changefreq>monthly</changefreq>
<priority>0.7</priority>
</url>`,
)
.join('\n')}
${posts
.map((element) => {
const { lastUpdated, slug } = element;
return `
<url>
<loc>${siteUrl}/${slug}/</loc>
<lastmod>${`${lastUpdated}`}</lastmod>
<changefreq>daily</changefreq>
<priority>0.7</priority>
<loc>${siteUrl}/${slug}</loc>
<lastmod>${`${new Date(lastUpdated).toISOString()}`}</lastmod>
</url>
`;
})
.join('')}
</urlset>`;

/** @type {import('./$types').RequestHandler} */
export async function GET() {
const __dirname = path.resolve();
const location = path.join(__dirname, BLOG_PATH);
const postsContent = await getPostsContent(location);
const posts = await getPosts(postsContent, false);

const pages = Object.keys(import.meta.glob('/src/routes/**/!(_)*.svelte'))
.filter((page) => {
const filters = ['slug]', '_', 'private'];

return !filters.find((filter) => page.includes(filter));
})
.map((page) =>
page.replace('/src/routes', siteUrl).replace('/index.svelte', '').replace('.svelte', ''),
export async function GET({ setHeaders }) {
try {
const mdModules = import.meta.glob('../../content/blog/**/index.md');
const posts = await Promise.all(
Object.keys(mdModules).map(async (path) => {
const slug = path.split('/').at(-2);
const { metadata } = await mdModules[path]();
const { lastUpdated } = metadata;
return { lastUpdated, slug };
}),
);

return {
body: render(pages, posts),
headers: {
'Cache-Control': `max-age=0, s-max-age=${600}`,
const pagePaths = ['', '/contact'];
const pages = pagePaths.map((element) => `${siteUrl}${element}`);

setHeaders({
'Cache-Control': 'max-age=0, s-max-age=600',
'Content-Type': 'application/xml',
},
};
});

return new Response(render(pages, posts));
} catch (err) {
console.error(`Error in sitemap.xml: ${err}`);
throw error(500, err);
}
}
42 changes: 0 additions & 42 deletions static/sitemap.xml

This file was deleted.

0 comments on commit bd16004

Please sign in to comment.