Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 0 additions & 16 deletions packages/stacks-docs-next/_redirects
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to self: Verify that we don't need these redirects that have been removed

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can go too, was also ported from v2 Netlify.toml but not needed

# Assets
/assets/img/logo-stacks@2x.png /assets/img/logos/so/logo-stacks@2x.png 302

Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,6 @@
https://alpha.stackoverflow.design/* https://stackoverflow.design/:splat 301
https://beta.stackoverflow.design/* https://stackoverflow.design/:splat 302

# Section index pages → first child (mirrors Navigation.svelte L67)
/brand/ /brand/logo 302

/copy/ /copy/voice 302
/copy/patterns/ /copy/patterns/messages 302

/system/ /system/develop/using-stacks 302
/system/develop/ /system/develop/using-stacks 302
/system/accessibility/ /system/accessibility/intro 302
/system/foundation/ /system/foundation/color-fundamentals 302
/system/base/ /system/base/backgrounds 302
/system/forms/ /system/forms/checkbox 302
/system/components/ /system/components/activity-indicator 302

/handbook/ /handbook/story 302
/resources/ /resources/fonts 302

# Email section → v2 docs
/email* https://v2.stackoverflow.design/email:splat 302
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { PageServerLoad } from "./$types";
import { error } from "@sveltejs/kit";
import { error, redirect } from "@sveltejs/kit";
import type { Component } from "svelte";
import { render } from "svelte/server";
import TurndownService from "turndown";
Expand All @@ -10,6 +10,13 @@ const turndownService = new TurndownService({

const mdFiles = import.meta.glob("$docs/**/*.md");

type NavItem = { slug: string; items?: NavItem[] };

function firstLeafSlug(prefix: string, item: NavItem): string {
if (!item.items?.length) return `${prefix}/${item.slug}`;
return firstLeafSlug(`${prefix}/${item.slug}`, item.items[0]);
}

export const load: PageServerLoad = async (event) => {
// SECURITY: Check auth first - don't load any content if unauthorized
const parent = await event.parent();
Expand Down Expand Up @@ -71,5 +78,10 @@ export const load: PageServerLoad = async (event) => {
};
}

// If the active item is a section (has children), redirect to the first leaf page
if (parent.active?.items?.length > 0) {
throw redirect(302, `/${firstLeafSlug(slug, parent.active.items[0])}`);
}

throw error(404, `No content found for ${slug}`);
};
Loading