Skip to content

Commit

Permalink
Don't just catch everything as a flat page
Browse files Browse the repository at this point in the history
  • Loading branch information
eyeseast committed Jan 16, 2025
1 parent 86a4faf commit 8da2860
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts">
import Flatpage from "@/lib/components/layouts/Flatpage.svelte";
import Flatpage from "$lib/components/layouts/Flatpage.svelte";
export let data;
Expand Down
26 changes: 26 additions & 0 deletions src/routes/(pages)/about/+page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { error } from "@sveltejs/kit";

import { PAGE_MAX_AGE } from "@/config/config.js";
import * as flatpages from "$lib/api/flatpages";

export const trailingSlash = "always";

const path = "/about/";

export async function load({ fetch, setHeaders }) {
const { data, error: err } = await flatpages.get(path, fetch);

if (err) {
return error(err.status, { message: err.message });
}

if (!data) {
return error(404, "Page not found");
}

setHeaders({
"cache-control": `public, max-age=${PAGE_MAX_AGE}`,
});

return data;
}
14 changes: 14 additions & 0 deletions src/routes/(pages)/help/[...path]/+page.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<script lang="ts">
import Flatpage from "$lib/components/layouts/Flatpage.svelte";
export let data;
$: title = data.title;
$: content = data.content;
</script>

<svelte:head>
<title>{title} | DocumentCloud</title>
</svelte:head>

<Flatpage {content} />
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import { error } from "@sveltejs/kit";
import { PAGE_MAX_AGE } from "@/config/config.js";
import * as flatpages from "$lib/api/flatpages";

export const trailingSlash = "ignore";
export const trailingSlash = "always";

export async function load({ fetch, params, setHeaders }) {
const { data, error: err } = await flatpages.get(params.path, fetch);
const path = ["help", ...params.path.split("/")].join("/");
const { data, error: err } = await flatpages.get(path, fetch);

if (err) {
return error(err.status, { message: err.message });
Expand Down

0 comments on commit 8da2860

Please sign in to comment.