Skip to content

Commit

Permalink
cleanup trailing slash
Browse files Browse the repository at this point in the history
  • Loading branch information
gvkhna committed May 23, 2024
1 parent 74bf6e6 commit 13b9f66
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 20 deletions.
12 changes: 11 additions & 1 deletion astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,17 @@ export default defineConfig({
}
// eslint-disable-next-line no-console,no-undef
console.log(`sitemap include?: ${url.pathname} -> ${sitemapAllow}`)
return sitemapAllow // Include the page
return sitemapAllow // Include? the page
},
serialize: (page) => {
const newUrl = new URL(page.url)
// Check if there's a trailing slash and it's not just the root path
if (newUrl.pathname.endsWith('/') && newUrl.pathname !== '/') {
// Remove the trailing slash if it exists
newUrl.pathname = newUrl.pathname.slice(0, -1)
}
page.url = newUrl.toString()
return page
}
}),
robotsTxt()
Expand Down
8 changes: 4 additions & 4 deletions src/layouts/auth-layout.astro
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
---
import HomeLayout, {type Props as HomeProps} from './home-layout.astro'
import MainLayout, {type Props as MainLayoutProps} from './main-layout.astro'
export interface Props extends HomeProps {}
export interface Props extends MainLayoutProps {}
const props = Astro.props
---

<HomeLayout {...props}>
<MainLayout {...props}>
<div
class='container relative grid h-[100vh] flex-col items-center justify-center lg:max-w-none lg:grid-cols-2 lg:px-0'
>
Expand Down Expand Up @@ -41,4 +41,4 @@ const props = Astro.props
</div>
</div>
</div>
</HomeLayout>
</MainLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ export interface Props {
const {title, desc, seo} = Astro.props
const newUrl = new URL(Astro.url.toString())
// Check if there's a trailing slash and it's not just the root path
if (newUrl.pathname.endsWith('/') && newUrl.pathname !== '/') {
// Remove the trailing slash if it exists
newUrl.pathname = newUrl.pathname.slice(0, -1)
}
import '@styles/globals.css'
---

Expand All @@ -16,6 +24,7 @@ import '@styles/globals.css'
<head>
<SEO
charset='utf-8'
canonical={newUrl}
extend={{
link: [
{rel: 'icon', href: '/favicon.ico'},
Expand Down
6 changes: 3 additions & 3 deletions src/pages/404.astro
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
import HomeLayout from '@/layouts/home-layout.astro'
import MainLayout from '@/layouts/main-layout.astro'
---

<HomeLayout title='404'>
<MainLayout title='404'>
<main class='flex-1'>
<div class='flex h-screen flex-col items-center justify-center'>
<div>
Expand All @@ -13,4 +13,4 @@ import HomeLayout from '@/layouts/home-layout.astro'
</div>
</div>
</main>
</HomeLayout>
</MainLayout>
6 changes: 3 additions & 3 deletions src/pages/app/[...path].astro
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
// main dashboard single page app
import HomeLayout from '@/layouts/home-layout.astro'
import MainLayout from '@/layouts/main-layout.astro'
import {verifyValidSession} from '@/lib/github-client'
export const prerender = false
Expand All @@ -12,7 +12,7 @@ if (!existingSession.valid && existingSession.redirect) {
}
---

<HomeLayout title='App Dashboard'>
<MainLayout title='App Dashboard'>
<h1>Successful auth</h1>
</HomeLayout>
</MainLayout>
z
6 changes: 3 additions & 3 deletions src/pages/github-callback.astro
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
import HomeLayout from '@/layouts/home-layout.astro'
import MainLayout from '@/layouts/main-layout.astro'
import {deleteOauthStateCookie, getOauthStateCookie} from '@/lib/cookies'
import {fetchGithubUserProfile, fetchGithubUserAccessToken, githubAuthUser} from '@/lib/github-client'
Expand Down Expand Up @@ -58,6 +58,6 @@ if (oauthState && githubState && oauthState === githubState && githubCode) {
deleteOauthStateCookie(Astro)
---

<HomeLayout title='Oauth Login'>
<MainLayout title='Oauth Login'>
{displayError ? <h1>{displayError.message}</h1> : <h1>Successful auth</h1>}
</HomeLayout>
</MainLayout>
6 changes: 3 additions & 3 deletions src/pages/index.astro
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
import HomeLayout from '@/layouts/home-layout.astro'
import MainLayout from '@/layouts/main-layout.astro'
import client from '@/lib/api-client'
import {drizzle} from 'drizzle-orm/d1'
import {desc} from 'drizzle-orm'
Expand All @@ -18,7 +18,7 @@ const db = drizzle(Astro.locals.runtime.env.DB)
const usersData = await db.select().from(users).orderBy(desc(users.id))
---

<HomeLayout
<MainLayout
title='Signin'
desc='Sign in to your account'
>
Expand All @@ -33,4 +33,4 @@ const usersData = await db.select().from(users).orderBy(desc(users.id))
}
</div>
<div>testing</div>
</HomeLayout>
</MainLayout>
6 changes: 3 additions & 3 deletions src/pages/viewer.astro
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
---
import HomeLayout from '@/layouts/home-layout.astro'
import MainLayout from '@/layouts/main-layout.astro'
export const prerender = true
import LocalViewerPage from '@/partials/viewer/local-viewer-page'
---

<HomeLayout title='Local Viewer'>
<MainLayout title='Local Viewer'>
<LocalViewerPage client:only='react' />
</HomeLayout>
</MainLayout>

0 comments on commit 13b9f66

Please sign in to comment.