Skip to content
This repository was archived by the owner on Jul 6, 2025. It is now read-only.

Commit dfb2dff

Browse files
committed
refactor(framework): rename pageModule to module
1 parent 30eac09 commit dfb2dff

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

framework/core/routing.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ export function isHttpUrl(url: string) {
231231
}
232232
}
233233

234-
export function isPageModule(url: string) {
234+
export function isModuleURL(url: string) {
235235
for (const ext of pageModuleExts) {
236236
if (url.endsWith('.' + ext)) {
237237
return true
@@ -241,11 +241,20 @@ export function isPageModule(url: string) {
241241
}
242242

243243
export function getPagePathname(url: string): string {
244-
const pathname = trimPageModuleExt(url).replace(/^\/pages\//, '/').replace(/\/?index$/, '/')
244+
let pathname = trimModuleExt(url)
245+
if (pathname.startsWith('/pages/')) {
246+
pathname = util.trimPrefix(pathname, '/pages')
247+
}
248+
if (pathname.endsWith('/index')) {
249+
pathname = util.trimSuffix(pathname, '/index')
250+
if (pathname === '') {
251+
pathname = '/'
252+
}
253+
}
245254
return pathname
246255
}
247256

248-
export function trimPageModuleExt(url: string) {
257+
export function trimModuleExt(url: string) {
249258
for (const ext of pageModuleExts) {
250259
if (url.endsWith('.' + ext)) {
251260
return url.slice(0, -(ext.length + 1))

framework/react/bootstrap.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { ComponentType } from 'https://esm.sh/react'
22
import { createElement } from 'https://esm.sh/react'
33
import { hydrate, render } from 'https://esm.sh/react-dom'
4-
import { Route, RouteModule, Routing, trimPageModuleExt } from '../core/routing.ts'
4+
import { Route, RouteModule, Routing, trimModuleExt } from '../core/routing.ts'
55
import type { PageRoute } from './pageprops.ts'
66
import { createPageProps } from './pageprops.ts'
77
import Router from './router.ts'
@@ -22,7 +22,7 @@ export default async function bootstrap(options: Options) {
2222
const customComponents: Record<string, ComponentType> = {}
2323
await Promise.all(sharedModules.map(async mod => {
2424
const { default: C } = await importModule(baseUrl, mod)
25-
switch (trimPageModuleExt(mod.url)) {
25+
switch (trimModuleExt(mod.url)) {
2626
case '/404':
2727
customComponents['E404'] = C
2828
break

framework/react/util.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { createContext } from 'https://esm.sh/react'
22
import util from '../../shared/util.ts'
33
import type { RouterURL } from '../../types.ts'
4-
import { trimPageModuleExt } from '../core/routing.ts'
4+
import { trimModuleExt } from '../core/routing.ts'
55

66
const symbolFor = typeof Symbol === 'function' && Symbol.for
77
const REACT_FORWARD_REF_TYPE = symbolFor ? Symbol.for('react.forward_ref') : 0xead0
@@ -50,7 +50,7 @@ export function importModule(baseUrl: string, mod: { url: string, hash: string }
5050
}
5151

5252
if (ALEPH && mod.url.startsWith('/pages/')) {
53-
const src = util.cleanPath(baseUrl + '/_aleph/' + trimPageModuleExt(mod.url) + `.bundle.${util.shortHash(mod.hash)}.js`)
53+
const src = util.cleanPath(baseUrl + '/_aleph/' + trimModuleExt(mod.url) + `.bundle.${util.shortHash(mod.hash)}.js`)
5454
return new Promise((resolve, reject) => {
5555
const script = document.createElement('script')
5656
script.onload = () => {
@@ -64,7 +64,7 @@ export function importModule(baseUrl: string, mod: { url: string, hash: string }
6464
})
6565
}
6666

67-
const src = util.cleanPath(baseUrl + '/_aleph/' + trimPageModuleExt(mod.url) + `.${util.shortHash(mod.hash)}.js`) + (forceRefetch ? `?t=${Date.now()}` : '')
67+
const src = util.cleanPath(baseUrl + '/_aleph/' + trimModuleExt(mod.url) + `.${util.shortHash(mod.hash)}.js`) + (forceRefetch ? `?t=${Date.now()}` : '')
6868
return import(src)
6969
}
7070

0 commit comments

Comments
 (0)