diff --git a/src/params/string.js b/src/params/string.js new file mode 100644 index 0000000..8be7d0b --- /dev/null +++ b/src/params/string.js @@ -0,0 +1,5 @@ +// test that a route doesn't end in .xml +// so [slug] can greedy match everything except .xml routes +export function match(value) { + return /^(?!.*[.]xml$).*$/.test(value) +} diff --git a/src/routes/(main)/[slug]/+page.js b/src/routes/(main)/[slug=string]/+page.js similarity index 69% rename from src/routes/(main)/[slug]/+page.js rename to src/routes/(main)/[slug=string]/+page.js index 876e552..26522de 100644 --- a/src/routes/(main)/[slug]/+page.js +++ b/src/routes/(main)/[slug=string]/+page.js @@ -1,18 +1,11 @@ import { error, redirect } from '@sveltejs/kit' +import { goto } from '$app/navigation' import { REPO_URL } from '$lib/siteConfig' export const csr = true // https://github.com/sveltejs/kit/pull/6446 export async function load({ params, fetch, setHeaders }) { const slug = params.slug - // redirect these slugs to appropriate routes - if (slug === 'feed' || slug === 'rss' || slug === 'rss.xml') { - throw redirect(308, '/rss.xml') - } - if (slug === 'sitemap' || slug === 'sitemap.xml') { - throw redirect(308, '/sitemap.xml') - } - let res = null res = await fetch(`/api/getContent/${slug}.json`) if (res.status > 400) { @@ -23,7 +16,7 @@ export async function load({ params, fetch, setHeaders }) { // because [slug] is a catchall, it gets gallery slugs too. redirect them. // e.g. /japan -> /gallery/japan if (json.type === 'gallery') { - throw redirect(308, `/gallery/${json.slug}`) + redirect(308, `/gallery/${json.slug}`) } setHeaders({ diff --git a/src/routes/(main)/[slug]/+page.svelte b/src/routes/(main)/[slug=string]/+page.svelte similarity index 100% rename from src/routes/(main)/[slug]/+page.svelte rename to src/routes/(main)/[slug=string]/+page.svelte diff --git a/src/routes/rss.xml/+server.js b/src/routes/rss.xml/+server.js index d40ae19..9f0042b 100644 --- a/src/routes/rss.xml/+server.js +++ b/src/routes/rss.xml/+server.js @@ -4,6 +4,8 @@ import { remark } from 'remark' import remarkHTML from 'remark-html' import { listContentFromIssues } from '$lib/content' +export const prerender = true + // Reference: https://github.com/sveltejs/kit/blob/master/examples/hn.svelte.dev/src/routes/%5Blist%5D/rss.js /** @type {import('@sveltejs/kit').RequestHandler} */ export async function GET({ fetch }) { diff --git a/src/routes/sitemap.xml/+server.js b/src/routes/sitemap.xml/+server.js index 4170476..152a8cc 100644 --- a/src/routes/sitemap.xml/+server.js +++ b/src/routes/sitemap.xml/+server.js @@ -2,6 +2,8 @@ import { SITE_URL } from '$lib/siteConfig' import { listContentFromIssues } from '$lib/content' import { fetchMarkdownPosts } from '$lib/localContent' +export const prerender = true + /** @type {import('@sveltejs/kit').RequestHandler} */ export async function GET({ fetch }) { const posts = await listContentFromIssues(fetch, 'Published')