Skip to content

Commit

Permalink
Merge pull request #89 from tjheffner/deps-upgrade
Browse files Browse the repository at this point in the history
fix xml routes hopefully
  • Loading branch information
tjheffner authored Jan 20, 2024
2 parents bc0d114 + 9fc0c44 commit 8b26239
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 9 deletions.
5 changes: 5 additions & 0 deletions src/params/string.js
Original file line number Diff line number Diff line change
@@ -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)
}
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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({
Expand Down
File renamed without changes.
2 changes: 2 additions & 0 deletions src/routes/rss.xml/+server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) {
Expand Down
2 changes: 2 additions & 0 deletions src/routes/sitemap.xml/+server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit 8b26239

Please sign in to comment.