RSS and sitemap, etc

This commit is contained in:
Jade Ellis
2024-02-19 13:15:46 +00:00
parent ac2accc8ea
commit 0602eea898
6 changed files with 212 additions and 23 deletions
+14
View File
@@ -0,0 +1,14 @@
import { dev } from '$app/environment';
export const SITE_TITLE = 'JadedBlueEyes';
export const SITE_URL = dev ? "http://localhost:5173" : "https://jade.ellis.link"
export const SITE_DOMAIN = 'jade.ellis.link';
export const SITE_DEFAULT_DESCRIPTION =
"Jade's website.";
export const RSS_DEFAULT_POSTS_PER_PAGE = 15;
+22 -1
View File
@@ -11,7 +11,8 @@
--font-color-secondary: rgba(0, 0, 0, .6);
--font-family-base: Roboto, sans-serif;
--font-family-heading: "Sen", Roboto, sans-serif;
--border-radius: 8px
--border-radius: 8px;
--shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
}
@media (prefers-color-scheme: dark) {
@@ -54,4 +55,24 @@ svg {
max-width: 1056px;
margin: 0 auto;
padding: 0 var(--spacing);
--edge-border-radius: var(--border-radius);
}
@media screen and (max-width: 320px) {
.main {
padding: 0 0;
--edge-border-radius: 0;
}
}
.card {
border-radius: var(--border-radius);
box-shadow: var(--shadow);
background-color: var(--surface-color);
}
.edge {
border-radius: var(--edge-border-radius);
}
@@ -0,0 +1,56 @@
import {
SITE_DEFAULT_DESCRIPTION,
SITE_TITLE,
SITE_URL,
RSS_DEFAULT_POSTS_PER_PAGE
} from '$lib/metadata';
import { create } from 'xmlbuilder2';
// import { base } from '$app/paths';
export const prerender = true;
export async function GET() {
const headers = {
'Cache-Control': 'max-age=0, s-maxage=3600',
'Content-Type': 'application/xml'
};
return new Response(await getRssXml(), { headers });
}
const AUTHOR = "Jade Ellis"
// prettier-ignore
async function getRssXml(): Promise<string> {
const rssUrl = `${SITE_URL}/rss.xml`;
const root = create({ version: '1.0', encoding: 'utf-8' })
.ele('feed', {
xmlns: 'http://www.w3.org/2005/Atom',
})
.ele('title').txt(SITE_TITLE).up()
.ele('link', { href: SITE_URL }).up()
.ele('link', { rel: 'self', href: rssUrl }).up()
.ele('updated').txt(new Date().toISOString()).up()
.ele('id').txt(SITE_URL).up()
.ele('author')
.ele('name').txt(AUTHOR).up()
.up()
.ele('subtitle').txt(SITE_DEFAULT_DESCRIPTION).up()
// for await (const post of posts) {
// const pubDate =
// const postUrl =
// const postHtml =
// const summary = post.metadata.description;
// root.ele('entry')
// .ele('title').txt(post.metadata.title).up()
// .ele('link', { href: postUrl }).up()
// .ele('updated').txt(pubDate).up()
// .ele('id').txt(postUrl).up()
// .ele('content', { type: 'html' }).txt(postHtml).up()
// .ele('summary').txt(summary).up()
// .up();
// }
return root.end()
}
@@ -0,0 +1,37 @@
import { SITE_URL } from '$lib/metadata';
import { create } from 'xmlbuilder2';
// Run at build time
export const prerender = true;
export async function GET() {
const headers = {
'Cache-Control': 'max-age=0, s-maxage=3600',
'Content-Type': 'application/xml'
};
return new Response(await getSitemapXml(), { headers });
}
async function getSitemapXml(): Promise<string> {
const root = create({ version: '1.0', encoding: 'utf-8' })
.ele('urlset', {
xmlns: 'http://www.sitemaps.org/schemas/sitemap/0.9',
'xmlns:xhtml': 'http://www.w3.org/1999/xhtml',
'xmlns:mobile': 'http://www.google.com/schemas/sitemap-mobile/1.0',
'xmlns:image': 'http://www.google.com/schemas/sitemap-image/1.1',
'xmlns:news': 'http://www.google.com/schemas/sitemap-news/0.9',
'xmlns:video': 'http://www.google.com/schemas/sitemap-video/1.1',
})
// for await (const post of posts) {
// const postUrl =
// const date =
// root.ele('url')
// .ele('loc').txt(postUrl).up()
// .ele('lastmod').txt(date).up()
// .up();
// }
return root.end()
}