({ pathname })
| 1 | import { loadConfig } from './loadConfig'; |
| 2 | |
| 3 | export async function resolveContentPath({ pathname }) { |
| 4 | if (pathname === '/') { |
| 5 | try { |
| 6 | const res = await fetch('/generated/index/pieces.json'); |
| 7 | const pieces = await res.json(); |
| 8 | if (pieces && pieces.length > 0) { |
| 9 | const mostRecent = pieces[0]; |
| 10 | return `/content/pieces/${mostRecent.slug}.md`; |
| 11 | } |
| 12 | return null; |
| 13 | } catch { |
| 14 | return null; |
| 15 | } |
| 16 | } else { |
| 17 | const slug = pathname.slice(1); |
| 18 | let isPage = false; |
| 19 | let isPiece = false; |
| 20 | try { |
| 21 | const pagesRes = await fetch('/generated/index/pages.json'); |
| 22 | const pages = await pagesRes.json(); |
| 23 | isPage = pages.some(page => page.slug === slug); |
| 24 | } catch (error) { |
| 25 | console.error('[router]: error fetching pages index:', error); |
| 26 | isPage = false; |
| 27 | } |
| 28 | if (!isPage) { |
| 29 | try { |
| 30 | const piecesRes = await fetch('/generated/index/pieces.json'); |
| 31 | const pieces = await piecesRes.json(); |
| 32 | isPiece = pieces.some(piece => piece.slug === slug); |
| 33 | } catch (error) { |
| 34 | console.error('[router]: error fetching pieces index:', error); |
| 35 | isPiece = false; |
| 36 | } |
| 37 | } |
| 38 | if (isPage) { |
| 39 | return `/content/pages/${slug}.md`; |
| 40 | } else if (isPiece) { |
| 41 | return `/content/pieces/${slug}.md`; |
| 42 | } else { |
| 43 | const config = await loadConfig(); |
| 44 | const notFoundSlug = config?.pages?.notFound || 'obscured'; |
| 45 | return `/content/pages/${notFoundSlug}.md`; |
| 46 | } |
| 47 | } |
| 48 | } |
no test coverage detected