Skip to content

Commit

Permalink
V2.0.0 beta.36
Browse files Browse the repository at this point in the history
Handle collison issue between subpages of same url
  • Loading branch information
mateomorris committed Sep 21, 2023
1 parent 2ecfbd1 commit 66beac5
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions src/routes/[site]/+layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,33 @@ export async function load({ depends, params, parent }) {

// Get site and page
const site_url = params['site']
const client_params = params['page']?.split('/') || null
const page_url = (client_params === null) ? 'index' : client_params.pop()
const client_params = params['page']?.split('/') || []
const page_url = client_params.pop() || 'index'
const parent_url = client_params.pop() || null

const [{ data: site }, { data: page }] = await Promise.all([
supabase.from('sites').select().filter('url', 'eq', site_url).single(),
supabase.from('pages').select('*, site!inner(id, url)').match({ 'site.url': site_url, url: page_url }).single()
])
let site, page
if (parent_url) {
const res = await Promise.all([
supabase.from('sites').select().filter('url', 'eq', site_url).single(),
supabase.from('pages').select(`*, site!inner(id, url), parent!inner(id, url)`).match({
url: page_url,
'site.url': site_url,
'parent.url': parent_url
}).single()
])
site = res[0]['data']
page = res[1]['data']
} else {
const res = await Promise.all([
supabase.from('sites').select().filter('url', 'eq', site_url).single(),
supabase.from('pages').select(`*, site!inner(id, url)`).match({
url: page_url,
'site.url': site_url
}).is('parent', null).single()
])
site = res[0]['data']
page = res[1]['data']
}

if (!site) {
throw redirect(303, '/')
Expand Down

0 comments on commit 66beac5

Please sign in to comment.