deno.land / x / lume@v2.1.4 / core / loaders / module.ts
12345678910111213141516171819202122232425262728293031323334353637import { isUrl } from "../utils/path.ts";import { isPlainObject } from "../utils/object.ts";import { env } from "../utils/env.ts";
import type { RawData } from "../file.ts";
/** Load a JavaScript/TypeScript file. Use a random hash to prevent caching */export default async function module(path: string): Promise<RawData> { const url = isUrl(path) ? path : `file://${path}`; const specifier = env<boolean>("LUME_LIVE_RELOAD") ? `${url}#${Date.now()}` : url;
const mod = await import(specifier); return toData(mod);}
/** Transform the imported module to RawData */export function toData(mod: Record<string, unknown>): RawData { const data: RawData = {};
for (const [name, value] of Object.entries(mod)) { if (name === "default") { if (isPlainObject(value)) { Object.assign(data, value); } else { data.content = value; } continue; }
data[name] = value; }
return data;}
Version Info