Skip to main content
Module

x/aleph/framework/core/module.ts

The Full-stack Framework in Deno.
Very Popular
Go to Latest
File
import util from '../../shared/util.ts'
export const moduleExts = ['tsx', 'jsx', 'ts', 'js', 'mjs']
export function toPagePath(url: string): string { let pathname = trimModuleExt(url) if (pathname.startsWith('/pages/')) { pathname = util.trimPrefix(pathname, '/pages') } if (pathname.endsWith('/index')) { pathname = util.trimSuffix(pathname, '/index') } if (pathname === '') { pathname = '/' } return pathname}
export function trimModuleExt(url: string) { for (const ext of moduleExts) { if (url.endsWith('.' + ext)) { return url.slice(0, -(ext.length + 1)) } } return url}
export function importModule(basePath: string, url: string, forceRefetch = false): Promise<any> { const { __ALEPH: ALEPH } = window as any
if (ALEPH) { return ALEPH.import(url, forceRefetch) }
let src = util.cleanPath(basePath + '/_aleph/' + trimModuleExt(url) + '.js') if (forceRefetch) { src += '?t=' + Date.now() } return import(src)}